Skip to content

Commit a82b4a5

Browse files
committed
Ensure test uses --allow-non-interactive-project-install
1 parent 4add071 commit a82b4a5

4 files changed

Lines changed: 64 additions & 28 deletions

File tree

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
displayDetailsOnTestsThatTriggerWarnings="true"
1212
failOnRisky="true"
1313
failOnWarning="true">
14+
<php>
15+
<env name="COMPOSER_NO_INTERACTION" value="1" />
16+
</php>
1417
<testsuites>
1518
<testsuite name="unit">
1619
<directory>test/unit</directory>

src/Command/CommandHelper.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
5252
final class CommandHelper
5353
{
54-
public const ARG_REQUESTED_PACKAGE_AND_VERSION = 'requested-package-and-version';
55-
public const OPTION_WITH_PHP_CONFIG = 'with-php-config';
56-
public const OPTION_WITH_PHP_PATH = 'with-php-path';
57-
public const OPTION_WITH_PHPIZE_PATH = 'with-phpize-path';
58-
public const OPTION_WORKING_DIRECTORY = 'working-dir';
54+
public const ARG_REQUESTED_PACKAGE_AND_VERSION = 'requested-package-and-version';
55+
public const OPTION_WITH_PHP_CONFIG = 'with-php-config';
56+
public const OPTION_WITH_PHP_PATH = 'with-php-path';
57+
public const OPTION_WITH_PHPIZE_PATH = 'with-phpize-path';
58+
public const OPTION_WORKING_DIRECTORY = 'working-dir';
5959
public const OPTION_ALLOW_NON_INTERACTIVE_PROJECT_INSTALL = 'allow-non-interactive-project-install';
60-
private const OPTION_MAKE_PARALLEL_JOBS = 'make-parallel-jobs';
61-
private const OPTION_SKIP_ENABLE_EXTENSION = 'skip-enable-extension';
62-
private const OPTION_FORCE = 'force';
60+
private const OPTION_MAKE_PARALLEL_JOBS = 'make-parallel-jobs';
61+
private const OPTION_SKIP_ENABLE_EXTENSION = 'skip-enable-extension';
62+
private const OPTION_FORCE = 'force';
6363

6464
/** @psalm-suppress UnusedConstructor */
6565
private function __construct()

src/Command/InstallExtensionsForProjectCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@
2525
use Symfony\Component\Console\Command\Command;
2626
use Symfony\Component\Console\Helper\QuestionHelper;
2727
use Symfony\Component\Console\Input\InputInterface;
28-
use Symfony\Component\Console\Input\InputOption;
2928
use Symfony\Component\Console\Output\ConsoleOutputInterface;
3029
use Symfony\Component\Console\Output\NullOutput;
3130
use Symfony\Component\Console\Output\OutputInterface;
3231
use Symfony\Component\Console\Question\ChoiceQuestion;
3332
use Throwable;
3433

34+
use function array_column;
3535
use function array_keys;
3636
use function array_map;
3737
use function array_merge;
3838
use function array_walk;
3939
use function assert;
4040
use function chdir;
41+
use function count;
4142
use function getcwd;
43+
use function implode;
4244
use function in_array;
4345
use function is_dir;
4446
use function is_string;
@@ -131,7 +133,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
131133
'<warning>Aborting! You are not running in interactive mode, and --%s was not specified.</warning>',
132134
CommandHelper::OPTION_ALLOW_NON_INTERACTIVE_PROJECT_INSTALL,
133135
));
134-
// @todo more details
135136

136137
return Command::FAILURE;
137138
}
@@ -270,6 +271,7 @@ static function (array $match): string {
270271

271272
return;
272273
}
274+
273275
$selectedPackageName = substr($selectedPackageAnswer, 0, (int) strpos($selectedPackageAnswer, ':'));
274276
} else {
275277
$selectedPackageName = $matches[0]['name'];

test/integration/Command/InstallExtensionsForProjectCommandTest.php

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

Comments
 (0)