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 (#50)
  • Loading branch information
vjik authored Mar 10, 2024
1 parent 587fe6c commit 154d0d9
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.1.2 under development

- no changes in this release.
- New #50: Add ability to set custom config merge plan file path, config and vendor directories (@vjik)

## 2.1.1 December 26, 2023

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"yiisoft/definitions": "^1.0|^2.0|^3.0",
"yiisoft/di": "^1.0",
"yiisoft/yii-console": "^2.0",
"yiisoft/yii-runner": "^2.1"
"yiisoft/yii-runner": "^2.2"
},
"require-dev": {
"codeception/codeception": "^5.0",
Expand Down
9 changes: 9 additions & 0 deletions src/ConsoleApplicationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ final class ConsoleApplicationRunner 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 @@ -61,6 +64,9 @@ public function __construct(
array $nestedParamsGroups = ['params'],
array $nestedEventsGroups = ['events'],
array $configModifiers = [],
string $configDirectory = 'config',
string $vendorDirectory = 'vendor',
string $configMergePlanFile = '.merge-plan.php',
) {
parent::__construct(
$rootPath,
Expand All @@ -77,6 +83,9 @@ public function __construct(
$nestedParamsGroups,
$nestedEventsGroups,
$configModifiers,
$configDirectory,
$vendorDirectory,
$configMergePlanFile,
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/Unit.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
actor: UnitTester
35 changes: 35 additions & 0 deletions tests/Unit/ConsoleApplicationRunnerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Runner\Console\Tests\Unit;

use Codeception\PHPUnit\TestCase;
use Yiisoft\Yii\Runner\Console\ConsoleApplicationRunner;

final class ConsoleApplicationRunnerTest extends TestCase
{
public function testConfigMergePlanFile(): void
{
$runner = new ConsoleApplicationRunner(
rootPath: __DIR__ . '/Support/custom-merge-plan',
configMergePlanFile: 'test-merge-plan.php',
);

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

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

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

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

$this->assertSame(['age' => 22], $params);
}
}
14 changes: 14 additions & 0 deletions tests/Unit/Support/custom-config/.merge-plan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

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

declare(strict_types=1);

return [
'age' => 22,
];
14 changes: 14 additions & 0 deletions tests/Unit/Support/custom-merge-plan/config/test-merge-plan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

// Do not edit. Content will be replaced.
return [
'/' => [
'params-console' => [
'/' => [
'test-params.php',
],
],
],
];
7 changes: 7 additions & 0 deletions tests/Unit/Support/custom-merge-plan/config/test-params.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

return [
'a' => 42,
];
29 changes: 29 additions & 0 deletions tests/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Runner\Console\Tests;

/**
* Inherited Methods
* @method void wantTo($text)
* @method void wantToTest($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause($vars = [])
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;

/**
* Define custom actions here
*/
}

0 comments on commit 154d0d9

Please sign in to comment.