I have a PHPUnit test case class (consisting of some test functions). I would like to write a oneTimeSetUp()
function to be called once for all my tests in the clas
I came to this page with the same question, however the accepted answer is ran on all classes, and for me was not the correct answer.
If you are like me, your first "Integration test" is to clear out the DB, and run migrations. This gets yourself at a database baseline for all test. I am constantly changing migration files at this point, so setting up the baseline is truly part of all tests.
The migration takes a while, so I do not want it run on all tests.
Then I needed to build up the database testing each piece. I need to write an order test, but first I need to create some products and test that, then I need to test an import fuction.
So, what I did is SUPER easy, but not explained extremely well on the internet. I created a simple test to setup the database. Then in your phpspec.xml file add a testsuite....
tests/in/SystemSetupTest.php
tests/in/ProductTest.php
tests/in/ProductImportTest.php
And in the the SystemSetupTest.php ....
class SystemSetupTest extends ApiTester
{
/** @test */
function system_init()
{
fwrite(STDOUT, __METHOD__ . "\n");
self::createEM(); //this has all the code to init the system...
}
}
Then execute it like:
phpunit --testsuite Products
In the end, its a ton easier. It will allow me to build up my system correctly.
Additionally I am using laravel 5. When using setUpBeforeClass()
I end up with bootstrap issues, which I am sure I can fix, but the method I use above works perfect.