Skip to content

Commit

Permalink
Closes #3425
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 29, 2018
1 parent 2975888 commit 1c17ac3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 237 deletions.
1 change: 1 addition & 0 deletions ChangeLog-8.0.md
Expand Up @@ -13,6 +13,7 @@ All notable changes of the PHPUnit 8.0 release series are documented in this fil
* Implemented [#3338](https://github.com/sebastianbergmann/phpunit/issues/3338): Deprecate assertions (and helper methods) that operate on (non-public) attributes
* Implemented [#3341](https://github.com/sebastianbergmann/phpunit/issues/3341): Deprecate optional parameters of `assertEquals()` and `assertNotEquals()`
* Implemented [#3369](https://github.com/sebastianbergmann/phpunit/issues/3369): Deprecate `assertInternalType()` and `assertNotInternalType()`
* Implemented [#3425](https://github.com/sebastianbergmann/phpunit/issues/3425): Deprecate `assertContains()` and `assertNotContains()`

### Removed

Expand Down
6 changes: 6 additions & 0 deletions src/Framework/Assert.php
Expand Up @@ -227,9 +227,12 @@ public static function assertIterableNotContainsSame($needle, iterable $haystack
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3422
* @codeCoverageIgnore
*/
public static function assertContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void
{
self::createWarning('assertContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertStringContainsString(), assertStringContainsStringIgnoringCase(), assertIterableContains(), or assertIterableContainsSame() instead.');

if (\is_array($haystack) ||
(\is_object($haystack) && $haystack instanceof Traversable)) {
$constraint = new TraversableContains(
Expand Down Expand Up @@ -292,9 +295,12 @@ public static function assertAttributeContains($needle, string $haystackAttribut
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3422
* @codeCoverageIgnore
*/
public static function assertNotContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void
{
self::createWarning('assertNotContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertStringNotContainsString(), assertStringNotContainsStringIgnoringCase(), assertIterableNotContains(), or assertIterableNotContainsSame() instead.');

if (\is_array($haystack) ||
(\is_object($haystack) && $haystack instanceof Traversable)) {
$constraint = new LogicalNot(
Expand Down
212 changes: 0 additions & 212 deletions tests/unit/Framework/AssertTest.php
Expand Up @@ -32,50 +32,6 @@ public function testFail(): void
throw new AssertionFailedError('Fail did not throw fail exception');
}

public function testAssertSplObjectStorageContainsObject(): void
{
$a = new \stdClass;
$b = new \stdClass;
$c = new \SplObjectStorage;
$c->attach($a);

$this->assertContains($a, $c);

$this->expectException(AssertionFailedError::class);

$this->assertContains($b, $c);
}

public function testAssertArrayContainsObject(): void
{
$a = new \stdClass;
$b = new \stdClass;

$this->assertContains($a, [$a]);

$this->expectException(AssertionFailedError::class);

$this->assertContains($a, [$b]);
}

public function testAssertArrayContainsString(): void
{
$this->assertContains('foo', ['foo']);

$this->expectException(AssertionFailedError::class);

$this->assertContains('foo', ['bar']);
}

public function testAssertArrayContainsNonObject(): void
{
$this->assertContains('foo', [true]);

$this->expectException(AssertionFailedError::class);

$this->assertContains('foo', [true], '', false, true, true);
}

public function testAssertContainsOnlyInstancesOf(): void
{
$test = [new \Book, new \Book];
Expand All @@ -90,43 +46,6 @@ public function testAssertContainsOnlyInstancesOf(): void
$this->assertContainsOnlyInstancesOf(\Book::class, $test2);
}

public function testAssertContainsPartialStringInString(): void
{
$this->assertContains('bar', 'foo bar');

$this->expectException(AssertionFailedError::class);

$this->assertContains('cake', 'foo bar');
}

public function testAssertContainsNonCaseSensitiveStringInString(): void
{
$this->assertContains('Foo', 'foo', '', true);

$this->expectException(AssertionFailedError::class);

$this->assertContains('Foo', 'foo', '', false);
}

public function testAssertContainsEmptyStringInString(): void
{
$this->assertContains('', 'test');
}

public function testAssertStringContainsNonString(): void
{
$this->expectException(Exception::class);

$this->assertContains(null, '');
}

public function testAssertStringNotContainsNonString(): void
{
$this->expectException(Exception::class);

$this->assertNotContains(null, '');
}

public function testAssertArrayHasKeyThrowsExceptionForInvalidFirstArgument(): void
{
$this->expectException(Exception::class);
Expand Down Expand Up @@ -343,137 +262,6 @@ public function testAssertArrayNotHasKeyPropertlyFailsWithArrayAccessValue(): vo
$this->assertArrayNotHasKey('bar', $array);
}

public function testAssertContainsThrowsException(): void
{
$this->expectException(Exception::class);

$this->assertContains(null, null);
}

public function testAssertIteratorContainsObject(): void
{
$foo = new \stdClass;

$this->assertContains($foo, new \TestIterator([$foo]));

$this->expectException(AssertionFailedError::class);

$this->assertContains($foo, new \TestIterator([new \stdClass]));
}

public function testAssertIteratorContainsString(): void
{
$this->assertContains('foo', new \TestIterator(['foo']));

$this->expectException(AssertionFailedError::class);

$this->assertContains('foo', new \TestIterator(['bar']));
}

public function testAssertStringContainsString(): void
{
$this->assertContains('foo', 'foobar');

$this->expectException(AssertionFailedError::class);

$this->assertContains('foo', 'bar');
}

public function testAssertStringContainsStringForUtf8(): void
{
$this->assertContains('oryginał', 'oryginał');

$this->expectException(AssertionFailedError::class);

$this->assertContains('ORYGINAŁ', 'oryginał');
}

public function testAssertStringContainsStringForUtf8WhenIgnoreCase(): void
{
$this->assertContains('oryginał', 'oryginał', '', true);
$this->assertContains('ORYGINAŁ', 'oryginał', '', true);

$this->expectException(AssertionFailedError::class);

$this->assertContains('foo', 'oryginał', '', true);
}

public function testAssertNotContainsThrowsException(): void
{
$this->expectException(Exception::class);

$this->assertNotContains(null, null);
}

public function testAssertSplObjectStorageNotContainsObject(): void
{
$a = new \stdClass;
$b = new \stdClass;
$c = new \SplObjectStorage;
$c->attach($a);

$this->assertNotContains($b, $c);

$this->expectException(AssertionFailedError::class);

$this->assertNotContains($a, $c);
}

public function testAssertArrayNotContainsObject(): void
{
$a = new \stdClass;
$b = new \stdClass;

$this->assertNotContains($a, [$b]);

$this->expectException(AssertionFailedError::class);

$this->assertNotContains($a, [$a]);
}

public function testAssertArrayNotContainsString(): void
{
$this->assertNotContains('foo', ['bar']);

$this->expectException(AssertionFailedError::class);

$this->assertNotContains('foo', ['foo']);
}

public function testAssertArrayNotContainsNonObject(): void
{
$this->assertNotContains('foo', [true], '', false, true, true);

$this->expectException(AssertionFailedError::class);

$this->assertNotContains('foo', [true]);
}

public function testAssertStringNotContainsString(): void
{
$this->assertNotContains('foo', 'bar');

$this->expectException(AssertionFailedError::class);

$this->assertNotContains('foo', 'foo');
}

public function testAssertStringNotContainsStringForUtf8(): void
{
$this->assertNotContains('ORYGINAŁ', 'oryginał');

$this->expectException(AssertionFailedError::class);

$this->assertNotContains('oryginał', 'oryginał');
}

public function testAssertStringNotContainsStringForUtf8WhenIgnoreCase(): void
{
$this->expectException(AssertionFailedError::class);

$this->assertNotContains('ORYGINAŁ', 'oryginał', '', true);
}

public function testAssertArrayContainsOnlyIntegers(): void
{
$this->assertContainsOnly('integer', [1, 2, 3]);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Framework/Constraint/ArraySubsetTest.php
Expand Up @@ -79,8 +79,8 @@ public function testEvaluateFailMessage(): void
} catch (ExpectationFailedException $expectedException) {
$comparisonFailure = $expectedException->getComparisonFailure();
$this->assertNotNull($comparisonFailure);
$this->assertContains("'foo' => 'bar'", $comparisonFailure->getExpectedAsString());
$this->assertContains("'baz' => 'bar'", $comparisonFailure->getActualAsString());
$this->assertStringContainsString("'foo' => 'bar'", $comparisonFailure->getExpectedAsString());
$this->assertStringContainsString("'baz' => 'bar'", $comparisonFailure->getActualAsString());
}
}
}
2 changes: 1 addition & 1 deletion tests/unit/Framework/ExceptionWrapperTest.php
Expand Up @@ -46,7 +46,7 @@ public function testNoOriginalExceptionInStacktrace(): void

$data = \print_r($wrapper, 1);

$this->assertNotContains(
$this->assertStringNotContainsString(
'BadFunctionCallException',
$data,
'Assert there is s no other BadFunctionCallException mention in stacktrace'
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Framework/MockObject/MockObjectTest.php
Expand Up @@ -503,7 +503,7 @@ public function testGetMockForTrait(): void
$parent = \get_parent_class($mock);
$traits = \class_uses($parent, false);

$this->assertContains(AbstractTrait::class, $traits);
$this->assertIterableContains(AbstractTrait::class, $traits);
}

public function testClonedMockObjectShouldStillEqualTheOriginal(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Framework/TestSuiteTest.php
Expand Up @@ -162,7 +162,7 @@ public function testTestDataProviderDependency(): void
$lastSkippedResult = \array_pop($skipped);
$message = $lastSkippedResult->thrownException()->getMessage();

$this->assertContains('Test for DataProviderDependencyTest::testDependency skipped by data provider', $message);
$this->assertStringContainsString('Test for DataProviderDependencyTest::testDependency skipped by data provider', $message);
}

public function testIncompleteTestDataProvider(): void
Expand Down

0 comments on commit 1c17ac3

Please sign in to comment.