@alkhatib Do you have a migration for "settings" table?
SQLSTATE[HY000]: General error: 1 no such table
Hello, When running tests, I'm encountering an error because a specific database table cannot be found. The error seems to occur due to a query in the AppProviderService. How can I ensure that the database is fully set up and accessible during tests to prevent this issue?
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>app</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_STORE" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="MAIL_MAILER" value="array"/>
<env name="PULSE_ENABLED" value="false"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
Pest.php
pest()
->extend(Tests\TestCase::class)
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
->in('Feature');
DashboardPanelProvider
class DashboardPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('dashboard')
->path(Settings::dashboardPrefix());
}
}
test
/** @test */
it('renders successfully', function () {
$response = $this->get(route('login'));
$response
->assertSeeLivewire(Login::class)
->assertStatus(200);
});
error
FAILED Tests\Feature\Livewire\Auth\LoginTest > it renders successfully QueryException
SQLSTATE[HY000]: General error: 1 no such table: settings (Connection: sqlite, SQL: select "name", "payload" from "settings" where "group" = system)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:407
403▕ // For select statements, we'll simply execute the query and return an array
404▕ // of the database result set. Each element in the array will be a single
405▕ // row from the database table, and will either be an array or objects.
406▕ $statement = $this->prepared(
➜ 407▕ $this->getPdoForSelect($useReadPdo)->prepare($query)
408▕ );
409▕
410▕ $this->bindValues($statement, $this->prepareBindings($bindings));
411▕
+15 vendor frames
16 app/Services/Settings/Concerns/HasSystem.php:56
+1 vendor frames
18 app/Providers/Filament/DashboardPanelProvider.php:32
Tests: 1 failed (0 assertions)
Duration: 7.82s
@alkhatib Here are a few references to similar errors: https://github.com/laravel/framework/issues/25223 https://laracasts.com/discuss/channels/laravel/queryexception-general-error-1-no-such-table-categories https://laracasts.com/discuss/channels/testing/sqlstatehy000-general-error-1-no-such-table
Most of them say that the AppServiceProvider's boot method executes before table creation. Hence the error.
Hope you can find the solution in these links.
Please or to participate in this conversation.