Maybe, In your Symfony project, you tried to run something as:
$ php bin/phpunit
and you had as result this ugly message (or similar):
PHP Fatal error: Uncaught Error: Class "PHPUnit\TextUI \Command" not found in /var/www/html/yourproject/bin/phpunit:12
Stack trace:
#0 {main}
thrown in /var/www/html/yourproject/bin/phpunit on line 12
Don't worry. Edit your bin/phpunit file and rewrite it with the following content:
#!/usr/bin/env php
<?php
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
exit((new \PHPUnit\TextUI\Application())->run($GLOBALS['argv']));
} else {
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}
Happy codding!
- Thanks to simonjamain for fixing my code.
Top comments (8)
Thank you for code, it helps, but there is one important thing missing that got us quite confused :
The command line exit code was always 0 no matter what, which break the backward compatibility (and out CI/CD). As a matter of fact, the return code is return by the
run
method so you just have to wrap your line with andexit()
:You should IMHO make the Following change to your provided code :
exit((new \PHPUnit\TextUI\Application())->run($GLOBALS['argv']));
Thank you again !
You're right. Thanks you for fixing my code!
Also don't forget to upgrade the xml.dist file:
vendor/bin/phpunit --migrate-configuration
What should we do with.. this.. This it's gone after the new xml.dist file, because it seems that listeners is not a valid parent element anymore in v10:
The updated symfony bridge takes care of that
Thanks 🙏🏻
To you for reading it!
Thanks 💙