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
25 changes: 22 additions & 3 deletions src/Command/InstallExtensionsForProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Php\Pie\Installing\InstallForPhpProject\InstallSelectedPackage;
use Php\Pie\Platform;
use Php\Pie\Platform\InstalledPiePackages;
use Php\Pie\Platform\TargetPlatform;
use Php\Pie\Util\Emoji;
use Psr\Container\ContainerInterface;
use Safe\Exceptions\DirException;
Expand Down Expand Up @@ -103,6 +104,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);

$rootPackage = $this->composerFactoryForProject->rootPackage($this->io);
$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $this->io);
self::warnIfTargetPhpDoesNotSatisfyComposerRequirement($rootPackage->getRequires()['php'] ?? null, $targetPlatform, $this->io);

if (ExtensionType::isValid($rootPackage->getType())) {
try {
Expand All @@ -122,7 +125,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$this,
$cwd,
$rootPackage,
PieJsonEditor::fromTargetPlatform(CommandHelper::determineTargetPlatformFromInputs($input, new NullIO())),
PieJsonEditor::fromTargetPlatform($targetPlatform),
$input,
$this->io,
);
Expand All @@ -142,8 +145,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}

$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $this->io);

$this->io->write(sprintf(
'Checking extensions for your project <info>%s</info> (path: %s)',
$rootPackage->getPrettyName(),
Expand Down Expand Up @@ -315,4 +316,22 @@ static function (array $match): string {

return $anyErrorsHappened ? self::FAILURE : self::SUCCESS;
}

private static function warnIfTargetPhpDoesNotSatisfyComposerRequirement(Link|null $phpRequirement, TargetPlatform $targetPlatform, IOInterface $io): void
{
if ($phpRequirement === null) {
return;
}

$targetPhpVersion = $targetPlatform->phpBinaryPath->version();
if ($phpRequirement->getConstraint()->matches((new VersionParser())->parseConstraints($targetPhpVersion))) {
return;
}

$io->writeError(sprintf(
'<warning>Target PHP %s does not satisfy composer.json requirement php:%s.</warning>',
$targetPhpVersion,
$phpRequirement->getPrettyConstraint(),
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,40 @@ public function testInstallingExtensionsForPhpProjectWithMultipleMatches(): void
self::assertStringContainsString('Multiple packages were found for ext-foobar', $outputString);
}

public function testWarnsWhenTargetPhpDoesNotSatisfyProjectPhpRequirement(): void
{
$rootPackage = new RootPackage('my/project', '1.2.3.0', '1.2.3');
$rootPackage->setRequires([
'php' => new Link('my/project', 'php', new Constraint('>=', '999.0.0.0-dev'), Link::TYPE_REQUIRE, '^999.0'),
]);
$this->composerFactoryForProject->method('rootPackage')->willReturn($rootPackage);

$installedRepository = new InstalledArrayRepository([$rootPackage]);

$repositoryManager = $this->createMock(RepositoryManager::class);
$repositoryManager->method('getLocalRepository')->willReturn($installedRepository);

$composer = $this->createMock(Composer::class);
$composer->method('getPackage')->willReturn($rootPackage);
$composer->method('getRepositoryManager')->willReturn($repositoryManager);

$this->composerFactoryForProject->method('composer')->willReturn($composer);
$this->installedPiePackages->method('allPiePackages')->willReturn(new PiePackageList([]));

$this->commandTester->execute(
['--allow-non-interactive-project-install' => true],
['verbosity' => BufferedOutput::VERBOSITY_VERY_VERBOSE],
);

$outputString = $this->commandTester->getDisplay();

$this->commandTester->assertCommandIsSuccessful($outputString);
self::assertStringContainsString(
'does not satisfy composer.json requirement php:^999.0.',
$outputString,
);
}

public function testInstallingExtensionsForPieProject(): void
{
$rootPackage = new RootPackage('my/project', '1.2.3.0', '1.2.3');
Expand Down