@@ -101,10 +101,6 @@ public function testInstallingExtensionsForPhpProject(): void
101101 new Constraint ('>= ' , '1.2.0.0-dev ' ),
102102 new Constraint ('< ' , '2.0.0.0-dev ' ),
103103 ]), Link::TYPE_REQUIRE , '^1.2 ' ),
104- // 'ext-mismatching' => new Link('my/project', 'ext-mismatching', new MultiConstraint([
105- // new Constraint('>=', '2.0.0.0-dev'),
106- // new Constraint('<', '3.0.0.0-dev'),
107- // ]), Link::TYPE_REQUIRE, '^2.0'),
108104 ]);
109105 $ this ->composerFactoryForProject ->method ('rootPackage ' )->willReturn ($ rootPackage );
110106
@@ -119,20 +115,8 @@ public function testInstallingExtensionsForPhpProject(): void
119115
120116 $ this ->composerFactoryForProject ->method ('composer ' )->willReturn ($ composer );
121117
122- // $this->installedPiePackages->method('allPiePackages')->willReturn([
123- // 'mismatching' => new Package(
124- // $this->createMock(CompletePackageInterface::class),
125- // ExtensionType::PhpModule,
126- // ExtensionName::normaliseFromString('mismatching'),
127- // 'vendor/mismatching',
128- // '1.9.3',
129- // null,
130- // ),
131- // ]);
132-
133118 $ this ->findMatchingPackages ->method ('for ' )->willReturn ([
134119 ['name ' => 'vendor1/foobar ' , 'description ' => 'The official foobar implementation ' ],
135- ['name ' => 'vendor2/afoobar ' , 'description ' => 'An improved async foobar extension ' ],
136120 ]);
137121
138122 $ this ->questionHelper ->method ('ask ' )->willReturn ('vendor1/foobar: The official foobar implementation ' );
@@ -142,16 +126,63 @@ public function testInstallingExtensionsForPhpProject(): void
142126 ->with ('vendor1/foobar:^1.2 ' );
143127
144128 $ this ->commandTester ->execute (
145- [],
129+ [' --allow-non-interactive-project-install ' => true ],
146130 ['verbosity ' => BufferedOutput::VERBOSITY_VERY_VERBOSE ],
147131 );
148132
149133 $ outputString = $ this ->commandTester ->getDisplay ();
150134
151- $ this ->commandTester ->assertCommandIsSuccessful ();
135+ $ this ->commandTester ->assertCommandIsSuccessful ($ outputString );
136+ self ::assertStringContainsString ('Checking extensions for your project my/project ' , $ outputString );
137+ self ::assertStringContainsString ('requires: ext-standard:* ✅ Already installed ' , $ outputString );
138+ self ::assertStringContainsString ('requires: ext-foobar:^1.2 🚫 Missing ' , $ outputString );
139+ }
140+
141+ public function testInstallingExtensionsForPhpProjectWithMultipleMatches (): void
142+ {
143+ $ rootPackage = new RootPackage ('my/project ' , '1.2.3.0 ' , '1.2.3 ' );
144+ $ rootPackage ->setRequires ([
145+ 'ext-standard ' => new Link ('my/project ' , 'ext-standard ' , new Constraint ('= ' , '* ' ), Link::TYPE_REQUIRE , '* ' ),
146+ 'ext-foobar ' => new Link ('my/project ' , 'ext-foobar ' , new MultiConstraint ([
147+ new Constraint ('>= ' , '1.2.0.0-dev ' ),
148+ new Constraint ('< ' , '2.0.0.0-dev ' ),
149+ ]), Link::TYPE_REQUIRE , '^1.2 ' ),
150+ ]);
151+ $ this ->composerFactoryForProject ->method ('rootPackage ' )->willReturn ($ rootPackage );
152+
153+ $ installedRepository = new InstalledArrayRepository ([$ rootPackage ]);
154+
155+ $ repositoryManager = $ this ->createMock (RepositoryManager::class);
156+ $ repositoryManager ->method ('getLocalRepository ' )->willReturn ($ installedRepository );
157+
158+ $ composer = $ this ->createMock (Composer::class);
159+ $ composer ->method ('getPackage ' )->willReturn ($ rootPackage );
160+ $ composer ->method ('getRepositoryManager ' )->willReturn ($ repositoryManager );
161+
162+ $ this ->composerFactoryForProject ->method ('composer ' )->willReturn ($ composer );
163+
164+ $ this ->findMatchingPackages ->method ('for ' )->willReturn ([
165+ ['name ' => 'vendor1/foobar ' , 'description ' => 'The official foobar implementation ' ],
166+ ['name ' => 'vendor2/afoobar ' , 'description ' => 'An improved async foobar extension ' ],
167+ ]);
168+
169+ $ this ->questionHelper ->method ('ask ' )->willReturn ('vendor1/foobar: The official foobar implementation ' );
170+
171+ $ this ->installSelectedPackage ->expects (self ::never ())
172+ ->method ('withPieCli ' );
173+
174+ $ this ->commandTester ->execute (
175+ ['--allow-non-interactive-project-install ' => true ],
176+ ['verbosity ' => BufferedOutput::VERBOSITY_VERY_VERBOSE ],
177+ );
178+
179+ $ outputString = $ this ->commandTester ->getDisplay ();
180+
181+ self ::assertSame (Command::FAILURE , $ this ->commandTester ->getStatusCode ());
152182 self ::assertStringContainsString ('Checking extensions for your project my/project ' , $ outputString );
153183 self ::assertStringContainsString ('requires: ext-standard:* ✅ Already installed ' , $ outputString );
154184 self ::assertStringContainsString ('requires: ext-foobar:^1.2 🚫 Missing ' , $ outputString );
185+ self ::assertStringContainsString ('Multiple packages were found for ext-foobar ' , $ outputString );
155186 }
156187
157188 public function testInstallingExtensionsForPieProject (): void
0 commit comments