Skip to content
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

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

Merged
merged 20 commits into from
Jun 10, 2024
Merged
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
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(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed scenario where app.php configuration file is not available. Verified with tests below.

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());
}
}