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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonathan1055 created an issue. See original summary.

Berdir’s picture

Berdir’s picture

More 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.

jonathan1055’s picture

Thanks 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.

jonathan1055’s picture

Assigned: Unassigned » jonathan1055
Issue summary: View changes
jonathan1055’s picture

For 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.

jonathan1055’s picture

Missed one in assertDumpEquals which is a devel function defined in the /Kernel/DevelDumperTestTrait

jonathan1055’s picture

Forgot the interdiff.

Back to two test fails (for javascriptTestBase), as expected. This is probably OK to get committed. RTBC, anyone?

  • jonathan1055 committed 2dd8c43 on 8.x-3.x
    Issue #3127750 by jonathan1055, Berdir: Using assertContains() with...
jonathan1055’s picture

Assigned: jonathan1055 » Unassigned
Status: Needs review » Fixed

Before, the phpunit output had

WARNINGS!
Tests: 85, Assertions: 1690, Warnings: 4.

Now, after this commit, we have

OK (85 tests, 1690 assertions)

There are no deprecation warnings on test runs at 9.0.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.