Skip to content

Commit 7bfeaef

Browse files
committed
Add SYMFONY_ALLOW_CONTRIB variable
1 parent 81e14fb commit 7bfeaef

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/Flex.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ public function install(Event $event)
386386
}
387387

388388
$this->io->writeError(\sprintf('<info>Symfony operations: %d recipe%s (%s)</>', \count($recipes), \count($recipes) > 1 ? 's' : '', $this->downloader->getSessionId()));
389-
$installContribs = $this->composer->getPackage()->getExtra()['symfony']['allow-contrib'] ?? false;
389+
if (false === $installContribs = getenv('SYMFONY_ALLOW_CONTRIB')) {
390+
$installContribs = $this->composer->getPackage()->getExtra()['symfony']['allow-contrib'] ?? false;
391+
}
392+
if (! is_bool($installContribs)) {
393+
$installContribs = filter_var($installContribs, FILTER_VALIDATE_BOOL);
394+
}
390395
$manifest = null;
391396
$originalComposerJsonHash = $this->getComposerJsonHash();
392397
$postInstallRecipes = [];

tests/FlexTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)