Skip to content

Commit

Permalink
Empty configuration groups from packages were not added to merge plan
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 16, 2023
1 parent f509e98 commit b622336
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.3.1 under development

- Bug #145: Use composer library and plugins only, instead of any packages before (@vjik)
- Bug #150: Empty configuration groups from packages were not added to merge plan (@vjik)

## 1.3.0 February 11, 2023

Expand Down
4 changes: 2 additions & 2 deletions src/Composer/MergePlanProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ private function addPackagesConfigsToMergePlan(bool $isVendorOverrideLayer): voi
$packageName = $isVendorOverrideLayer ? Options::VENDOR_OVERRIDE_PACKAGE_NAME : $name;

foreach ($this->helper->getPackageConfig($package) as $group => $files) {
$files = (array) $files;
$this->mergePlan->addGroup($group);

foreach ($files as $file) {
foreach ((array) $files as $file) {
$isOptional = false;

if (Options::isOptional($file)) {
Expand Down
13 changes: 13 additions & 0 deletions src/MergePlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public function addEnvironmentWithoutConfigs(string $environment): void
$this->mergePlan[$environment] = [];
}

/**
* Add empty group if it not exists.
*
* @param string $group The group name.
* @param string $environment The environment name.
*/
public function addGroup(string $group, string $environment = Options::DEFAULT_ENVIRONMENT): void
{
if (!isset($this->mergePlan[$environment][$group])) {
$this->mergePlan[$environment][$group] = [];
}
}

/**
* Returns the merge plan group.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/Composer/PackagesListBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ public function testBuild(): void
{
$packages = (new PackagesListBuilder($this->createComposerMock()))->build();

$this->assertCount(6, $packages);
$this->assertCount(7, $packages);
$this->assertSame('test/a', $packages['test/a']->getPrettyName());
$this->assertSame('test/ba', $packages['test/ba']->getPrettyName());
$this->assertSame('test/c', $packages['test/c']->getPrettyName());
$this->assertSame('test/custom-source', $packages['test/custom-source']->getPrettyName());
$this->assertSame('test/over', $packages['test/over']->getPrettyName());
$this->assertSame('test/d-dev-c', $packages['test/d-dev-c']->getPrettyName());
$this->assertSame('test/empty-group', $packages['test/empty-group']->getPrettyName());
}
}
7 changes: 7 additions & 0 deletions tests/Composer/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ protected function assertMergePlan(array $environments = []): void
'custom-dir/events-web.php',
],
],
'widgets' => [],
'empty' => [
Options::ROOT_PACKAGE_NAME => [],
],
Expand Down Expand Up @@ -230,6 +231,11 @@ protected function createComposerMock(
'test/custom-source' => new Link("$sourcePath/custom-source", "$targetPath/test/custom-source", new Constraint('>=', '1.0.0')),
'test/over' => new Link("$sourcePath/over", "$targetPath/test/over", new Constraint('>=', '1.0.0')),
'test/metapack' => new Link("$sourcePath/metapack", "$targetPath/test/metapack", new Constraint('>=', '1.0.0')),
'test/empty-group' => new Link(
"$sourcePath/empty-group",
"$targetPath/test/empty-group",
new Constraint('>=', '1.0.0')
),
]);
$rootPackage
->method('getDevRequires')
Expand All @@ -251,6 +257,7 @@ protected function createComposerMock(
new CompletePackage('test/over', '1.0.0', '1.0.0'),
new Package('test/e', '1.0.0', '1.0.0'),
$metapackage,
new CompletePackage('test/empty-group', '1.0.0', '1.0.0'),
];

foreach ($packages as $package) {
Expand Down
9 changes: 9 additions & 0 deletions tests/TestAsset/packages/empty-group/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "test/empty-group",
"version": "1.0.0",
"extra": {
"config-plugin": {
"widgets": []
}
}
}

0 comments on commit b622336

Please sign in to comment.