diff --git a/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php b/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php index 2fa429f83034..4771d5d10505 100644 --- a/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php +++ b/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php @@ -5,6 +5,7 @@ use Illuminate\Config\Repository; use Illuminate\Contracts\Config\Repository as RepositoryContract; use Illuminate\Contracts\Foundation\Application; +use Illuminate\Support\Collection; use SplFileInfo; use Symfony\Component\Finder\Finder; @@ -69,7 +70,7 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $ ? $this->getBaseConfiguration() : []; - foreach (array_diff(array_keys($base), array_keys($files)) as $name => $config) { + foreach ((new Collection($base))->diffKeys($files) as $name => $config) { $repository->set($name, $config); } diff --git a/tests/Foundation/Bootstrap/LoadConfigurationTest.php b/tests/Foundation/Bootstrap/LoadConfigurationTest.php index f8d3f387c1d2..bc5e89f54bf3 100644 --- a/tests/Foundation/Bootstrap/LoadConfigurationTest.php +++ b/tests/Foundation/Bootstrap/LoadConfigurationTest.php @@ -2,6 +2,7 @@ namespace Illuminate\Tests\Foundation\Bootstrap; +use Illuminate\Filesystem\Filesystem; use Illuminate\Foundation\Application; use Illuminate\Foundation\Bootstrap\LoadConfiguration; use PHPUnit\Framework\TestCase; @@ -12,7 +13,7 @@ public function testLoadsBaseConfiguration() { $app = new Application(); - (new LoadConfiguration())->bootstrap($app); + (new LoadConfiguration)->bootstrap($app); $this->assertSame('Laravel', $app['config']['app.name']); } @@ -22,7 +23,7 @@ public function testDontLoadBaseConfiguration() $app = new Application(); $app->dontMergeFrameworkConfiguration(); - (new LoadConfiguration())->bootstrap($app); + (new LoadConfiguration)->bootstrap($app); $this->assertNull($app['config']['app.name']); } @@ -32,9 +33,28 @@ public function testLoadsConfigurationInIsolation() $app = new Application(__DIR__.'/../fixtures'); $app->useConfigPath(__DIR__.'/../fixtures/config'); - (new LoadConfiguration())->bootstrap($app); + (new LoadConfiguration)->bootstrap($app); $this->assertNull($app['config']['bar.foo']); $this->assertSame('bar', $app['config']['custom.foo']); } + + public function testConfigurationArrayKeysMatchLoadedFilenames() + { + $baseConfigPath = __DIR__.'/../../../config'; + $customConfigPath = __DIR__.'/../fixtures/config'; + + $app = new Application(); + $app->useConfigPath($customConfigPath); + + (new LoadConfiguration)->bootstrap($app); + + $this->assertEqualsCanonicalizing( + array_keys($app['config']->all()), + collect((new Filesystem)->files([ + $baseConfigPath, + $customConfigPath, + ]))->map(fn ($file) => $file->getBaseName('.php'))->unique()->values()->toArray() + ); + } }