From 2440e56ac11f90ac99d566dd0be70331a3e5ff9e Mon Sep 17 00:00:00 2001 From: nuno maduro Date: Mon, 6 Jul 2026 13:18:03 +0100 Subject: [PATCH] fix: escape generated test case filename (#1747) Co-authored-by: Claude Opus 4.8 (1M context) --- src/Factories/TestCaseFactory.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 3349d03d..77328756 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -89,7 +89,8 @@ final class TestCaseFactory $filename = (string) preg_replace_callback('~^(?P[a-z]+:\\\)~i', static fn (array $match): string => strtolower($match['drive']), $filename); } - $filename = str_replace('\\\\', '\\', addslashes((string) realpath($filename))); + $realpath = (string) realpath($filename); + $filename = str_replace('\\\\', '\\', addslashes($realpath)); $rootPath = TestSuite::getInstance()->rootPath; $relativePath = str_replace($rootPath.DIRECTORY_SEPARATOR, '', $filename); @@ -144,6 +145,8 @@ final class TestCaseFactory $attributesCode = Attributes::code($this->attributes); + $filenameLiteral = var_export($realpath, true); + $methodsCode = implode('', array_map( fn (TestCaseMethodFactory $methodFactory): string => $methodFactory->buildForEvaluation(), $methods @@ -161,7 +164,7 @@ final class TestCaseFactory final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN { $traitsCode - private static \$__filename = '$filename'; + private static \$__filename = $filenameLiteral; $methodsCode }