New in Symfony 4.4: PHPUnit Polyfills
When testing some code that has to be compatible with several versions of PHP, it's difficult to pick a PHPUnit version: latest versions like PHPUnit 8 use features incompatible with PHP 5.5 and remove methods available in earlier PHPUnit versions. In addition, PHPUnit 6 switched to namespaced classes, so tests must work with and without namespaces.
That's why in Symfony 4.4, we've improved the PHPUnit Bridge with several polyfills that allow to create tests that are compatible with multiple PHPUnit versions.
Removing the Void Return Type¶
When running the
simple-phpunit script with the
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT environment variable set to
the PHPUnit bridge will alter the code of PHPUnit to remove the
type (introduced in PHPUnit 8) from
tearDownAfterClass() methods. This allows you to
write a test compatible with both PHP 5 and PHPUnit 8.
Alternatively, you can use the trait SetUpTearDownTrait in your test class to
inject the methods without the
void return type.
Namespaced PHPUnit Classes¶
The PHPUnit bridge adds namespaced class aliases for most of the PHPUnit classes
declared without namespaces (e.g.
PHPUnit_Framework_Assert), allowing you to
always use the namespaced class declaration even when the test is executed with
PHPUnit 4, where namespaces aren't used.
New in Symfony 4.4: PHPUnit Polyfills symfony.com/blog/new-in-symfony-4-4-phpunit-polyfillsTweet this