How to use PHPUnit 10 with Symfony

This article was published more than 6 months ago, this means the content may be out of date or no longer relevant.

PHPUnit has been release 8 months ago (the 3rd of February 2023). But if we try to use it in a Symfony project using the symfony/phpunit-bridge component, a PHP Fatal error: Uncaught Error: Class "PHPUnit\TextUI\Command occurred.

PHP Fatal error:  Uncaught Error: Class "PHPUnit\TextUI\Command" not found in /home/jdecool/Workspace/sandbox/test/bin/phpunit:11
Stack trace:
#0 {main}
  thrown in /home/jdecool/Workspace/sandbox/test/bin/phpunit on line 11

Fatal error: Uncaught Error: Class "PHPUnit\TextUI\Command" not found in /home/jdecool/Workspace/sandbox/test/bin/phpunit on line 11

Error: Class "PHPUnit\TextUI\Command" not found in /home/jdecool/Workspace/sandbox/test/bin/phpunit on line 11

Call Stack:
    0.0001     396248   1. {main}() /home/jdecool/Workspace/sandbox/test/bin/phpunit:0

The Symfony script tries to use a deleted PHPUnit class. While there are several PRs to fix the problem, but none are currently merged.

If you want to solve this issue, you can simply update the bin/phpunit file using this patch:

-    PHPUnit\TextUI\Command::main();
+    exit((new PHPUnit\TextUI\Application)->run($_SERVER['argv']));