Skip to content

Commit

Permalink
sebastianbergmann#3342 Remove optional parameters of assertEquals() a…
Browse files Browse the repository at this point in the history
…nd assertNotEquals()
  • Loading branch information
maksimovic committed Mar 4, 2019
1 parent 36f92d5 commit ae3bfa3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 71 deletions.
76 changes: 7 additions & 69 deletions src/Framework/Assert.php
Expand Up @@ -180,49 +180,19 @@ public static function assertArrayNotHasKey($key, $array, string $message = ''):
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws Exception
*/
public static function assertContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void
public static function assertContains($needle, $haystack, string $message = ''): void
{
// @codeCoverageIgnoreStart
if (\is_string($haystack)) {
self::createWarning('Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringContainsString() or assertStringContainsStringIgnoringCase() instead.');
}

if (!$checkForObjectIdentity) {
self::createWarning('The optional $checkForObjectIdentity parameter of assertContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertContainsEquals() instead.');
}

if ($checkForNonObjectIdentity) {
self::createWarning('The optional $checkForNonObjectIdentity parameter of assertContains() is deprecated and will be removed in PHPUnit 9.');
}

if ($ignoreCase) {
self::createWarning('The optional $ignoreCase parameter of assertContains() is deprecated and will be removed in PHPUnit 9.');
}
// @codeCoverageIgnoreEnd

if (\is_array($haystack) ||
(\is_object($haystack) && $haystack instanceof Traversable)) {
$constraint = new TraversableContains(
$needle,
$checkForObjectIdentity,
$checkForNonObjectIdentity
);
} elseif (\is_string($haystack)) {
if (!\is_string($needle)) {
throw InvalidArgumentHelper::factory(
1,
'string'
);
}

$constraint = new StringContains(
$needle,
$ignoreCase
true,
false
);
} else {
throw InvalidArgumentHelper::factory(
2,
'array, traversable or string'
'array or traversable'
);
}

Expand Down Expand Up @@ -271,47 +241,15 @@ public static function assertAttributeContains($needle, string $haystackAttribut
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws Exception
*/
public static function assertNotContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void
public static function assertNotContains($needle, $haystack, string $message = ''): void
{
// @codeCoverageIgnoreStart
if (\is_string($haystack)) {
self::createWarning('Using assertNotContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringNotContainsString() or assertStringNotContainsStringIgnoringCase() instead.');
}

if (!$checkForObjectIdentity) {
self::createWarning('The optional $checkForObjectIdentity parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotContainsEquals() instead.');
}

if ($checkForNonObjectIdentity) {
self::createWarning('The optional $checkForNonObjectIdentity parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.');
}

if ($ignoreCase) {
self::createWarning('The optional $ignoreCase parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.');
}
// @codeCoverageIgnoreEnd

if (\is_array($haystack) ||
(\is_object($haystack) && $haystack instanceof Traversable)) {
$constraint = new LogicalNot(
new TraversableContains(
$needle,
$checkForObjectIdentity,
$checkForNonObjectIdentity
)
);
} elseif (\is_string($haystack)) {
if (!\is_string($needle)) {
throw InvalidArgumentHelper::factory(
1,
'string'
);
}

$constraint = new LogicalNot(
new StringContains(
$needle,
$ignoreCase
true,
false
)
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Assert/Functions.php
Expand Up @@ -113,7 +113,7 @@ function assertArrayNotHasKey($key, $array, string $message = ''): void
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
function assertContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void
function assertContains($needle, $haystack, string $message = ''): void
{
Assert::assertContains(...\func_get_args());
}
Expand All @@ -138,7 +138,7 @@ function assertAttributeContains($needle, string $haystackAttributeName, $haysta
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
function assertNotContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void
function assertNotContains($needle, $haystack, string $message = ''): void
{
Assert::assertNotContains(...\func_get_args());
}
Expand Down

0 comments on commit ae3bfa3

Please sign in to comment.