-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up assertContains() and assertNotContains() #3426
Comments
@sebastianbergmann the PHPUnit 9 changelog does not document the behavior change of |
The ChangeLog has
which links to this ticket where this is explained. |
but if you don't click on the link, you don't have any indication that |
…ity rector As of sebastianbergmann/phpunit#3426 assertContains() and assertNotContains() will perform strict comparisons starting with PHPUnit 9 where non-strict comparisons were performed in PHPUnit 8 and earlier; assertContainsEqual() and assertNotContainsEqual() should be used instead if needed non-strict comparison
Hey @sebastianbergmann. We got bitten by this change as well in Laravel. I agree with @stof that this should be added to the changelog. If you can point me to where I need to make it I'll be happy to send in a PR. |
The methods assertContains() and assertNotContains() now perform strict (type and value) comparison, pretty much like assertSame() does. A couple of new assertContainsEquals() and assertNotContainsEquals() methods have been created to provide old (non-strict) behavior, pretty much like assertEquals() do. Apart from replacing the calls needing a relaxed comparison to those new methods, there are also a couple of alternative, about how to fix this, depending of every case: - If the test is making any array_values() conversion, then it's better to remove that conversion and use assertArrayHasKey(), that is not strict. - Sometimes if may be also possible to, simply, cast the expectation to the exact type coming in the array. I've not applied this technique to any of the cases in core. Link: sebastianbergmann/phpunit#3426
The methods assertContains() and assertNotContains() now perform strict (type and value) comparison, pretty much like assertSame() does. A couple of new assertContainsEquals() and assertNotContainsEquals() methods have been created to provide old (non-strict) behavior, pretty much like assertEquals() do. Apart from replacing the calls needing a relaxed comparison to those new methods, there are also a couple of alternative, about how to fix this, depending of every case: - If the test is making any array_values() conversion, then it's better to remove that conversion and use assertArrayHasKey(), that is not strict. - Sometimes if may be also possible to, simply, cast the expectation to the exact type coming in the array. I've not applied this technique to any of the cases in core. Link: sebastianbergmann/phpunit#3426
PHPUnit >= 9 adds assertStringContainsString, which ought to replace assertContains, and PHPUnit >= 9 removed[^1] support for calling assertContains on strings. [^1]: sebastianbergmann/phpunit#3426
assertContains()
andassertNotContains()
onstring
haystacks$ignoreCase
,$checkForObjectIdentity
, and$checkForNonObjectIdentity
ofassertContains()
andassertNotContains()
Assert::contains()
TraversableContainsEqual
andTraversableContainsIdentical
by inheriting fromTraversableContains
(which becomes an abstract base class for these two concrete classes)TraversableContainsIdentical
inAssert::assertContains()
andAssert::assertNotContains()
(this means thatassertContains()
andassertNotContains()
will perform strict comparisons starting with PHPUnit 9 where non-strict comparisons were performed in PHPUnit 8 and earlier; useassertContainsEqual()
andassertNotContainsEqual()
if you need non-strict comparison)The text was updated successfully, but these errors were encountered: