Samstag, 27. Januar 2018

Laravel phpunit test drops migration tables in local database

I have a reoccuring problem that sometimes when i start the phpunit test all of the tables of my local db get dropped.

There is quite a simple solution :
do
php artisan config:clear
before starting the test run

To automatically do this i did this before every testing by calling

Artisan::call('config:clear');

in setup method of the TestCase.php file:

  protected function setUp()
    {
        parent::setUp();
        Artisan::call('config:clear');
      
    }

An import of the Artisan Class is needed, so I put

use Illuminate\Support\Facades\Artisan;

in the top part of the TestCase.php class:

<?php
namespace Tests;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;