From ffe3c3e8392286739bc346429be3cd645b554175 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 May 2020 23:11:14 +0200 Subject: [PATCH 1/5] Don't use "reapath" in binary for cross-compatibility --- bin/pest | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/pest b/bin/pest index 9b66a2b6b..5ff4eea1d 100755 --- a/bin/pest +++ b/bin/pest @@ -1,6 +1,7 @@ #!/usr/bin/env php register(); + (new Provider())->register(); $rootPath = getcwd(); From ba66ef140013d15660389514701de1ba265848aa Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 May 2020 23:12:16 +0200 Subject: [PATCH 2/5] Make sure test targets are sanitized in a windows-compatible way --- src/PendingObjects/UsesCall.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/PendingObjects/UsesCall.php b/src/PendingObjects/UsesCall.php index d7cfc1f62..56205be81 100644 --- a/src/PendingObjects/UsesCall.php +++ b/src/PendingObjects/UsesCall.php @@ -59,7 +59,17 @@ public function __construct(string $filename, array $classAndTraits) 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[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 @@ public function in(string ...$targets): void }, $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); } From 82796511b4ef6bc80136ee0379c964d6b93ad962 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Sat, 30 May 2020 00:10:48 +0200 Subject: [PATCH 3/5] Make sure PHP is called before calling pest as sub process --- tests/Visual/SingleTestOrDirectory.php | 2 +- tests/Visual/Success.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index d86fc4c91..b2200ed8a 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -3,7 +3,7 @@ use Symfony\Component\Process\Process; $run = function (string $target) { - $process = new Process(['./bin/pest', $target], dirname(__DIR__, 2)); + $process = new Process(['php', 'bin/pest', $target], dirname(__DIR__, 2)); $process->run(); diff --git a/tests/Visual/Success.php b/tests/Visual/Success.php index 70d11a523..d327beb5a 100644 --- a/tests/Visual/Success.php +++ b/tests/Visual/Success.php @@ -9,7 +9,7 @@ ]); $output = function () use ($testsPath) { - $process = (new Symfony\Component\Process\Process(['./bin/pest'], dirname($testsPath), ['EXCLUDE' => 'integration', 'REBUILD_SNAPSHOTS' => false])); + $process = (new Symfony\Component\Process\Process(['php', 'bin/pest'], dirname($testsPath), ['EXCLUDE' => 'integration', 'REBUILD_SNAPSHOTS' => false])); $process->run(); From df927307fcf594ef285fd97bc1885a244ae7488f Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Sat, 30 May 2020 00:11:26 +0200 Subject: [PATCH 4/5] Normalize Windows dir name in TestCaseFactory --- src/Factories/TestCaseFactory.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index b04efb6ce..3fe45ae1b 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -152,10 +152,18 @@ public function build(TestSuite $testSuite): array */ public function makeClassFromFilename(string $filename): string { + if ('\\' === DIRECTORY_SEPARATOR) { + // In case Windows, strtolower drive name, like in UsesCall. + $filename = (string) preg_replace_callback('~^(?P[a-z]+:\\\)~i', function ($match): string { + return strtolower($match['drive']); + }, $filename); + } + $rootPath = TestSuite::getInstance()->rootPath; $relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename); // 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); From 2297d2529c54ea59712794e5764ece96fa09508c Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Sat, 30 May 2020 00:11:47 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Not=20sure=20about=20this=20commit=20?= =?UTF-8?q?=F0=9F=A4=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Factories/TestCaseFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 3fe45ae1b..d6454ad64 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -168,7 +168,7 @@ public function makeClassFromFilename(string $filename): string // 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'); + $classFQN = 'P\\' . preg_replace('~\.php$~i', '', ucfirst(str_replace('/', '\\', $relativePath))); if (class_exists($classFQN)) { return $classFQN;