Skip to content

Commit

Permalink
Initial work on #3422
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 28, 2018
1 parent bcba5f4 commit 77d079f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ChangeLog-7.5.md
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions src/Framework/Assert.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 77d079f

Please sign in to comment.