Skip to content

Commit f04fb3a

Browse files
[12.x] Fix stale in-memory SQLite connections after re-migration in RefreshDatabase (#57716)
* [12.x] Fix safely updating SQLite in-memory connections after re-migration in tests * Update RefreshDatabase.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent fa96878 commit f04fb3a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Illuminate/Foundation/Testing/RefreshDatabase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,30 @@ protected function refreshTestDatabase()
8585

8686
$this->app[Kernel::class]->setArtisan(null);
8787

88+
$this->updateLocalCacheOfInMemoryDatabases();
89+
8890
RefreshDatabaseState::$migrated = true;
8991
}
9092

9193
$this->beginDatabaseTransaction();
9294
}
9395

96+
/**
97+
* Update locally cached in-memory PDO connections after migration.
98+
*
99+
* @return void
100+
*/
101+
protected function updateLocalCacheOfInMemoryDatabases()
102+
{
103+
$database = $this->app->make('db');
104+
105+
foreach ($this->connectionsToTransact() as $name) {
106+
if ($this->usingInMemoryDatabase($name)) {
107+
RefreshDatabaseState::$inMemoryConnections[$name] = $database->connection($name)->getPdo();
108+
}
109+
}
110+
}
111+
94112
/**
95113
* Migrate the database.
96114
*

0 commit comments

Comments
 (0)