You can just try and find out, but if I'm not wrong, it does the rollback after each test so testGetUser will fail
Jun 14, 2018
3
Level 1
Does RefreshDatabase rollback changes after each test of at the end of all
Let's say I have simple test with 2 functions:
public function testCreateUser()
{
User::create(['username' => 'test']);
}
And this is where I create a user and it has id=1.
Now I want to get that user in next test function
public function testGetUser()
{
User::find(1);
}
Will this user be in my database or will RefreshDatabase rollback my changes after it finishes with testCreateUser() so my user won't be saved in the database?
Level 10
Depends.
If you're using an in-memory database (DB_DATABASE = :memory:) then the trait will refresh the database after each test.
If you're using a normal database, then it will migrate ONCE, and then run your tests within transactions. This is faster than migrating and rolling back after each test individually
1 like
Please or to participate in this conversation.