ohffs's avatar
Level 50

Dusk tests on upgraded L5.5 app report readonly database

I've been stuck on this for a while so finally giving in and asking...

I've updated an app from 5.4 -> 5.5 and all is good. Reguar phpunit tests all pass. But the dusk tests fail whenever I'm using the database migrations trait with :

PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database

I've got dusk 2.x, pulled in the current dusk test case, re-installed the vendor/ folder etc - to no avail. If I change the database config to a non-existant sqlite file I get a proper 'does not exist' error - but no matter what valid, writeable sqlite file I set the config too I get the 'readonly' error. When I run the tests the timestamp on the sqlite file is updated so it's clearly doing something, but the file remains at zero bytes and the readonly error is thrown.

If I make a new dusk test it runs ok - but as soon as I add the use DatabaseMigrations it too fails with the readonly error.

I've tried a fresh install of L5.5 and don't get the same error - so "something" is wrong in the upgraded app. Has anyone else hit this?

0 likes
2 replies
ohffs's avatar
Level 50

Ok - sort of solved. I had code in my AppServiceProvider as follows :

if (DB::connection() instanceof \Illuminate\Database\SQLiteConnection) {
    DB::statement(DB::raw('PRAGMA foreign_keys=1'));
}

Which enforces 'proper' SQL foreign key constraints for sqlite (eg, triggers properly for onDelete()). But that seems to break dusk 2.x with the misleading 'readonly' error above. So commenting that out lets dusk work ok, but then phpunit fails because the code assume proper onDelete() functionality.

Replacing the above code with :

if ($this->app->environment('testing')) {
    DB::statement(DB::raw('PRAGMA foreign_keys=1'));
}

Then both dusk and phpunit run ok (my .env/dusk setting for APP_ENV is 'local', for plain phpunit it's 'testing').

Bit of a hack, but it'll do for now...

1 like

Please or to participate in this conversation.