From a2e5d88db53991dc3d984ce9808f3369413f948d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A4nz=20Friederes?= Date: Thu, 29 Oct 2020 19:01:54 +0100 Subject: [PATCH] Fix an issue where missing .env files result in an endless loop on Windows, refs #34 --- src/Environment/LoaderFactory.php | 11 ++++---- test/unit/Environment/LoaderFactoryTest.php | 31 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 test/unit/Environment/LoaderFactoryTest.php 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 @@ +