captureDeprecations(function () { // Laravel 부팅 후 config 파일을 재include — database_path() 등 헬퍼 사용 가능 $config = require config_path('database.php'); $mysqlOptions = $config['connections']['mysql']['options']; $mariadbOptions = $config['connections']['mariadb']['options']; // array_filter 결과를 실제로 순회하여 키 상수 평가 강제 foreach ($mysqlOptions as $k => $v) { $unused = $k; } foreach ($mariadbOptions as $k => $v) { $unused = $k; } }); $this->assertEmpty( $deprecations, 'config/database.php emitted PHP deprecation: ' . json_encode($deprecations, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) ); } public function test_config_file_does_not_reference_unguarded_deprecated_pdo_constant(): void { $file = file_get_contents(config_path('database.php')); // 가드 패턴: PHP_VERSION_ID >= 80500 ternary 안에서만 PDO::MYSQL_ATTR_SSL_CA 사용 허용 $guardedPattern = '/PHP_VERSION_ID\s*>=\s*80500.*?Pdo\\\\Mysql::ATTR_SSL_CA.*?PDO::MYSQL_ATTR_SSL_CA/s'; $hasGuard = (bool) preg_match($guardedPattern, $file); // 직접 참조 횟수 $directReferences = preg_match_all('/PDO::MYSQL_ATTR_SSL_CA/', $file); if ($directReferences > 0 && ! $hasGuard) { $this->fail( "config/database.php references PDO::MYSQL_ATTR_SSL_CA without a " . "PHP_VERSION_ID >= 80500 ternary guard. This causes E_DEPRECATED " . "on PHP 8.5+. Use \\Pdo\\Mysql::ATTR_SSL_CA when PHP_VERSION_ID >= 80500." ); } $this->assertTrue(true); } /** * @param callable $fn 실행 중 발생한 deprecation 을 수집할 콜백 * @return array */ private function captureDeprecations(callable $fn): array { $deprecations = []; set_error_handler(function ($severity, $message, $file, $line) use (&$deprecations) { if ($severity === E_DEPRECATED || $severity === E_USER_DEPRECATED) { if (str_contains($message, 'PDO::') || str_contains($message, 'MYSQL_ATTR_')) { $deprecations[] = compact('message', 'file', 'line'); } } return true; }, E_DEPRECATED | E_USER_DEPRECATED); try { $fn(); } finally { restore_error_handler(); } return $deprecations; } }