Files
timebank-cc-public/tests/Feature/PlatformConfigMergeTest.php
T

60 lines
2.6 KiB
PHP

<?php
namespace Tests\Feature;
use Illuminate\Support\Facades\File;
use Tests\TestCase;
/**
* When the platform folder has a config.php, that is the platform config, so config:merge merges new keys into
* it: from config/<TIMEBANK_CONFIG>.php.example when that exists, else from the default template.
*/
class PlatformConfigMergeTest extends TestCase
{
private string $root;
protected function setUp(): void
{
parent::setUp();
$this->root = sys_get_temp_dir() . '/platform-config-merge-' . uniqid();
File::makeDirectory($this->root);
config(['app.platform_path' => $this->root]);
File::put("{$this->root}/config.php", "<?php\n\nreturn [\n 'own_setting' => 'kept',\n];\n");
}
protected function tearDown(): void
{
File::deleteDirectory($this->root);
File::delete(File::glob(storage_path('config-backups/platform-config.php.backup.*')));
parent::tearDown();
}
public function test_a_platform_name_without_its_own_template_merges_from_the_default_template(): void
{
config(['app.timebank_config' => 'config-merge-test-platform']);
$this->artisan('config:merge', ['file' => 'config-merge-test-platform', '--force' => true])->assertExitCode(0);
$merged = include "{$this->root}/config.php";
$this->assertSame('kept', $merged['own_setting']);
$this->assertArrayHasKey('account_info', $merged);
$this->assertFalse(File::exists(base_path('config/config-merge-test-platform.php')), 'nothing is written to config/');
$this->assertCount(1, File::glob(storage_path('config-backups/platform-config.php.backup.*')), 'the backup is named after the platform folder');
}
public function test_a_platform_with_its_own_template_merges_from_that_one(): void
{
config(['app.timebank_config' => 'timebank_cc']);
$own = (include base_path('config/timebank_cc.php.example'))['mail']['system_admin']['email'];
$default = (include base_path('config/timebank-default.php.example'))['mail']['system_admin']['email'];
$this->assertNotSame($own, $default, 'the two templates must differ here for this test to mean something');
$this->artisan('config:merge', ['file' => 'timebank_cc', '--dry-run' => true])->assertExitCode(0);
$this->assertSame("<?php\n\nreturn [\n 'own_setting' => 'kept',\n];\n", File::get("{$this->root}/config.php"), 'a dry run changes nothing');
$this->artisan('config:merge', ['file' => 'timebank_cc', '--force' => true])->assertExitCode(0);
$this->assertSame($own, (include "{$this->root}/config.php")['mail']['system_admin']['email']);
}
}