1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 16:24:03 +00:00

Query for MySQL defaults instead of assuming them in charset test

This commit is contained in:
lukinovec 2026-05-04 11:54:45 +02:00
parent 2b3466f951
commit 338526d9fb

View file

@ -672,8 +672,11 @@ test('newly created tenant databases use the correct charset and collation with
withBootstrapping(); withBootstrapping();
$charset = fn () => DB::selectOne('SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = DATABASE()')->DEFAULT_CHARACTER_SET_NAME; $serverDefaultCharset = DB::selectOne('SELECT @@character_set_server AS charset')->charset;
$collation = fn () => DB::selectOne('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = DATABASE()')->DEFAULT_COLLATION_NAME; $serverDefaultCollation = DB::selectOne('SELECT @@collation_server AS collation')->collation;
$databaseCharset = fn () => DB::selectOne('SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = DATABASE()')->DEFAULT_CHARACTER_SET_NAME;
$databaseCollation = fn () => DB::selectOne('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = DATABASE()')->DEFAULT_COLLATION_NAME;
$defaultTenant = Tenant::create(); $defaultTenant = Tenant::create();
@ -681,8 +684,8 @@ test('newly created tenant databases use the correct charset and collation with
// No charset or collation specified, // No charset or collation specified,
// defaults from the MySQL config used. // defaults from the MySQL config used.
expect($charset())->toBe('utf8mb4'); expect($databaseCharset())->toBe('utf8mb4');
expect($collation())->toBe('utf8mb4_unicode_ci'); expect($databaseCollation())->toBe('utf8mb4_unicode_ci');
$tenantWithCharsetAndCollation = Tenant::create([ $tenantWithCharsetAndCollation = Tenant::create([
'tenancy_db_charset' => 'latin1', 'tenancy_db_charset' => 'latin1',
@ -692,8 +695,8 @@ test('newly created tenant databases use the correct charset and collation with
tenancy()->initialize($tenantWithCharsetAndCollation); tenancy()->initialize($tenantWithCharsetAndCollation);
// Custom charset and collation from tenant config // Custom charset and collation from tenant config
expect($charset())->toBe('latin1'); expect($databaseCharset())->toBe('latin1');
expect($collation())->toBe('latin1_swedish_ci'); expect($databaseCollation())->toBe('latin1_swedish_ci');
$tenantWithNullCharsetAndCollation = Tenant::create([ $tenantWithNullCharsetAndCollation = Tenant::create([
'tenancy_db_charset' => null, 'tenancy_db_charset' => null,
@ -703,8 +706,9 @@ test('newly created tenant databases use the correct charset and collation with
tenancy()->initialize($tenantWithNullCharsetAndCollation); tenancy()->initialize($tenantWithNullCharsetAndCollation);
// Default MySQL server charset and collation // Default MySQL server charset and collation
expect($charset())->toBe('utf8mb4'); // (e.g. charset = utf8mb4, collation = utf8mb4_0900_ai_ci)
expect($collation())->toBe('utf8mb4_0900_ai_ci'); expect($databaseCharset())->toBe($serverDefaultCharset);
expect($databaseCollation())->toBe($serverDefaultCollation);
$tenantWithCharsetAndNullCollation = Tenant::create([ $tenantWithCharsetAndNullCollation = Tenant::create([
'tenancy_db_charset' => 'binary', 'tenancy_db_charset' => 'binary',
@ -715,8 +719,8 @@ test('newly created tenant databases use the correct charset and collation with
// Charset specified, collation is null, // Charset specified, collation is null,
// MySQL will choose a default collation for the specified charset. // MySQL will choose a default collation for the specified charset.
expect($charset())->toBe('binary'); expect($databaseCharset())->toBe('binary');
expect($collation())->toBe('binary'); expect($databaseCollation())->toBe('binary');
// Collation specified, charset is null, // Collation specified, charset is null,
// MySQL will choose a default charset for the specified collation. // MySQL will choose a default charset for the specified collation.
@ -727,8 +731,8 @@ test('newly created tenant databases use the correct charset and collation with
tenancy()->initialize($tenantWithCollationAndNullCharset); tenancy()->initialize($tenantWithCollationAndNullCharset);
expect($charset())->toBe('latin1'); expect($databaseCharset())->toBe('latin1');
expect($collation())->toBe('latin1_swedish_ci'); expect($databaseCollation())->toBe('latin1_swedish_ci');
}); });
// Datasets // Datasets