@@ -313,6 +313,61 @@ class_exists(LockArrayRepository::class) ? LockArrayRepository::class : Reposito
313313 $ this ->assertSame ('2.3 ' , $ recipes ['doctrine/doctrine-bundle ' ]->getVersion ());
314314 }
315315
316+ public function testInstallWithSymfonyAllowContribEnvVar ()
317+ {
318+ $ data = [
319+ 'manifests ' => [
320+ 'dummy/contrib-package ' => [
321+ 'manifest ' => [
322+ 'bundles ' => [
323+ 'Dummy \\ContribBundle \\ContribBundle ' => ['all ' ],
324+ ],
325+ ],
326+ 'origin ' => 'dummy/contrib-package:1.0@github.com/symfony/recipes-contrib:main ' ,
327+ 'is_contrib ' => true ,
328+ ],
329+ ],
330+ 'locks ' => [
331+ 'dummy/contrib-package ' => [
332+ 'recipe ' => [],
333+ 'version ' => '1.0 ' ,
334+ ],
335+ ],
336+ ];
337+
338+ $ package = new Package ('dummy/contrib-package ' , '1.0.0 ' , '1.0.0 ' );
339+
340+ // SYMFONY_ALLOW_CONTRIB=1 should install contrib recipes even without config
341+ putenv ('SYMFONY_ALLOW_CONTRIB=1 ' );
342+ $ io = new BufferIO ('' , OutputInterface::VERBOSITY_VERBOSE );
343+ $ recipe = new Recipe ($ package , 'dummy/contrib-package ' , 'install ' , $ data ['manifests ' ]['dummy/contrib-package ' ], $ data ['locks ' ]['dummy/contrib-package ' ]);
344+ $ rootPackage = $ this ->mockRootPackage (['symfony ' => []]);
345+ $ flex = $ this ->mockFlex ($ io , $ rootPackage , $ recipe , $ data );
346+ $ flex ->record ($ this ->mockPackageEvent ($ package ));
347+ $ flex ->install ($ this ->mockFlexEvent ());
348+
349+ $ output = $ io ->getOutput ();
350+ $ this ->assertStringContainsString ('Configuring dummy/contrib-package ' , $ output );
351+ $ this ->assertStringNotContainsString ('IGNORING ' , $ output );
352+
353+ // SYMFONY_ALLOW_CONTRIB=0 should skip contrib recipes even with config allow-contrib=true
354+ putenv ('SYMFONY_ALLOW_CONTRIB=0 ' );
355+ $ io = new BufferIO ('' , OutputInterface::VERBOSITY_NORMAL );
356+ $ recipe = new Recipe ($ package , 'dummy/contrib-package ' , 'install ' , $ data ['manifests ' ]['dummy/contrib-package ' ], $ data ['locks ' ]['dummy/contrib-package ' ]);
357+ $ rootPackage = $ this ->mockRootPackage (['symfony ' => ['allow-contrib ' => true ]]);
358+ // For this test, we expect the recipe NOT to be installed, so pass null as recipe to configurator
359+ $ flex = $ this ->mockFlex ($ io , $ rootPackage , null , $ data );
360+ $ flex ->record ($ this ->mockPackageEvent ($ package ));
361+ $ flex ->install ($ this ->mockFlexEvent ());
362+
363+ $ output = $ io ->getOutput ();
364+ $ this ->assertStringContainsString ('IGNORING ' , $ output );
365+ $ this ->assertStringNotContainsString ('Configuring dummy/contrib-package ' , $ output );
366+
367+ // Cleanup
368+ putenv ('SYMFONY_ALLOW_CONTRIB ' );
369+ }
370+
316371 public function testInstallWithPackageJsonToSynchronizeSkipped ()
317372 {
318373 $ io = new BufferIO ('' , OutputInterface::VERBOSITY_VERBOSE );
0 commit comments