mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 10:17:23 +01:00
Make sure test targets are sanitized in a windows-compatible way
This commit is contained in:
committed by
Dimitrios Karvounaris
parent
b0c964d4d9
commit
3d2c83a501
@ -59,7 +59,17 @@ final class UsesCall
|
|||||||
public function in(string ...$targets): void
|
public function in(string ...$targets): void
|
||||||
{
|
{
|
||||||
$targets = array_map(function ($path): string {
|
$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
|
? $path
|
||||||
: implode(DIRECTORY_SEPARATOR, [
|
: implode(DIRECTORY_SEPARATOR, [
|
||||||
dirname($this->filename),
|
dirname($this->filename),
|
||||||
@ -68,12 +78,12 @@ final class UsesCall
|
|||||||
}, $targets);
|
}, $targets);
|
||||||
|
|
||||||
$this->targets = array_map(function ($target): string {
|
$this->targets = array_map(function ($target): string {
|
||||||
$realTarget = realpath($target);
|
$isValid = is_dir($target) || file_exists($target);
|
||||||
if ($realTarget === false) {
|
if (!$isValid) {
|
||||||
throw new InvalidUsesPath($target);
|
throw new InvalidUsesPath($target . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $realTarget;
|
return $target;
|
||||||
}, $targets);
|
}, $targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user