Skip to content

Commit

Permalink
Add ability to set custom config merge plan file path, config and ven…
Browse files Browse the repository at this point in the history
…dor directories (#69)
  • Loading branch information
vjik committed Mar 10, 2024
1 parent b915496 commit 0ea74dd
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
- Enh #58: Support stream output headers (@xepozz)
- Enh #64: Don't use buffered output in `SapiEmitter` when body size is less than buffer (@Gerych1984, @vjik)
- Enh #65: Add support for `psr/http-message` version `^2.0` (@vjik)
- New #69: Add ability to set custom config merge plan file path, config and vendor directories (@vjik)

## 2.2.0 December 25, 2023

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -40,7 +40,7 @@
"yiisoft/log": "^2.0",
"yiisoft/log-target-file": "^3.0",
"yiisoft/yii-http": "^1.0",
"yiisoft/yii-runner": "^2.1"
"yiisoft/yii-runner": "^2.2"
},
"require-dev": {
"httpsoft/http-message": "^1.0",
Expand Down
9 changes: 9 additions & 0 deletions src/HttpApplicationRunner.php
Expand Up @@ -51,6 +51,9 @@ final class HttpApplicationRunner extends ApplicationRunner
* @param array $nestedEventsGroups Configuration group names that are included into events' configuration group.
* This is needed for reverse and recursive merge of events' configurations.
* @param object[] $configModifiers Modifiers for {@see Config}.
* @param string $configDirectory The relative path from {@see $rootPath} to the configuration storage location.
* @param string $vendorDirectory The relative path from {@see $rootPath} to the vendor directory.
* @param string $configMergePlanFile The relative path from {@see $configDirectory} to merge plan.
*
* @psalm-param list<string> $nestedParamsGroups
* @psalm-param list<string> $nestedEventsGroups
Expand All @@ -71,6 +74,9 @@ public function __construct(
array $nestedParamsGroups = ['params'],

Check warning on line 74 in src/HttpApplicationRunner.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ * @psalm-param list<string> $nestedEventsGroups * @psalm-param list<object> $configModifiers */ - public function __construct(string $rootPath, bool $debug = false, bool $checkEvents = false, ?string $environment = null, string $bootstrapGroup = 'bootstrap-web', string $eventsGroup = 'events-web', string $diGroup = 'di-web', string $diProvidersGroup = 'di-providers-web', string $diDelegatesGroup = 'di-delegates-web', string $diTagsGroup = 'di-tags-web', string $paramsGroup = 'params-web', array $nestedParamsGroups = ['params'], array $nestedEventsGroups = ['events'], array $configModifiers = [], string $configDirectory = 'config', string $vendorDirectory = 'vendor', string $configMergePlanFile = '.merge-plan.php') + public function __construct(string $rootPath, bool $debug = false, bool $checkEvents = false, ?string $environment = null, string $bootstrapGroup = 'bootstrap-web', string $eventsGroup = 'events-web', string $diGroup = 'di-web', string $diProvidersGroup = 'di-providers-web', string $diDelegatesGroup = 'di-delegates-web', string $diTagsGroup = 'di-tags-web', string $paramsGroup = 'params-web', array $nestedParamsGroups = [], array $nestedEventsGroups = ['events'], array $configModifiers = [], string $configDirectory = 'config', string $vendorDirectory = 'vendor', string $configMergePlanFile = '.merge-plan.php') { parent::__construct($rootPath, $debug, $checkEvents, $environment, $bootstrapGroup, $eventsGroup, $diGroup, $diProvidersGroup, $diDelegatesGroup, $diTagsGroup, $paramsGroup, $nestedParamsGroups, $nestedEventsGroups, $configModifiers, $configDirectory, $vendorDirectory, $configMergePlanFile); }
array $nestedEventsGroups = ['events'],

Check warning on line 75 in src/HttpApplicationRunner.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ * @psalm-param list<string> $nestedEventsGroups * @psalm-param list<object> $configModifiers */ - public function __construct(string $rootPath, bool $debug = false, bool $checkEvents = false, ?string $environment = null, string $bootstrapGroup = 'bootstrap-web', string $eventsGroup = 'events-web', string $diGroup = 'di-web', string $diProvidersGroup = 'di-providers-web', string $diDelegatesGroup = 'di-delegates-web', string $diTagsGroup = 'di-tags-web', string $paramsGroup = 'params-web', array $nestedParamsGroups = ['params'], array $nestedEventsGroups = ['events'], array $configModifiers = [], string $configDirectory = 'config', string $vendorDirectory = 'vendor', string $configMergePlanFile = '.merge-plan.php') + public function __construct(string $rootPath, bool $debug = false, bool $checkEvents = false, ?string $environment = null, string $bootstrapGroup = 'bootstrap-web', string $eventsGroup = 'events-web', string $diGroup = 'di-web', string $diProvidersGroup = 'di-providers-web', string $diDelegatesGroup = 'di-delegates-web', string $diTagsGroup = 'di-tags-web', string $paramsGroup = 'params-web', array $nestedParamsGroups = ['params'], array $nestedEventsGroups = [], array $configModifiers = [], string $configDirectory = 'config', string $vendorDirectory = 'vendor', string $configMergePlanFile = '.merge-plan.php') { parent::__construct($rootPath, $debug, $checkEvents, $environment, $bootstrapGroup, $eventsGroup, $diGroup, $diProvidersGroup, $diDelegatesGroup, $diTagsGroup, $paramsGroup, $nestedParamsGroups, $nestedEventsGroups, $configModifiers, $configDirectory, $vendorDirectory, $configMergePlanFile); }
array $configModifiers = [],
string $configDirectory = 'config',
string $vendorDirectory = 'vendor',
string $configMergePlanFile = '.merge-plan.php',
) {
parent::__construct(
$rootPath,
Expand All @@ -87,6 +93,9 @@ public function __construct(
$nestedParamsGroups,
$nestedEventsGroups,
$configModifiers,
$configDirectory,
$vendorDirectory,
$configMergePlanFile,
);
}

Expand Down
24 changes: 24 additions & 0 deletions tests/HttpApplicationRunnerTest.php
Expand Up @@ -118,6 +118,30 @@ public function testRunWithFailureDuringProcess(): void
$runner->run();
}

public function testConfigMergePlanFile(): void
{
$runner = new HttpApplicationRunner(
rootPath: __DIR__ . '/Support',
configMergePlanFile: 'test-merge-plan.php',
);

$params = $runner->getConfig()->get('params-web');

$this->assertSame(['a' => 42,], $params);
}

public function testConfigDirectory(): void
{
$runner = new HttpApplicationRunner(
rootPath: __DIR__ . '/Support',
configDirectory: 'custom-config',
);

$params = $runner->getConfig()->get('params-web');

$this->assertSame(['age' => 22], $params);
}

public function testImmutability(): void
{
$this->assertNotSame($this->runner, $this->runner->withConfig($this->createConfig()));
Expand Down
14 changes: 14 additions & 0 deletions tests/Support/config/test-merge-plan.php
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

// Do not edit. Content will be replaced.
return [
'/' => [
'params-web' => [
'/' => [
'test-params.php',
],
],
],
];
7 changes: 7 additions & 0 deletions tests/Support/config/test-params.php
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

return [
'a' => 42,
];
14 changes: 14 additions & 0 deletions tests/Support/custom-config/.merge-plan.php
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

// Do not edit. Content will be replaced.
return [
'/' => [
'params-web' => [
'/' => [
'params.php',
],
],
],
];
7 changes: 7 additions & 0 deletions tests/Support/custom-config/params.php
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

return [
'age' => 22,
];

0 comments on commit 0ea74dd

Please sign in to comment.