From 3ae7aef663a9986d127662e7b682e3a5e09fadb1 Mon Sep 17 00:00:00 2001 From: Pouya Date: Sun, 9 Nov 2025 01:39:25 +0330 Subject: [PATCH 1/2] [12.x] Fix safely updating SQLite in-memory connections after re-migration in tests --- .../Foundation/Testing/RefreshDatabase.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/RefreshDatabase.php b/src/Illuminate/Foundation/Testing/RefreshDatabase.php index f039c510f8c2..f70cdbd2809c 100644 --- a/src/Illuminate/Foundation/Testing/RefreshDatabase.php +++ b/src/Illuminate/Foundation/Testing/RefreshDatabase.php @@ -85,12 +85,31 @@ protected function refreshTestDatabase() $this->app[Kernel::class]->setArtisan(null); + $this->updateInMemoryConnections(); + RefreshDatabaseState::$migrated = true; } $this->beginDatabaseTransaction(); } + /** + * Update stored in-memory PDO connections after migration. + * + * @return void + */ + protected function updateInMemoryConnections() + { + $database = $this->app->make('db'); + + foreach ($this->connectionsToTransact() as $name) { + if ($this->usingInMemoryDatabase($name)) { + $connection = $database->connection($name); + RefreshDatabaseState::$inMemoryConnections[$name] = $connection->getPdo(); + } + } + } + /** * Migrate the database. * From 162136d8f0ea0e7f1b945fe06f17895388265d09 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 16 Nov 2025 17:34:06 -0600 Subject: [PATCH 2/2] Update RefreshDatabase.php --- src/Illuminate/Foundation/Testing/RefreshDatabase.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/RefreshDatabase.php b/src/Illuminate/Foundation/Testing/RefreshDatabase.php index f70cdbd2809c..28626ec5e706 100644 --- a/src/Illuminate/Foundation/Testing/RefreshDatabase.php +++ b/src/Illuminate/Foundation/Testing/RefreshDatabase.php @@ -85,7 +85,7 @@ protected function refreshTestDatabase() $this->app[Kernel::class]->setArtisan(null); - $this->updateInMemoryConnections(); + $this->updateLocalCacheOfInMemoryDatabases(); RefreshDatabaseState::$migrated = true; } @@ -94,18 +94,17 @@ protected function refreshTestDatabase() } /** - * Update stored in-memory PDO connections after migration. + * Update locally cached in-memory PDO connections after migration. * * @return void */ - protected function updateInMemoryConnections() + protected function updateLocalCacheOfInMemoryDatabases() { $database = $this->app->make('db'); foreach ($this->connectionsToTransact() as $name) { if ($this->usingInMemoryDatabase($name)) { - $connection = $database->connection($name); - RefreshDatabaseState::$inMemoryConnections[$name] = $connection->getPdo(); + RefreshDatabaseState::$inMemoryConnections[$name] = $database->connection($name)->getPdo(); } } }