Skip to content

Commit

Permalink
Respect directory separator
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Feb 19, 2024
1 parent 8c71eb5 commit a256e99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ public function testLocateFromASingleDirectory(): void
}

$foundFiles = $this->locate([$dir], '.php', null);
$foundFiles = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $foundFiles);

$this->assertCount(count($files), $foundFiles);
foreach ($files as $file) {
$this->assertContains($file, str_replace('\\', '/', $foundFiles));
$this->assertContains($file, $foundFiles);
}
}

Expand Down Expand Up @@ -157,7 +158,7 @@ private function locate(array $directories, string $fileExtension, array|null $b
{
$files = [];
foreach (($this->locator)(new ArrayObject($directories), $fileExtension, $blacklist) as $file) {
$files[] = str_replace('\\', '/', $file);
$files[] = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $file);
}

return $files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testSingleDependency(): void
$this->assertCount(1, $files);

$expectedFile = $this->path('vendor/foo/bar/src/MyClass.php');
$actualFile = str_replace('\\', '/', reset($files));
$actualFile = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, reset($files));
$this->assertSame($expectedFile, $actualFile);
}

Expand All @@ -89,7 +89,7 @@ public function testVendorConfigSettingIsBeingUsed(): void
$this->assertCount(1, $files);

$expectedFile = $this->path('alternate-vendor/foo/bar/src/MyClass.php');
$actualFile = str_replace('\\', '/', reset($files));
$actualFile = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, reset($files));
$this->assertSame($expectedFile, $actualFile);
}

Expand All @@ -104,7 +104,7 @@ public function testInstalledJsonUsedAsFallback(): void
$this->assertCount(1, $files);

$expectedFile = $this->path('vendor/foo/bar/src/MyClass.php');
$actualFile = str_replace('\\', '/', reset($files));
$actualFile = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, reset($files));
$this->assertSame($expectedFile, $actualFile);

// Ensure we didn't leave our temporary composer.json lying around
Expand All @@ -125,7 +125,7 @@ public function testOldInstalledJsonUsedAsFallback(): void
$this->assertCount(1, $files);

$expectedFile = $this->path('vendor/foo/bar/src/MyClass.php');
$actualFile = str_replace('\\', '/', reset($files));
$actualFile = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, reset($files));
$this->assertSame($expectedFile, $actualFile);

// Ensure we didn't leave our temporary composer.json lying around
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private function files(string $composerJson): array
$files = [];
$filesGenerator = ($this->locator)($composerData, dirname($composerJson));
foreach ($filesGenerator as $file) {
$files[] = str_replace('\\', '/', $file);
$files[] = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $file);
}

return $files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use PHPUnit\Framework\TestCase;
use Spatie\TemporaryDirectory\TemporaryDirectory;

use function array_map;
use function realpath;
use function str_replace;
use function touch;

Expand Down Expand Up @@ -43,10 +45,13 @@ public function testGlobPattern(): void
touch($this->path('bin/console123.php'));
touch($this->path('bin/not-console'));

$files = $this->files(['bin/console*.php'], $this->root->path() . '/');
$files = $this->files(['bin' . DIRECTORY_SEPARATOR . 'console*.php'], $this->root->path() . DIRECTORY_SEPARATOR);
$files = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $files);
$files = array_map('realpath', $files);

self::assertCount(2, $files);
self::assertContains($this->path('bin/console.php'), $files);
self::assertContains($this->path('bin/console123.php'), $files);
self::assertContains(realpath($this->path('bin/console.php')), $files);
self::assertContains(realpath($this->path('bin/console123.php')), $files);
}

/**
Expand All @@ -59,7 +64,7 @@ private function files(array $globPatterns, string $dir): array
$files = [];
$filesGenerator = ($this->locator)($globPatterns, $dir);
foreach ($filesGenerator as $file) {
$files[] = $file;
$files[] = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $file);
}

return $files;
Expand Down

0 comments on commit a256e99

Please sign in to comment.