From 3ae7aef663a9986d127662e7b682e3a5e09fadb1 Mon Sep 17 00:00:00 2001
From: Pouya
Date: Sun, 9 Nov 2025 01:39:25 +0330
Subject: [PATCH] [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.
*