Ashley Clarke
Ashley Clarke

Reputation: 446

Laravel DatabaseTransactions, DatabaseMigrations have no effect when testing

I have the following test class

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ProvidersTest extends TestCase
{
    use DatabaseMigrations;

    /**
     * @var \Orka\Entities\User
     */
    protected $user;

    public function setUp()
    {
        parent::setUp();
        $user = factory(\Orka\Entities\User::class)->create();
        $this->user = $user;
    }

    /**
     * @test
     */
    public function it_shows_no_connected_providers()
    {
        $this
            ->actingAs($this->user)
            ->visit('/teams/1/providers')
            ->see('You have not connected a provider yet.')
        ;
    }
}

When running this code I get an error telling me tables do no exist, the only way I can get it to work is to call $this->runDatabaseMigrations(); in the setUp() method, but as far as I know I should not need to do that. I have similar issues with DatabaseTransactions.

Laravel 5.1.23

Any ideas on why this is happening as the docs say that it should be triggered automatically.

Upvotes: 2

Views: 1042

Answers (2)

Nabsta
Nabsta

Reputation: 101

I'm having the same problem. I ended up going the route of using shell_exec() to drop, create, and reseed the database with a mysql.dump file. It's a pretty sloppy alternative, but the only thing that seems to be working right now, short of writing a bunch of SQL scripts to put everything in.

Laravel 5 Reseeding the Database for Unit Testing Between Tests

Upvotes: 1

Related Questions