Skip to content

Commit

Permalink
bug #482 Fix bundles.php generation when false value is used (fferriere)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.2-dev branch.

Discussion
----------

Fix bundles.php generation when false value is used

Fix when we set an environment to `false` in bundle.php it set at `true` on generation.

Commits
-------

b2b78e6 Fix bundles.php generation when false value is used
  • Loading branch information
nicolas-grekas committed Apr 3, 2019
2 parents b70f9c8 + b2b78e6 commit 305a6cd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Configurator/BundlesConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ private function dump(string $file, array $bundles)
$contents = "<?php\n\nreturn [\n";
foreach ($bundles as $class => $envs) {
$contents .= " $class::class => [";
foreach (array_keys($envs) as $env) {
$contents .= "'$env' => true, ";
foreach ($envs as $env => $value) {
$booleanValue = var_export($value, true);
$contents .= "'$env' => $booleanValue, ";
}
$contents = substr($contents, 0, -2)."],\n";
}
Expand Down
38 changes: 38 additions & 0 deletions tests/Configurator/BundlesConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,44 @@ public function testConfigure()
FooBundle::class => ['dev' => true, 'test' => true],
];
EOF
, file_get_contents($config));
}

public function testConfigureWhenBundlesAlreayExists()
{
$config = FLEX_TEST_DIR.'/config/bundles.php';
file_put_contents($config, <<<EOF
<?php
return [
BarBundle::class => ['prod' => false, 'all' => true],
];
EOF
);

$configurator = new BundlesConfigurator(
$this->getMockBuilder('Composer\Composer')->getMock(),
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
new Options(['config-dir' => 'config', 'root-dir' => FLEX_TEST_DIR])
);

$recipe = $this->getMockBuilder(Recipe::class)->disableOriginalConstructor()->getMock();
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();

$configurator->configure($recipe, [
'FooBundle' => ['dev', 'test'],
'Symfony\Bundle\FrameworkBundle\FrameworkBundle' => ['all'],
], $lock);
$this->assertEquals(<<<EOF
<?php
return [
BarBundle::class => ['prod' => false, 'all' => true],
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
FooBundle::class => ['dev' => true, 'test' => true],
];
EOF
, file_get_contents($config));
}
Expand Down

0 comments on commit 305a6cd

Please sign in to comment.