Currently we run code to setup the database in setUpBeforeClass. However this runs before every test class is tested. Is it possible to have code run once before any tests are run, and maybe run some code when all tests are complete too?
This is precisely what the bootstrap file is designed to handle. By default PHPUnit will execute the code in bootstrap.php
in the current directory. You can use the phpunit.xml
configuration file or the --bootstrap
command-line switch to point to a different file.
This file is executed exactly once before trying to locate the tests to be run. It allows you to set up an include path, autoloader, constants, etc. before instantiating or running any tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With