Skip to content

Commit 4135a80

Browse files
u01jmg3calebdw
andauthored
[12.x] Merge 11.x into 12.x (#56289)
* [11.x] Correct how base options for missing config files are preloaded (#56216) * Formatting * Add breaking test to demo config array has been incorrectly keyed with numbers * Correct how base options for missing config files are preloaded * fix: AsCommand properties not being set on commands (#56236) The Symfony Command uses the AsCommand attribute to set properties on the command class. However, the properties are only set if they are identical to an empty string. The Laravel Command class overrides the properties and removes the default value which causes the properties to be null and therefore not set. --------- Co-authored-by: Caleb White <[email protected]>
1 parent 0d1887e commit 4135a80

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Config\Repository;
66
use Illuminate\Contracts\Config\Repository as RepositoryContract;
77
use Illuminate\Contracts\Foundation\Application;
8+
use Illuminate\Support\Collection;
89
use SplFileInfo;
910
use Symfony\Component\Finder\Finder;
1011

@@ -69,7 +70,7 @@ protected function loadConfigurationFiles(Application $app, RepositoryContract $
6970
? $this->getBaseConfiguration()
7071
: [];
7172

72-
foreach (array_diff(array_keys($base), array_keys($files)) as $name => $config) {
73+
foreach ((new Collection($base))->diffKeys($files) as $name => $config) {
7374
$repository->set($name, $config);
7475
}
7576

tests/Foundation/Bootstrap/LoadConfigurationTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Tests\Foundation\Bootstrap;
44

5+
use Illuminate\Filesystem\Filesystem;
56
use Illuminate\Foundation\Application;
67
use Illuminate\Foundation\Bootstrap\LoadConfiguration;
78
use PHPUnit\Framework\TestCase;
@@ -12,7 +13,7 @@ public function testLoadsBaseConfiguration()
1213
{
1314
$app = new Application();
1415

15-
(new LoadConfiguration())->bootstrap($app);
16+
(new LoadConfiguration)->bootstrap($app);
1617

1718
$this->assertSame('Laravel', $app['config']['app.name']);
1819
}
@@ -22,7 +23,7 @@ public function testDontLoadBaseConfiguration()
2223
$app = new Application();
2324
$app->dontMergeFrameworkConfiguration();
2425

25-
(new LoadConfiguration())->bootstrap($app);
26+
(new LoadConfiguration)->bootstrap($app);
2627

2728
$this->assertNull($app['config']['app.name']);
2829
}
@@ -32,9 +33,28 @@ public function testLoadsConfigurationInIsolation()
3233
$app = new Application(__DIR__.'/../fixtures');
3334
$app->useConfigPath(__DIR__.'/../fixtures/config');
3435

35-
(new LoadConfiguration())->bootstrap($app);
36+
(new LoadConfiguration)->bootstrap($app);
3637

3738
$this->assertNull($app['config']['bar.foo']);
3839
$this->assertSame('bar', $app['config']['custom.foo']);
3940
}
41+
42+
public function testConfigurationArrayKeysMatchLoadedFilenames()
43+
{
44+
$baseConfigPath = __DIR__.'/../../../config';
45+
$customConfigPath = __DIR__.'/../fixtures/config';
46+
47+
$app = new Application();
48+
$app->useConfigPath($customConfigPath);
49+
50+
(new LoadConfiguration)->bootstrap($app);
51+
52+
$this->assertEqualsCanonicalizing(
53+
array_keys($app['config']->all()),
54+
collect((new Filesystem)->files([
55+
$baseConfigPath,
56+
$customConfigPath,
57+
]))->map(fn ($file) => $file->getBaseName('.php'))->unique()->values()->toArray()
58+
);
59+
}
4060
}

0 commit comments

Comments
 (0)