Skip to content

Commit

Permalink
Fix #45: Add ability to set custom config modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 22, 2023
1 parent 268f7b8 commit fd7929b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
@@ -1,8 +1,8 @@
# Yii Runner Change Log

## 2.0.1 under development
## 2.1.0 under development

- no changes in this release.
- New #45: Add ability to set custom config modifiers (@vjik)

## 2.0.0 February 19, 2023

Expand Down
4 changes: 4 additions & 0 deletions src/ApplicationRunner.php
Expand Up @@ -43,9 +43,11 @@ abstract class ApplicationRunner implements RunnerInterface
* This is needed for recursive merging of parameters.
* @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}.
*
* @psalm-param list<string> $nestedParamsGroups
* @psalm-param list<string> $nestedEventsGroups
* @psalm-param list<object> $configModifiers
*/
public function __construct(
protected string $rootPath,
Expand All @@ -61,6 +63,7 @@ public function __construct(
protected string $paramsGroup,
protected array $nestedParamsGroups,
protected array $nestedEventsGroups,
protected array $configModifiers = [],
) {
}

Expand Down Expand Up @@ -161,6 +164,7 @@ private function createDefaultConfig(): Config
[
ReverseMerge::groups(...$eventsGroups),
RecursiveMerge::groups(...$paramsGroups, ...$eventsGroups),
...$this->configModifiers,
],
$this->paramsGroup,
);
Expand Down
22 changes: 22 additions & 0 deletions tests/ApplicationRunnerTest.php
Expand Up @@ -169,6 +169,28 @@ public function testEvents(): void
);
}

public function testConfigModifiers(): void
{
$runner = new ApplicationRunner(
configModifiers: [
RecursiveMerge::groups('custom'),
],
);

$config = $runner->getRunnerConfig();

$this->assertSame(
[
'a' => [
'b' => 7,
'c' => 8,
'd' => 9,
],
],
$config->get('custom')
);
}

public function testImmutability(): void
{
$runner = new ApplicationRunner();
Expand Down
2 changes: 2 additions & 0 deletions tests/Support/ApplicationRunner/ApplicationRunner.php
Expand Up @@ -13,6 +13,7 @@ public function __construct(
bool $checkEvents = true,
string $eventsGroup = 'events-web',
?string $bootstrapGroup = 'bootstrap-web',
array $configModifiers = [],
) {
parent::__construct(
rootPath: __DIR__,
Expand All @@ -28,6 +29,7 @@ public function __construct(
paramsGroup: 'params',
nestedParamsGroups: [],
nestedEventsGroups: ['events', 'events-more'],
configModifiers: $configModifiers,
);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Support/ApplicationRunner/config/.merge-plan.php
Expand Up @@ -11,6 +11,12 @@
'params-more.php',
],
],
'custom' => [
'/' => [
'custom.php',
'custom2.php',
],
],
'di-web' => [
'/' => [
'di-web.php',
Expand Down
10 changes: 10 additions & 0 deletions tests/Support/ApplicationRunner/config/custom.php
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

return [
'a' => [
'b' => 7,
'c' => 8,
],
];
9 changes: 9 additions & 0 deletions tests/Support/ApplicationRunner/config/custom2.php
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

return [
'a' => [
'd' => 9,
],
];

0 comments on commit fd7929b

Please sign in to comment.