How Is It Possible To Call Php Artisan Doctrine:schema:update Before The Testing Starts? PhpUnit

- 1 answer

I would like to test my project using PHPUnit. My project is built on Laravel and Doctrine. For testing I use an sqlite :memory: database. Since it is a memory database, I can not generate the tables from my entities before testing, and I have to call php artisan doctrine:schema:update when phpunitstarts.

I tried to add the RefreshDatabase trait to the class, but it still does not work:

namespace Tests\Unit\Example;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

use EntityManager;

class MyExampleTest extends TestCase

    use RefreshDatabase;

    // ...


I get this error:

General error: 1 no such table: users


If you want to run your migrations before each test you can use the Illuminate\Foundation\Testing\RefreshDatabase trait, this will set up the database tables from your migrations and clean everything before running the test.

so to use it include the class and add the use RefreshDatabase to your test class.

here is a link to the docs.