Repository: symfony/flex (php)

Issue:
Flex changing bundles.php environments
We have a special bundles.php. Since some changes now flex seems to overwrite our `bundles.php` configurations which ends up in a none working version of @sulu as example we requires fixtures bundle be enabled in all environments and has other envs configured:

<img width="721" alt="Bildschirmfoto 2022-03-03 um 14 10 54" src="https://user-images.githubusercontent.com/1698337/156571530-b05680c1-59db-43ec-9553-822f47a1be2c.png">

I'm not sure which change in flex did this change. But it seems flex is ignoring exist entries in the `bundles.php` and there configuration and just overwrites them now. Which was not the case in the past.

Pull request:
Fix problem of overwriting envs
Fixes problem of flex overwriting bundles.php envs.

Fixes #879 which currently breaks @sulu skeleton installation.

Patch:
diff --git a/src/Configurator/BundlesConfigurator.php b/src/Configurator/BundlesConfigurator.php
index 877f41b..a452989 100644
--- a/src/Configurator/BundlesConfigurator.php
+++ b/src/Configurator/BundlesConfigurator.php
@@ -69,12 +69,11 @@ class BundlesConfigurator extends AbstractConfigurator
             unset($classes[$fwb]);
         }
         foreach ($classes as $class => $envs) {
-            // if the class already existed, clear so we can update the envs
-            if (isset($registered[$class])) {
-                $registered[$class] = [];
-            }
-            foreach ($envs as $env) {
-                $registered[$class][$env] = true;
+            // do not override existing configured envs for a bundle
+            if (!isset($registered[$class])) {
+                foreach ($envs as $env) {
+                    $registered[$class][$env] = true;
+                }
             }
         }
 


Test patch:
diff --git a/tests/Configurator/BundlesConfiguratorTest.php b/tests/Configurator/BundlesConfiguratorTest.php
index b59fd64..84ffcd7 100644
--- a/tests/Configurator/BundlesConfiguratorTest.php
+++ b/tests/Configurator/BundlesConfiguratorTest.php
@@ -170,12 +170,13 @@ return [
 EOF
         ], $recipeUpdate->getOriginalFiles());
 
+        // FooBundle::class => ['dev' => true, 'test' => true]: configured envs should not be overwritten
         $this->assertSame(['config/bundles.php' => <<<EOF
 <?php
 
 return [
     BarBundle::class => ['prod' => false, 'all' => true],
-    FooBundle::class => ['all' => true],
+    FooBundle::class => ['dev' => true, 'test' => true],
     BazBundle::class => ['all' => true],
     NewBundle::class => ['all' => true],
 ];
diff --git a/tests/Configurator/DockerComposeConfiguratorTest.php b/tests/Configurator/DockerComposeConfiguratorTest.php
index 580f699..4539168 100644
--- a/tests/Configurator/DockerComposeConfiguratorTest.php
+++ b/tests/Configurator/DockerComposeConfiguratorTest.php
@@ -13,7 +13,7 @@ namespace Symfony\Flex\Tests\Configurator;
 
 use Composer\Composer;
 use Composer\IO\IOInterface;
-use Composer\Package\Package;
+use Composer\Package\RootPackage;
 use PHPUnit\Framework\TestCase;
 use Symfony\Component\Filesystem\Filesystem;
 use Symfony\Flex\Configurator\DockerComposeConfigurator;
@@ -114,7 +114,7 @@ YAML;
     /** @var DockerComposeConfigurator */
     private $configurator;
 
-    /** @var Package */
+    /** @var RootPackage */
     private $package;
 
     private $originalEnvComposer;
@@ -139,7 +139,7 @@ YAML;
         $this->lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
 
         // Configurator
-        $this->package = new Package('dummy/dummy', '1.0.0', '1.0.0');
+        $this->package = new RootPackage('dummy/dummy', '1.0.0', '1.0.0');
         $this->package->setExtra(['symfony' => ['docker' => true]]);
 
         $this->composer = $this->getMockBuilder(Composer::class)->getMock();
diff --git a/tests/Configurator/DockerfileConfiguratorTest.php b/tests/Configurator/DockerfileConfiguratorTest.php
index 2b1ae40..f9610c2 100644
--- a/tests/Configurator/DockerfileConfiguratorTest.php
+++ b/tests/Configurator/DockerfileConfiguratorTest.php
@@ -13,7 +13,7 @@ namespace Symfony\Flex\Configurator;
 
 use Composer\Composer;
 use Composer\IO\IOInterface;
-use Composer\Package\Package;
+use Composer\Package\RootPackage;
 use PHPUnit\Framework\TestCase;
 use Symfony\Flex\Lock;
 use Symfony\Flex\Options;
@@ -278,7 +278,7 @@ EOF
 
     private function createConfigurator(): DockerfileConfigurator
     {
-        $package = new Package('dummy/dummy', '1.0.0', '1.0.0');
+        $package = new RootPackage('dummy/dummy', '1.0.0', '1.0.0');
         $package->setExtra(['symfony' => ['docker' => true]]);
 
         $composer = $this->getMockBuilder(Composer::class)->getMock();
diff --git a/tests/FlexTest.php b/tests/FlexTest.php
index 9894771..26ef496 100644
--- a/tests/FlexTest.php
+++ b/tests/FlexTest.php
@@ -22,6 +22,7 @@ use Composer\Package\Locker;
 use Composer\Package\Package;
 use Composer\Package\RootPackageInterface;
 use Composer\Plugin\PluginInterface;
+use Composer\Repository\LockArrayRepository;
 use Composer\Repository\RepositoryInterface;
 use Composer\Repository\RepositoryManager;
 use Composer\Repository\WritableRepositoryInterface;
@@ -275,7 +276,10 @@ EOF
         $downloader->expects($this->once())->method('removeRecipeFromIndex')->with('doctrine/doctrine-bundle', '2.4');
 
         $locker = $this->getMockBuilder(Locker::class)->disableOriginalConstructor()->getMock();
-        $lockedRepository = $this->getMockBuilder(RepositoryInterface::class)->disableOriginalConstructor()->getMock();
+        $lockedRepository = $this->getMockBuilder(
+            // LockArrayRepository does not exist on composer 1.0.2 fallback to RepositoryInterface
+            class_exists(LockArrayRepository::class) ? LockArrayRepository::class : RepositoryInterface::class
+        )->disableOriginalConstructor()->getMock();
         // make the conflicted package show up
         $locker->expects($this->any())
             ->method('getLockedRepository')