diff --git a/src/Environment/LoaderFactory.php b/src/Environment/LoaderFactory.php index e359d96..ba03805 100644 --- a/src/Environment/LoaderFactory.php +++ b/src/Environment/LoaderFactory.php @@ -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 { /** @@ -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; diff --git a/test/unit/Environment/LoaderFactoryTest.php b/test/unit/Environment/LoaderFactoryTest.php new file mode 100644 index 0000000..d5858a2 --- /dev/null +++ b/test/unit/Environment/LoaderFactoryTest.php @@ -0,0 +1,31 @@ +