RefreshDatabase trait

Published 7 months ago by bestmomo

Hello,

I use RefreshDatabase trait in Testcase.php but this doesn't work, not hit on trait and no database refresh.

I use this in phpunit.xml :

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

This was working on a previous project but not my new one, I use Laravel 5.6.

tykus
tykus
7 months ago (692,230 XP)

I use RefreshDatabase trait in Testcase.php

How/where do you use RefreshDatabase inside TestCase.php?

bestmomo
abstract class TestCase extends BaseTestCase
{
    use CreatesApplication, RefreshDatabase;

    /**
     * Authentification.
     *
     * @return void
     */
    protected function auth($id) 
    {
        $user = User::find($id);

        $this->actingAs($user);
    }
}

In fact I have my own method, but not the problem :

use CreatesApplication, RefreshDatabase, Init {
    Init::refreshInMemoryDatabase insteadof RefreshDatabase;
}
tykus
tykus
7 months ago (692,230 XP)

Hmmm... can't replicate. I have taken a 5.6 project and moved use RefreshDatabase from the test classes into TestCase like you describe, but everything continues to work - also for an in-memory sqlite database.

¯\_(ツ)_/¯
bestmomo

Ok, thanks to answer ;)

Please sign in or create an account to participate in this conversation.