From 77d079f8c216d23179b1ab9ac56f2e7f930175aa Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 28 Nov 2018 16:57:51 +0100 Subject: [PATCH] Initial work on #3422 --- ChangeLog-7.5.md | 4 ++- src/Framework/Assert.php | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/ChangeLog-7.5.md b/ChangeLog-7.5.md index e1d354ccd18..eba297097ce 100644 --- a/ChangeLog-7.5.md +++ b/ChangeLog-7.5.md @@ -10,12 +10,14 @@ 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()` ### Deprecated -* 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 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 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. [7.5.0]: https://github.com/sebastianbergmann/phpunit/compare/7.4...7.5.0 diff --git a/src/Framework/Assert.php b/src/Framework/Assert.php index b666c1023cc..20f79106bb1 100644 --- a/src/Framework/Assert.php +++ b/src/Framework/Assert.php @@ -164,11 +164,69 @@ public static function assertArrayNotHasKey($key, $array, string $message = ''): static::assertThat($array, $constraint, $message); } + public static function assertStringContainsString(string $needle, string $haystack, string $message): void + { + $constraint = new StringContains($needle, false); + + static::assertThat($haystack, $constraint, $message); + } + + public static function assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message): void + { + $constraint = new StringContains($needle, true); + + static::assertThat($haystack, $constraint, $message); + } + + public static function assertStringNotContainsString(string $needle, string $haystack, string $message): void + { + $constraint = new LogicalNot(new StringContains($needle)); + + static::assertThat($haystack, $constraint, $message); + } + + public static function assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message): void + { + $constraint = new LogicalNot(new StringContains($needle, true)); + + 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 { @@ -229,6 +287,8 @@ 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 {