Skip to content

Commit

Permalink
Fix an issue where missing .env files result in an endless loop on Wi…
Browse files Browse the repository at this point in the history
…ndows, refs #34
  • Loading branch information
ffraenz committed Oct 29, 2020
1 parent 8ee419d commit a2e5d88
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Environment/LoaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
use FFraenz\PrivateComposerInstaller\Environment\LoaderInterface;

use function class_exists;
use function count;
use function dirname;
use function getcwd;
use function in_array;
use function realpath;

use const DIRECTORY_SEPARATOR;

class LoaderFactory
{
/**
Expand All @@ -38,13 +36,14 @@ public static function create(?string $path = null, ?string $name = null): Loade
*
* @return string[]
*/
private static function computePaths(string $path): array
public static function computePaths(string $path): array
{
$paths = [$path];
$path = dirname($path);

while (! in_array($path, ['.', DIRECTORY_SEPARATOR], true)) {
$path = dirname($path);
while ($paths[count($paths) - 1] !== $path) {
$paths[] = $path;
$path = dirname($path);
}

return $paths;
Expand Down
31 changes: 31 additions & 0 deletions test/unit/Environment/LoaderFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace FFraenz\PrivateComposerInstaller\Test\Environment;

use FFraenz\PrivateComposerInstaller\Environment\LoaderFactory;
use PHPUnit\Framework\TestCase;

use function implode;

class LoaderFactoryTest extends TestCase
{
public function testComputePaths()
{
self::assertSame(
'.',
implode(',', LoaderFactory::computePaths('.'))
);
self::assertSame(
'/',
implode(',', LoaderFactory::computePaths('/'))
);
self::assertSame(
'foo/bar,foo,.',
implode(',', LoaderFactory::computePaths('foo/bar'))
);
self::assertSame(
'/foo/bar,/foo,/',
implode(',', LoaderFactory::computePaths('/foo/bar'))
);
}
}

0 comments on commit a2e5d88

Please sign in to comment.