From dff9bbc1349b8600cd93d48fad7b36266020a06e Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 18:24:03 +0200 Subject: [PATCH] Fix file paths not being used properly basename() will strip full path information on some systems. What is needed is to use both dirname() & basename() on paths, as recognized by all systems, and only afterwards do any replacements. --- src/Factories/TestCaseFactory.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 05859fdd..022c0d1a 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -165,18 +165,18 @@ final class TestCaseFactory }, $filename); } - $filename = realpath($filename); + $filename = realpath($filename); $rootPath = TestSuite::getInstance()->rootPath; $relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename); + $relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php'); + $relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath); + // Strip out any %-encoded octets. $relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath); - $relativePath = str_replace('\\', '/', $relativePath); - // Limit to A-Z, a-z, 0-9, '_', '-'. - $relativePath = (string) preg_replace('/[^A-Za-z0-9.\/]/', '', $relativePath); - - $classFQN = 'P\\' . basename(ucfirst(str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath)), '.php'); + $relativePath = (string) preg_replace('/[^A-Za-z0-9.\\\]/', '', $relativePath); + $classFQN = 'P\\' . $relativePath; if (class_exists($classFQN)) { return $classFQN; }