I’m having trouble with my Laravel feature tests using Pest. Despite using the RefreshDatabase
trait, my SQLite database isn’t being refreshed between test executions. This causes test failures, as some tests incorrectly find persisted data from previous tests.
Here’s what I’ve observed:
-
SQLite version: 3.37.2
-
Rollback confirmation: I’ve verified that the application is correctly rolling back transactions after each test (
Illuminate\Database\Concerns\ManagesTransactions:309
$pdo->rollBack()
returningtrue
). -
Data persistence: Models created during tests are still visible in the database after the test suite runs.
Code Snippet:
it('test1', function () {
Testmodel::create(['foo' => 'bar');
expect(Testmodel::count())->toBe(1); // this test succeeds
});
it('test2', function () {
expect(Testmodel::count())->toBe(0); // this test fails
});
Am I misunderstanding how RefreshDatabase works with SQLite? Why isn’t the data being cleared despite successful transaction rollbacks?
Thanks for your help!