Skip to content

Commit

Permalink
[11.x] Fixes config:publish with `dontMergeFrameworkConfiguration()…
Browse files Browse the repository at this point in the history
…` set to `true` (#51751)

* [11.x] Fixes `config:publish` with `dontMergeFrameworkConfiguration()`
set to `true`

fixes #51736

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Apply fixes from StyleCI

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Apply fixes from StyleCI

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Update ConfigPublishCommandTest.php

* Apply fixes from StyleCI

* Update composer.json

* Update composer.json

* Update ConfigPublishCommandTest.php

* Update composer.json

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
crynobone and StyleCIBot authored Jun 10, 2024
1 parent c632b1f commit fecf031
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"league/flysystem-sftp-v3": "^3.0",
"mockery/mockery": "^1.6",
"nyholm/psr7": "^1.2",
"orchestra/testbench-core": "^9.1.4",
"orchestra/testbench-core": "^9.1.5",
"pda/pheanstalk": "^5.0",
"phpstan/phpstan": "^1.4.7",
"phpunit/phpunit": "^10.5|^11.0",
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/Bootstrap/RegisterProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Foundation\Bootstrap;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;

class RegisterProviders
{
Expand Down Expand Up @@ -57,7 +58,7 @@ protected function mergeAdditionalProviders(Application $app)
$app->make('config')->set(
'app.providers',
array_merge(
$app->make('config')->get('app.providers'),
$app->make('config')->get('app.providers') ?? ServiceProvider::defaultProviders()->toArray(),
static::$merge,
array_values($packageProviders ?? []),
),
Expand Down
6 changes: 5 additions & 1 deletion src/Illuminate/Foundation/Console/ConfigPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ protected function getBaseConfigurationFiles()
{
$config = [];

$shouldMergeConfiguration = $this->laravel->shouldMergeFrameworkConfiguration();

foreach (Finder::create()->files()->name('*.php')->in(__DIR__.'/../../../../config') as $file) {
$name = basename($file->getRealPath(), '.php');

$config[$name] = file_exists($stubPath = (__DIR__.'/../../../../config-stubs/'.$name.'.php')) ? $stubPath : $file->getRealPath();
$config[$name] = ($shouldMergeConfiguration === true && file_exists($stubPath = (__DIR__.'/../../../../config-stubs/'.$name.'.php')))
? $stubPath
: $file->getRealPath();
}

return collect($config)->sortKeys()->all();
Expand Down
66 changes: 66 additions & 0 deletions tests/Integration/Foundation/Console/ConfigPublishCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Illuminate\Tests\Integration\Foundation\Console;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Bootstrap\LoadConfiguration;
use Illuminate\Support\ServiceProvider;
use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles;
use Orchestra\Testbench\TestCase;

use function Orchestra\Testbench\package_path;

class ConfigPublishCommandTest extends TestCase
{
use InteractsWithPublishedFiles;

protected array $files = [
'config-stubs/*.php',
];

#[\Override]
protected function setUp(): void
{
$files = new Filesystem();

$this->afterApplicationCreated(function () use ($files) {
$files->ensureDirectoryExists($this->app->basePath('config-stubs'));
});

$this->beforeApplicationDestroyed(function () use ($files) {
$files->deleteDirectory($this->app->basePath('config-stubs'));
});

parent::setUp();
}

#[\Override]
protected function resolveApplicationConfiguration($app)
{
$app->instance(LoadConfiguration::class, new LoadConfiguration());

$app->useConfigPath($app->basePath('config-stubs'));

$app->dontMergeFrameworkConfiguration();

parent::resolveApplicationConfiguration($app);
}

public function testItCanPublishConfigFilesWhenConfiguredWithDontMergeFrameworkConfiguration()
{
$this->artisan('config:publish', ['--all' => true])->assertOk();

foreach ([
'app', 'auth', 'broadcasting', 'cache', 'cors',
'database', 'filesystems', 'hashing', 'logging',
'mail', 'queue', 'services', 'session', 'view',
] as $file) {
$this->assertFilenameExists("config-stubs/{$file}.php");
$this->assertStringContainsString(
file_get_contents(package_path(['config', "{$file}.php"])), file_get_contents(config_path("{$file}.php"))
);
}

$this->assertSame(config('app.providers'), ServiceProvider::defaultProviders()->toArray());
}
}

0 comments on commit fecf031

Please sign in to comment.