Skip to content

Commit

Permalink
More work on #3422.
Browse files Browse the repository at this point in the history
* Revert deprecation of assertContains() and assertNotContains()
* Revert addition of assertIterableContains(), assertIterableContainsSame(), assertIterableNotContains(), and assertIterableNotContainsSame()
* Deprecate using assertContains() and assertNotContains() on string haystacks
* Deprecate the optional parameters $ignoreCase, $checkForObjectIdentity, and $checkForNonObjectIdentity of assertContains() and assertNotContains()
  • Loading branch information
sebastianbergmann committed Dec 2, 2018
1 parent de7eba0 commit 5a5b982
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 127 deletions.
7 changes: 4 additions & 3 deletions ChangeLog-7.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ All notable changes of the PHPUnit 7.5 release series are documented in this fil
* Implemented [#3368](https://github.com/sebastianbergmann/phpunit/issues/3368): Added `assertIsArray()`, `assertIsBool()`, `assertIsFloat()`, `assertIsInt()`, `assertIsNumeric()`, `assertIsObject()`, `assertIsResource()`, `assertIsString()`, `assertIsScalar()`, `assertIsCallable()`, `assertIsIterable()`, `assertIsNotArray()`, `assertIsNotBool()`, `assertIsNotFloat()`, `assertIsNotInt()`, `assertIsNotNumeric()`, `assertIsNotObject()`, `assertIsNotResource()`, `assertIsNotString()`, `assertIsNotScalar()`, `assertIsNotCallable()`, `assertIsNotIterable()` as alternatives to `assertInternalType()` and `assertNotInternalType()`
* Implemented [#3391](https://github.com/sebastianbergmann/phpunit/issues/3391): Added a `TestHook` that fires after each test, regardless of result
* Implemented [#3417](https://github.com/sebastianbergmann/phpunit/pull/3417): Refinements related to test suite sorting and TestDox result printer
* Implemented [#3422](https://github.com/sebastianbergmann/phpunit/issues/3422): Added `assertStringContainsString()`, `assertStringContainsStringIgnoringCase()`, `assertStringNotContainsString()`, `assertStringNotContainsStringIgnoringCase()`, `assertIterableContains()`, `assertIterableContainsSame()`, `assertIterableNotContains()`, and `assertIterableNotContainsSame()`
* Implemented [#3422](https://github.com/sebastianbergmann/phpunit/issues/3422): Added `assertStringContainsString()`, `assertStringContainsStringIgnoringCase()`, `assertStringNotContainsString()`, and `assertStringNotContainsStringIgnoringCase()`

### Deprecated

* The methods `assertContains()` and `assertNotContains()` are now deprecated. There is no behavioral change in this version of PHPUnit. Using these methods will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these methods will be removed.
* The methods `assertInternalType()` and `assertNotInternalType()` are now deprecated. There is no behavioral change in this version of PHPUnit. Using these methods will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these methods will be removed.
* The methods `assertAttributeContains()`, `assertAttributeNotContains()`, `assertAttributeContainsOnly()`, `assertAttributeNotContainsOnly()`, `assertAttributeCount()`, `assertAttributeNotCount()`, `assertAttributeEquals()`, `assertAttributeNotEquals()`, `assertAttributeEmpty()`, `assertAttributeNotEmpty()`, `assertAttributeGreaterThan()`, `assertAttributeGreaterThanOrEqual()`, `assertAttributeLessThan()`, `assertAttributeLessThanOrEqual()`, `assertAttributeSame()`, `assertAttributeNotSame()`, `assertAttributeInstanceOf()`, `assertAttributeNotInstanceOf()`, `assertAttributeInternalType()`, `assertAttributeNotInternalType()`, `attributeEqualTo()`, `readAttribute()`, `getStaticAttribute()`, and `getObjectAttribute()` are now deprecated. There is no behavioral change in this version of PHPUnit. Using these methods will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these methods will be removed.
* The optional parameters `$delta`, `$maxDepth`, `$canonicalize`, and `$ignoreCase` of `assertEquals()`, and `assertNotEquals` are now deprecated. There is no behavioral change in this version of PHPUnit. Using these parameters will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these parameters will be removed.
* The optional parameters `$delta`, `$maxDepth`, `$canonicalize`, and `$ignoreCase` of `assertEquals()` and `assertNotEquals()` are now deprecated. There is no behavioral change in this version of PHPUnit. Using these parameters will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these parameters will be removed.
* The annotations `@expectedException`, `@expectedExceptionCode`, `@expectedExceptionMessage`, and `@expectedExceptionMessageRegExp` are now deprecated. There is no behavioral change in this version of PHPUnit. Using these annotations will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these annotations will be removed.
* Using the methods `assertContains()` and `assertNotContains()` on `string` haystacks is now deprecated. There is no behavioral change in this version of PHPUnit. Using these methods on `string` haystacks will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these methods cannot be used on on `string` haystacks anymore.
* The optional parameters `$ignoreCase`, `$checkForObjectIdentity`, and `$checkForNonObjectIdentity` of `assertContains()` and `assertNotContains()` are now deprecated. There is no behavioral change in this version of PHPUnit. Using these parameters will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these parameters will be removed.

### Fixed

Expand Down
32 changes: 0 additions & 32 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,41 +192,11 @@ public static function assertStringNotContainsStringIgnoringCase(string $needle,
static::assertThat($haystack, $constraint, $message);
}

public static function assertIterableContains($needle, iterable $haystack, string $message = ''): void
{
$constraint = new TraversableContains($needle, false, false);

static::assertThat($haystack, $constraint, $message);
}

public static function assertIterableContainsSame($needle, iterable $haystack, string $message = ''): void
{
$constraint = new TraversableContains($needle, true, true);

static::assertThat($haystack, $constraint, $message);
}

public static function assertIterableNotContains($needle, iterable $haystack, string $message = ''): void
{
$constraint = new LogicalNot(new TraversableContains($needle, false, false));

static::assertThat($haystack, $constraint, $message);
}

public static function assertIterableNotContainsSame($needle, iterable $haystack, string $message = ''): void
{
$constraint = new LogicalNot(new TraversableContains($needle, true, true));

static::assertThat($haystack, $constraint, $message);
}

/**
* Asserts that a haystack contains a needle.
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3422
*/
public static function assertContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void
{
Expand Down Expand Up @@ -287,8 +257,6 @@ public static function assertAttributeContains($needle, string $haystackAttribut
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3422
*/
public static function assertNotContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void
{
Expand Down
92 changes: 0 additions & 92 deletions tests/unit/Framework/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3004,98 +3004,6 @@ public function testStringNotContainsStringCanBeAssertedIgnoringCase(): void
$this->fail();
}

public function testIterableContainsObjectCanBeAsserted(): void
{
$object = new \stdClass;
$iterable = [$object];

$this->assertIterableContains(new \stdClass, $iterable);

try {
$this->assertIterableContains(new class {
}, $iterable);
} catch (AssertionFailedError $e) {
return;
}

$this->fail();
}

public function testIterableNotContainsObjectCanBeAsserted(): void
{
$object = new \stdClass;
$iterable = [$object];

$this->assertIterableNotContains(new class {
}, $iterable);

try {
$this->assertIterableNotContains(new \stdClass, $iterable);
} catch (AssertionFailedError $e) {
return;
}

$this->fail();
}

public function testIterableContainsSameObjectCanBeAsserted(): void
{
$object = new \stdClass;
$iterable = [$object];

$this->assertIterableContainsSame($object, $iterable);

try {
$this->assertIterableContainsSame(new \stdClass, $iterable);
} catch (AssertionFailedError $e) {
return;
}

$this->fail();
}

public function testIterableNotContainsSameObjectCanBeAsserted(): void
{
$object = new \stdClass;
$iterable = [$object];

$this->assertIterableNotContainsSame(new \stdClass, $iterable);

try {
$this->assertIterableNotContainsSame($object, $iterable);
} catch (AssertionFailedError $e) {
return;
}

$this->fail();
}

public function testIterableContainsSameNonObjectCanBeAsserted(): void
{
$this->assertIterableContainsSame(1, [1]);

try {
$this->assertIterableContainsSame('1', [1]);
} catch (AssertionFailedError $e) {
return;
}

$this->fail();
}

public function testIterableNotContainsSameNonObjectCanBeAsserted(): void
{
$this->assertIterableNotContainsSame('1', [1]);

try {
$this->assertIterableNotContainsSame(1, [1]);
} catch (AssertionFailedError $e) {
return;
}

$this->fail();
}

protected function sameValues(): array
{
$object = new \SampleClass(4, 8, 15);
Expand Down

0 comments on commit 5a5b982

Please sign in to comment.