Can I run a PHP script automatically after all PHPUnit tests are finished?
I'd like to report some non-fatal issues (i.e. correct but suboptimal test results) after all tests are finished.
Can I run a PHP script automatically after all PHPUnit tests are finished?
I'd like to report some non-fatal issues (i.e. correct but suboptimal test results) after all tests are finished.
Assuming you can detect such sub-optimal results, PHPUnit (v9 and before) has a 'TestListener' facility, that can be extended with custom code and enabled in the phpunit.xml file. It can run code before and after tests, and for each potential result (pass/fail/errors, etc, etc).
PHPUnit 10 replaces the TestListener with a new events system.
Another way to do this is to call a bootstrap script for PHPUnit. Inside this file, you can use the function register_shutdown_function
, which will be executed once when all tests are completed.
On the command line, it would look something like this:
phpunit --bootstrap "path/to/bootstrap.php"
And in the bootstrap.php file, you define something like:
register_shutdown_function(function () {
echo "This code was called after all tests were executed";
});
© 2022 - 2024 — McMap. All rights reserved.