Skip to content
Advertisement

Testing method which need log in

I want to testing some method like user (method need log in user).

$user = User::find(1);
$response = $this->actingAs($user)->json('POST', '/store/post', [
            'title' => 'Hello World',
            'description' => 'Hello World. We are Anonymous.',
            'user_id' => 1
]);

$response
    ->assertStatus(201)
    ->assertJson([
        'created' => true,
    ]);

I have this error (I don’t know hov I can add all error so I show parts of that):

1) TestsFeatureExampleTest::testBasicExample

IlluminateDatabaseQueryException: could not find driver (SQL: PRAGMA foreign_keys = ON;)
//...
Caused by
DoctrineDBALDriverPDOException: could not find driver
//...
Caused by
PDOException: could not find driver

This same problem I have, if I tryed use Factory like on docs. How I can solve my problem?

Advertisement

Answer

I believe you are using sqlite for mocking the database in PHPUnit In case of php5

sudo apt-get install php5-sqlite

of in case of php7

sudo apt-get install php7-sqlite

than restart the apache server

sudo service apache2 restart
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement