How can I run a script after phpunit tests finished
Asked Answered
F

2

8

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.

Forensics answered 23/6, 2016 at 8:53 Comment(0)
T
2

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.

Theo answered 27/9, 2017 at 19:46 Comment(0)
S
1

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"; 
});
Severe answered 23/2 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.