Skip to content

[12.x] Correct how base options for missing config files are preloaded #56198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 (Collection::make($base)->diffKeys($files) as $name => $config) {
$repository->set($name, $config);
}

Expand Down
26 changes: 23 additions & 3 deletions tests/Foundation/Bootstrap/LoadConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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']);
}
Expand All @@ -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']);
}
Expand All @@ -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()
);
}
}