Skip to content

Commit

Permalink
Fixing another bug where bundles changing environments wouldn't update
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Apr 10, 2022
1 parent 7d6a16d commit 408764b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/Configurator/BundlesConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ public function unconfigure(Recipe $recipe, $bundles, Lock $lock)

public function update(RecipeUpdate $recipeUpdate, array $originalConfig, array $newConfig): void
{
$originalBundles = $this->configureBundles($originalConfig);
$originalBundles = $this->configureBundles($originalConfig, true);
$recipeUpdate->setOriginalFile(
$this->getLocalConfFile(),
$this->buildContents($originalBundles)
);

$newBundles = $this->configureBundles($newConfig);
$newBundles = $this->configureBundles($newConfig, true);
$recipeUpdate->setNewFile(
$this->getLocalConfFile(),
$this->buildContents($newBundles)
);
}

private function configureBundles(array $bundles): array
private function configureBundles(array $bundles, bool $resetEnvironments = false): array
{
$file = $this->getConfFile();
$registered = $this->load($file);
Expand All @@ -70,7 +70,15 @@ private function configureBundles(array $bundles): array
}
foreach ($classes as $class => $envs) {
// do not override existing configured envs for a bundle
if (!isset($registered[$class])) {
if (!isset($registered[$class]) || $resetEnvironments) {
if ($resetEnvironments) {
// used during calculating an "upgrade"
// here, we want to "undo" the bundle's configuration entirely
// then re-add it fresh, in case some environments have been
// removed in an updated version of the recipe
$registered[$class] = [];
}

foreach ($envs as $env) {
$registered[$class][$env] = true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Configurator/BundlesConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testUpdate()
return [
BarBundle::class => ['prod' => false, 'all' => true],
FooBundle::class => ['dev' => true, 'test' => true],
FooBundle::class => ['all' => true],
BazBundle::class => ['all' => true],
NewBundle::class => ['all' => true],
];
Expand Down

0 comments on commit 408764b

Please sign in to comment.