jeudi 10 mars 2016

Get data from base in Laravel 5.1 tests

I have problem with database connection in tests. I don't want to create new user every test - I want to use existing user but when I try to use \App\User::find(1) I got error PDOException: could not find driver.

<?php

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

class CommentsTest extends TestCase
{
    public function testLogin()
    {
        $this->actingAs(\App\User::find(1))
             ->visit('/')
             ->see('Add comment');
    }
}

I'm using existing database and I'm not changing env file.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire