Make sure test targets are sanitized in a windows-compatible way

This commit is contained in:
Alex Rock Ancelet
2020-05-28 23:12:16 +02:00
committed by Dimitrios Karvounaris
parent b0c964d4d9
commit 3d2c83a501

View File

@ -59,7 +59,17 @@ final class UsesCall
public function in(string ...$targets): void
{
$targets = array_map(function ($path): string {
return $path[0] === DIRECTORY_SEPARATOR
$startChar = DIRECTORY_SEPARATOR;
if ('\\' === DIRECTORY_SEPARATOR) {
$path = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', function ($match): string {
return strtolower($match['drive']);
}, $path);
$startChar = strtolower((string) preg_replace('~^([a-z]+:\\\).*$~i', '$1', __DIR__));
}
return 0 === strpos($path, $startChar)
? $path
: implode(DIRECTORY_SEPARATOR, [
dirname($this->filename),
@ -68,12 +78,12 @@ final class UsesCall
}, $targets);
$this->targets = array_map(function ($target): string {
$realTarget = realpath($target);
if ($realTarget === false) {
throw new InvalidUsesPath($target);
$isValid = is_dir($target) || file_exists($target);
if (!$isValid) {
throw new InvalidUsesPath($target . "\n");
}
return $realTarget;
return $target;
}, $targets);
}