Regression in phpunit-bridge 5.2.4: fatal error instead of deprecation notice for Debug\DebugClassLoader

Symfony version(s) affected: 5.2.4

Description

While in symfony/phpunit-bridge 5.2.3 I get the nice deprecation notice The "Symfony\Component\Debug\DebugClassLoader" class is deprecated since Symfony 4.4, use "Symfony\Component\ErrorHandler\DebugClassLoader" instead., in symfony/phpunit-bridge 5.2.4 I get a fatal error like this:

PHP Fatal error:  Uncaught Error: Call to a member function getName() on null in /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/DeprecationErrorHandler/Deprecation.php:121
Stack trace:
#0 /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php(134): Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation->__construct('The "Symfony\\Co...', Array, '/var/www/Webfac...')
#1 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(16384, 'The "Symfony\\Co...', '/var/www/Webfac...', 16, Array)
#2 /var/www/WebfactoryDownloadBundle/vendor/symfony/debug/DebugClassLoader.php(16): trigger_error('The "Symfony\\Co...', 16384)
#3 /var/www/WebfactoryDownloadBundle/vendor/composer/ClassLoader.php(478): include('/var/www/Webfac...')
#4 /var/www/WebfactoryDownloadBundle/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile('/var/www/Webfac...')
#5 [internal function]: Composer\Autoload\ClassLoader->loadClass('Symfony\\Compone...')
#6 [internal function]: spl_autoload_call('Symfony\\Compone...')
#7 /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php(64): class_exists('Symfony\\Compone...')
#8 /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerForV7.php(34): Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait->__construct(Array)
#9 /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(1124): Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7->__construct()
#10 /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(161): PHPUnit\TextUI\TestRunner->handleConfiguration(Array)
#11 /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/src/TextUI/Command.php(206): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#12 /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\TextUI\Command->run(Array, true)
#13 /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#14 {main}
  thrown in /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/DeprecationErrorHandler/Deprecation.php on line 121

Fatal error: Uncaught Error: Call to a member function getName() on null in /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/DeprecationErrorHandler/Deprecation.php on line 121

Error: Call to a member function getName() on null in /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/DeprecationErrorHandler/Deprecation.php on line 121

Call Stack:
    0.0003     395160   1. {main}() /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/phpunit:0
    0.0161    1077728   2. PHPUnit\TextUI\Command::main() /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/phpunit:61
    0.0162    1077840   3. PHPUnit\TextUI\Command->run() /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/src/TextUI/Command.php:162
    0.0825    2959616   4. PHPUnit\TextUI\TestRunner->doRun() /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/src/TextUI/Command.php:206
    0.0825    2959640   5. PHPUnit\TextUI\TestRunner->handleConfiguration() /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:161
    0.0849    2994632   6. Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7->__construct() /var/www/WebfactoryDownloadBundle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:1124
    0.0858    3065528   7. Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait->__construct() /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerForV7.php:34
    0.0864    3074336   8. class_exists() /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php:64
    0.0864    3074416   9. spl_autoload_call() /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php:64
    0.0864    3074496  10. Composer\Autoload\ClassLoader->loadClass() /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php:64
    0.0866    3074608  11. Composer\Autoload\includeFile() /var/www/WebfactoryDownloadBundle/vendor/composer/ClassLoader.php:346
    0.0878    3187520  12. include('/var/www/WebfactoryDownloadBundle/vendor/symfony/debug/DebugClassLoader.php') /var/www/WebfactoryDownloadBundle/vendor/composer/ClassLoader.php:478
    0.0878    3187840  13. trigger_error() /var/www/WebfactoryDownloadBundle/vendor/symfony/debug/DebugClassLoader.php:16
    0.0878    3188904  14. Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError() /var/www/WebfactoryDownloadBundle/vendor/symfony/debug/DebugClassLoader.php:16
    0.0893    3305280  15. Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation->__construct() /var/www/WebfactoryDownloadBundle/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php:134

How to reproduce

Run phpunit tests with symfony/phpunit-bridge 5.2.4 and the deprecated symfony/debug 4.4 instead of the newer symfony/error-handler (i.e. in any symfony < 4.4).

This leads to Legacy/SymfonyTestsListenerTrait.php:64 trying to class load LegacyDebugClassLoader = Symfony\Component\Debug\DebugClassLoader, which trigger_errors in DebugClassLoader.php:16 with a stack trace that DeprecationErrorHandler\Deprecation::__construct does not handle well.

Possible Solution

It seems to me \Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation::__construct should be improved to handle such a stack trace. symfony/phpunit-bridge@d0eb698 already adresses this or a similar issue, but seemingly not for all legacy cases. I’ll try a PR.

1 possible answer(s) on “Regression in phpunit-bridge 5.2.4: fatal error instead of deprecation notice for Debug\DebugClassLoader