markTestSkipped('Set LOGIN_LOG_TEST_MYSQL_SOCKET to a disposable MySQL server.'); } $this->control = new PDO('mysql:unix_socket=' . $socket, 'root', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $this->database = 'bot28_login_log_test_' . bin2hex(random_bytes(8)); $this->control->exec('CREATE DATABASE `' . $this->database . '` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci'); parent::setUp(); // Reproduce the deployed schema: accounts and user IDs can have different collations. DB::statement('ALTER TABLE bot_users MODIFY user_id VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, MODIFY account VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL'); } protected function tearDown(): void { if ($this->control !== null) { parent::tearDown(); $this->control->exec('DROP DATABASE `' . $this->database . '`'); $this->control = null; } } protected function connectionConfig(): array { return [ 'driver' => 'mysql', 'unix_socket' => getenv('LOGIN_LOG_TEST_MYSQL_SOCKET'), 'database' => $this->database, 'username' => 'root', 'password' => '', 'prefix' => 'bot_', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ]; } public function test_account_matching_keeps_case_insensitive_and_unicode_semantics(): void { DB::table('users')->insert([ 'user_id' => '9004', 'member_id' => 'support-unicode', 'account' => '客服É', 'from' => '0', ]); $this->log('', 'KEFU001', 0); $this->log('', '客服é', 0); $expected = [$this->log('', '其他账号', 0), $this->log('1001', 'ALICE', 0)]; $data = $this->logs(['status' => 0]); $this->assertSame(2, $data['total']); $this->assertSame(array_reverse($expected), array_column($data['data'], 'id')); } }