idan
idan

Reputation: 43

Schema File not run in tests

When I run tests I call migrate:fresh. The schema file is not running. I'm using mysql database for testing. migrate:fresh runs well in other environments. please anyone has an idea?

This is the command I'm using:

Artisan::call('migrate:fresh')

Upvotes: 0

Views: 692

Answers (1)

Allan
Allan

Reputation: 53

This probably happens because your test database doesn't have the same name as your dumped database, so laravel can't find the migration. A work around could be manually specify the dump path to the RefreshDatabase trait like that:

namespace Tests;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication, RefreshDatabase;

    protected function migrateFreshUsing()
    {
        return ['--schema-path' => 'database/schema/mysql-schema.dump'];
    }
}

Upvotes: 2

Related Questions