Open Lenophie opened 6 years ago
Hi @Lenophie
This seems like a challenge I addressed recently by simply having my TestCase as follows:
<?php
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication, RefreshDatabase;
}
You should get a fresh DB instance after each class is run.
Hello, Thanks for your answer, I already tried similar solutions but I think they are sub-optimal compared to transactions :
Class-level transactions would be much cleaner and performant.
use DatabaseTransactions;
@deleugpn As I stated in the original post, use DatabaseTransactions;
is inappropriate because I want to be able to use PHPUnit's tests dependencies. As the transactions are rolled back between each test, the dependant tests surely fail.
Description:
To make full use of PHPUnit's test dependencies, I would like to be able to setup database transactions at class level instead of test level. A way I tried to implement this is to make use of PHPUnit's
setUpBeforeClass
andtearDownAfterClass
but I meet the following error when trying to run the test :I marked this issue as a feature request because I couldn't find any documentation on the subject whether it be in the docs or online, hinting that this may be an oversight rather than a bug.
Steps To Reproduce:
Here is the test prompting the error :
Note that the use of
Parent::createApplication();
is only to prevent another error from appearing, an error which I don't really understand either.Thanks for reviewing this issue,