Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,12 @@ public function install(Event $event)
}

$this->io->writeError(\sprintf('<info>Symfony operations: %d recipe%s (%s)</>', \count($recipes), \count($recipes) > 1 ? 's' : '', $this->downloader->getSessionId()));
$installContribs = $this->composer->getPackage()->getExtra()['symfony']['allow-contrib'] ?? false;
if (false === $installContribs = getenv('SYMFONY_ALLOW_CONTRIB')) {
$installContribs = $this->composer->getPackage()->getExtra()['symfony']['allow-contrib'] ?? false;
}
if (! is_bool($installContribs)) {
$installContribs = filter_var($installContribs, FILTER_VALIDATE_BOOL);
}
$manifest = null;
$originalComposerJsonHash = $this->getComposerJsonHash();
$postInstallRecipes = [];
Expand Down
63 changes: 59 additions & 4 deletions tests/FlexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testPostInstall()
$package = new Package('dummy/dummy', '1.0.0', '1.0.0');
$recipe = new Recipe($package, 'dummy/dummy', 'install', $data['manifests']['dummy/dummy'], $data['locks']['dummy/dummy']);

$rootPackage = $this->mockRootPackage(['symfony' => ['allow-contrib' => true]]);
$rootPackage = $this->mockRootPackage();
$flex = $this->mockFlex($io, $rootPackage, $recipe, $data);
$flex->record($this->mockPackageEvent($package));
$flex->install($this->mockFlexEvent());
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testActivateLoadsClasses()
{
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);

$package = $this->mockRootPackage(['symfony' => ['allow-contrib' => true]]);
$package = $this->mockRootPackage();
$package->method('getRequires')->willReturn([new Link('dummy', 'symfony/flex', class_exists(MatchAllConstraint::class) ? new MatchAllConstraint() : null)]);

$composer = $this->mockComposer($this->mockLocker(), $package, Factory::createConfig($io));
Expand Down Expand Up @@ -194,7 +194,7 @@ public function testFetchRecipesOrder()
];

$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
$rootPackage = $this->mockRootPackage(['symfony' => ['allow-contrib' => true]]);
$rootPackage = $this->mockRootPackage();

$flex = $this->mockFlex($io, $rootPackage, null, [
'manifests' => array_reduce($packages, static function (array $manifests, array $packageInfo) {
Expand Down Expand Up @@ -271,7 +271,7 @@ public function testFetchRecipesWithConflicts()
];

$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
$rootPackage = $this->mockRootPackage(['symfony' => ['allow-contrib' => true]]);
$rootPackage = $this->mockRootPackage();

$downloader = $this->getMockBuilder(Downloader::class)->disableOriginalConstructor()->getMock();
$downloader->expects($this->exactly(2))
Expand Down Expand Up @@ -313,6 +313,61 @@ class_exists(LockArrayRepository::class) ? LockArrayRepository::class : Reposito
$this->assertSame('2.3', $recipes['doctrine/doctrine-bundle']->getVersion());
}

public function testInstallWithSymfonyAllowContribEnvVar()
{
$data = [
'manifests' => [
'dummy/contrib-package' => [
'manifest' => [
'bundles' => [
'Dummy\\ContribBundle\\ContribBundle' => ['all'],
],
],
'origin' => 'dummy/contrib-package:1.0@github.com/symfony/recipes-contrib:main',
'is_contrib' => true,
],
],
'locks' => [
'dummy/contrib-package' => [
'recipe' => [],
'version' => '1.0',
],
],
];

$package = new Package('dummy/contrib-package', '1.0.0', '1.0.0');

// SYMFONY_ALLOW_CONTRIB=1 should install contrib recipes even without config
putenv('SYMFONY_ALLOW_CONTRIB=1');
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
$recipe = new Recipe($package, 'dummy/contrib-package', 'install', $data['manifests']['dummy/contrib-package'], $data['locks']['dummy/contrib-package']);
$rootPackage = $this->mockRootPackage(['symfony' => []]);
$flex = $this->mockFlex($io, $rootPackage, $recipe, $data);
$flex->record($this->mockPackageEvent($package));
$flex->install($this->mockFlexEvent());

$output = $io->getOutput();
$this->assertStringContainsString('Configuring dummy/contrib-package', $output);
$this->assertStringNotContainsString('IGNORING', $output);

// SYMFONY_ALLOW_CONTRIB=0 should skip contrib recipes even with config allow-contrib=true
putenv('SYMFONY_ALLOW_CONTRIB=0');
$io = new BufferIO('', OutputInterface::VERBOSITY_NORMAL);
$recipe = new Recipe($package, 'dummy/contrib-package', 'install', $data['manifests']['dummy/contrib-package'], $data['locks']['dummy/contrib-package']);
$rootPackage = $this->mockRootPackage(['symfony' => ['allow-contrib' => true]]);
// For this test, we expect the recipe NOT to be installed, so pass null as recipe to configurator
$flex = $this->mockFlex($io, $rootPackage, null, $data);
$flex->record($this->mockPackageEvent($package));
$flex->install($this->mockFlexEvent());

$output = $io->getOutput();
$this->assertStringContainsString('IGNORING', $output);
$this->assertStringNotContainsString('Configuring dummy/contrib-package', $output);

// Cleanup
putenv('SYMFONY_ALLOW_CONTRIB');
}

public function testInstallWithPackageJsonToSynchronizeSkipped()
{
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
Expand Down
Loading