Testing at Drupal 9.x has recently started producing the following deprecation warning:
Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringContainsString() or assertStringContainsStringIgnoringCase() instead.
The optional $ignoreCase parameter of assertContains() is deprecated and will be removed in PHPUnit 9.
The four tests that produce this are:
devel_generate\Functional\DevelGenerateCommandsTest::testDrushGenerateContent
devel_generate\Functional\DevelGenerateCommandsTest::testDrushGenerateMedia
devel\Functional\DevelToolbarTest::testToolbarIntegration
devel\Kernel\DevelTwigExtensionTest::testDumpFunctions
This warning was first seen on 14 April and was not in the test output on 7 April so it must be a new deprecation (?). This causes the tests to fail, even though it is only listed as a warning, so maybe deprecations for PHPunit cannot be suppressed and the test allowed to pass?
Testing at 8.x is not affected because that uses PHPUnit 7.5.20 whereas Drupal 9 uses PHPUnit 8.5.2.
Update 18th April
Following recent commits at core 8.9 and 8.8 we now have new forwards-compatibility functions available in PHPUnit 6, which is what drupal.org uses, and early versions of PHPunit 7. These were already included in PHPUnit 7.5.20
assertStringContainsString() and assertStringNotContainsString(). There are also ...IgnoringCase() versions of both functions.
Comments
Comment #2
BerdirSee #3113077: Replace assertContains() on strings with assertStringContainsString() or assertStringContainsStringIgnoringCase()
Comment #3
BerdirMore importantly, see #3126797: [D8 only] Add forwards-compatibility shim for assertString(Not)ContainsString()replacements in phpunit 6&7, so this can't be done yet in contrib as the replacement is currently PHPUnit 8 only.
Comment #4
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks for the links Berdir. Looks like #3126695: [D8 only] Add forwards-compatibility shim for assertEqualsCanonicalizing() in phpunit 6&7 might be the first one to land.
Comment #5
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commented#3126797: [D8 only] Add forwards-compatibility shim for assertString(Not)ContainsString()replacements in phpunit 6&7 is in 8.8 and 8.9 now, so I will work on the changes required.
Comment #6
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedFor the toolbar test, I simplified it by only taking the url part before '?' for both sides (the current test only did this for one side) so that the assertion now becomes assertEquals. The others are simple replacements.
Comment #7
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedMissed one in assertDumpEquals which is a devel function defined in the /Kernel/DevelDumperTestTrait
Comment #8
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedForgot the interdiff.
Back to two test fails (for javascriptTestBase), as expected. This is probably OK to get committed. RTBC, anyone?
Comment #10
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedBefore, the phpunit output had
Now, after this commit, we have
There are no deprecation warnings on test runs at 9.0.x