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.
This commit is contained in:
Dimitrios Karvounaris
2020-06-05 18:24:03 +02:00
parent 6e18912ea6
commit dff9bbc134

View File

@ -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;
}