From 7f93f4460a956628df759937423172f49a59c196 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 1 May 2026 14:35:18 +0200 Subject: [PATCH] Test that the SQLite DB manager recognizes in-memory DBs --- tests/TenantDatabaseManagerTest.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/TenantDatabaseManagerTest.php b/tests/TenantDatabaseManagerTest.php index 0a51bd1d..caa9109e 100644 --- a/tests/TenantDatabaseManagerTest.php +++ b/tests/TenantDatabaseManagerTest.php @@ -615,7 +615,7 @@ test('database managers validate parameters that cannot be bound', function ($dr } })->with('database_managers'); -test('sqlite database manager validates database names', function () { +test('sqlite database manager validates database names correctly', function () { $manager = app(SQLiteDatabaseManager::class); // Dots are allowed in database names @@ -629,14 +629,19 @@ test('sqlite database manager validates database names', function () { // Empty strings are considered invalid input for database names expect(fn () => $manager->databaseExists('')) ->toThrow(InvalidArgumentException::class); +}); - // In-memory database names have to start with 'file:_tenancy_inmemory_' - expect(fn () => $manager->databaseExists('file:_tenancy_inmemory_123?mode=memory&cache=shared')) - ->not()->toThrow(InvalidArgumentException::class); +test('sqlite database manager recognizes inmemory databases correctly', function () { + $manager = app(SQLiteDatabaseManager::class); - // Doesn't start with 'file:_tenancy_inmemory_', not considered an in-memory database, filename validation applies - expect(fn () => $manager->databaseExists('../_tenancy_inmemory_')) - ->toThrow(InvalidArgumentException::class); + expect($manager->isInMemory('file:_tenancy_inmemory_123?mode=memory&cache=shared'))->toBeTrue(); + expect($manager->isInMemory(':memory:'))->toBeTrue(); + + // Missing the '?mode=memory&cache=shared' suffix + expect($manager->isInMemory('file:_tenancy_inmemory_456'))->toBeFalse(); + + // Doesn't start with 'file:_tenancy_inmemory_' + expect($manager->isInMemory('_tenancy_inmemory_123?mode=memory&cache=shared'))->toBeFalse(); }); // Datasets