From 36782ebee76c88dd55c0a016c74e873802e9c778 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 8 Jun 2026 11:51:35 +0200 Subject: [PATCH] Move mysql charset/collation validation assertions to a dedicated test --- tests/TenantDatabaseManagerTest.php | 33 +++++++++++++---------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/tests/TenantDatabaseManagerTest.php b/tests/TenantDatabaseManagerTest.php index a123b2d8..692528fe 100644 --- a/tests/TenantDatabaseManagerTest.php +++ b/tests/TenantDatabaseManagerTest.php @@ -571,24 +571,6 @@ test('database managers validate parameters that cannot be bound', function ($dr expect(fn () => $manager->deleteDatabase($tenant)) ->toThrow(InvalidArgumentException::class, 'Forbidden character'); - - if ($driver === 'mysql') { - // MySQLDatabaseManager reads charset/collation from config. - // An exception is thrown during validation if the parameter is not a string. - config(['database.connections.mysql.charset' => []]); - DB::purge('mysql'); - - $tenantWithNonStringCharset = Tenant::make([ - 'tenancy_db_name' => 'valid_db_name', - ]); - - expect(fn () => $manager->createDatabase($tenantWithNonStringCharset)) - ->toThrow(InvalidArgumentException::class, 'Parameter has to be a string.'); - - // Restore the default charset - config(['database.connections.mysql.charset' => 'utf8mb4']); - DB::purge('mysql'); - } } else { // Invalid username, createUser() and deleteUser() should // throw an invalid argument exception. @@ -646,6 +628,21 @@ test('database managers validate parameters that cannot be bound', function ($dr } })->with('database_managers'); +test('mysql database manager validates charset and collation correctly', function () { + $manager = app(MySQLDatabaseManager::class); + $manager->setConnection('mysql'); + + config(['database.connections.mysql.charset' => []]); + DB::purge('mysql'); + + $tenant = Tenant::make([ + 'tenancy_db_name' => 'valid_db_name', + ]); + + expect(fn () => $manager->createDatabase($tenant)) + ->toThrow(InvalidArgumentException::class, 'Parameter has to be a string.'); +}); + test('sqlite database manager validates database names correctly', function () { $manager = app(SQLiteDatabaseManager::class);