By catch on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.1.x
Introduced in version:
9.1.0
Issue links:
Description:
Drupal 9.1.x has updated to PHPUnit 9. Installs on PHP 7.3 will continue to use PHPUnit 8.4 for compatibility reasons.
Most test should be unaffected, however, modules may need to account for the following:
-
::assertContains()now does strict type comparison which may cause some tests to fail. PHPUnit already provides the more permissive::assertContainsEquals()so tests can be updated to use this without breaking PHP 7.3 compatibility. -
Core has added a new
Drupal\Tests\PhpUnitCompatibilityTraitto all base classes. Contributed and custom tests should always extend from a core base test class, so it is better to do that than add the trait directly.
If you are depending on drupal/core-dev and you see errors similar to this when running core tests:
PHP Fatal error: Trait 'Prophecy\PhpUnit\ProphecyTrait' not found in core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit9/TestCompatibilityTrait.php on line 12
then you need to add an extra dependency:
composer require --dev phpspec/prophecy-phpunit:^2
This is because PHPUnit 8 includes Prophecy integration, but PHPUnit 9 does not. We are unable to depend on this package directly while supporting both versions of PHPUnit.
If you installed Drupal with drupal/core-recommended, be sure to run the command above within your project root instead of the core directory.
Impacts:
Module developers