Skip to content

Commit 7c7a216

Browse files
committed
Don't list contrib packages in symfony.lock when not applied
1 parent f356aa3 commit 7c7a216

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/Flex.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ function ($value) {
420420
'n'
421421
);
422422
if ('n' === $answer) {
423+
// Remove the recipe from the lock to allow re-asking next time
424+
$this->lock->remove($recipe->getName());
423425
continue;
424426
}
425427
if ('a' === $answer) {

tests/FlexTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444

4545
class FlexTest extends TestCase
4646
{
47+
public function tearDown(): void
48+
{
49+
@unlink(__DIR__.'/Fixtures/symfony.lock');
50+
}
51+
4752
public function testPostInstall()
4853
{
4954
$data = [
@@ -124,6 +129,56 @@ public function testActivateLoadsClasses()
124129
$this->assertTrue(class_exists(Response::class, false));
125130
}
126131

132+
public function testContribRecipeNotApprovedIsRemovedFromLock()
133+
{
134+
$data = [
135+
'manifests' => [
136+
'contrib/package' => [
137+
'manifest' => [
138+
'bundles' => [
139+
'Contrib\\Package\\ContribBundle' => ['all'],
140+
],
141+
],
142+
'origin' => 'contrib/package:1.0@github.com/symfony/recipes-contrib:main',
143+
'is_contrib' => true,
144+
],
145+
],
146+
'locks' => [
147+
'contrib/package' => [
148+
'recipe' => [
149+
'repo' => 'github.com/symfony/recipes-contrib',
150+
'version' => '1.0',
151+
],
152+
'version' => '1.0.0',
153+
],
154+
],
155+
];
156+
157+
// Non-interactive mode with allow-contrib disabled (BufferIO is non-interactive by default)
158+
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
159+
160+
$package = new Package('contrib/package', '1.0.0', '1.0.0');
161+
$rootPackage = $this->mockRootPackage([]); // no allow-contrib
162+
163+
$downloader = $this->mockDownloader($data);
164+
$configurator = $this->getMockBuilder(Configurator::class)->disableOriginalConstructor()->getMock();
165+
// Recipe should NOT be installed
166+
$configurator->expects($this->never())->method('install');
167+
168+
$lock = new Lock(__DIR__.'/Fixtures/symfony.lock');
169+
$composer = $this->mockComposer($this->mockLocker(), $rootPackage);
170+
$flex = $this->mockFlexCustom($io, $composer, $configurator, $downloader, $lock);
171+
172+
$flex->record($this->mockPackageEvent($package));
173+
$flex->install($this->mockFlexEvent());
174+
$this->assertFalse($lock->has('contrib/package'), 'Recipe lock entry has been removed');
175+
176+
// Verify the warning message was displayed
177+
$output = $io->getOutput();
178+
$this->assertStringContainsString('IGNORING', $output);
179+
$this->assertStringContainsString('contrib/package', $output);
180+
}
181+
127182
/**
128183
* @dataProvider getPackagesForAutoDiscovery
129184
*/

0 commit comments

Comments
 (0)