Drupal now uses Symfony's PHPUnit-Bridge polyfills for forward compatibility.
Similarly to Symfony's simple-phpunit
command, Drupal now rewrites some PHPUnit base classes to include polyfill traits that allow to extend later PHPUnit's methods to its earlier versions.
This allows module developers to start adjusting their PHPUnit tests even before a PHPUnit version is officially supported - for instance, by starting using, in the Drupal 9 cycle and running tests under PHPUnit 8 and 9, assertions that are formally implemented in PHPUnit 10.
Example:
The assertDirectoryNotExists()
assertion is deprecated in PHPUnit 9 and removed in PHPUnit 10:
// Confirm the style directory has been removed.
$directory = 'public://styles/' . $style_name;
$this->assertDirectoryNotExists($directory);
with the polyfill trait, its replacement assertDirectoryDoesNotExist()
can be seamlessly used in PHPUnit 8 and 9.
// Confirm the style directory has been removed.
$directory = 'public://styles/' . $style_name;
$this->assertDirectoryDoesNotExist($directory);
It's important that module developers keep their assertions updated so to smoothen the shift to later PHPUnit versions.