Reputation: 7184
I'm getting this error:
Database (homestead) does not exist.
When I try this simple Dusk test:
class ShowArticleTest extends DuskTestCase
{
use DatabaseMigrations;
/** @test */
public function it_shows_all_articles()
{
Article::create([
'title' => 'My First Article',
'body' => 'Some body text.'
]);
$this->browse(function (Browser $browser) {
$browser->visit('/articles')
->assertSee('My First Article');
});
}
}
I can see in the stack trace that the error comes from the controller method that handles the /articles
request, which looks like this:
public function all()
{
Article::all();
}
So it seems that the database is accessible by the test itself but not by the controller.
The .env.dusk.local
file looks like this:
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
The homestead
file is being created in my project root folder. The file is found inside the virtual machine too and the permissions looks like this:
-rw-rw-r-- 1 vagrant vagrant
Tried setting DATABASE
to database/testing.sqlite
in .env.dusk.local
. The file is created once Dusk starts but the error still says that it can't find the database/testing.sqlite
database.
Database (database/testing.sqlite) does not exist.
The database file can be accessed using the sqlite3
CLI and I can query for records without problem.
I'm using Laravel 5.5 and Homestead.
Upvotes: 1
Views: 927
Reputation: 7184
The problem occurs inside config/database.php
, around here:
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
]
Because DB_DATABASE
inside .env.dusk.local
is defined as homestead
, the configuration value for database.connections.sqlite.database
ends up just the same: homestead
.
The actual value should be the full path to the file, which can be obtained with the database_path()
helper. So, by simple moving database_path()
out of the env()
call:
'database' => database_path(env('DB_DATABASE', 'database.sqlite'))
The value for database.connections.sqlite.database
becomes the full path to the database file and everything seems to be working.
Upvotes: 5