diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index 77257e98..1e6c81b4 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -80,6 +80,10 @@ public function execute(InputInterface $input, OutputInterface $output): int return self::INVALID; } + if ($installFromLock && CommandHelper::noDev($input)) { + $this->io->writeError('The --no-dev option has no effect when used with --from-lock; all extensions in the lock file will be installed.'); + } + if (! $installFromLock && ! $input->getArgument(CommandHelper::ARG_REQUESTED_PACKAGE_AND_VERSION)) { return ($this->invokeSubCommand)( $this, diff --git a/test/unit/Command/InstallCommandTest.php b/test/unit/Command/InstallCommandTest.php index 6e77cb7e..531ace5a 100644 --- a/test/unit/Command/InstallCommandTest.php +++ b/test/unit/Command/InstallCommandTest.php @@ -4,10 +4,18 @@ namespace Php\PieUnitTest\Command; +use Composer\IO\BufferIO; use Php\Pie\Command\InstallCommand; +use Php\Pie\Command\InvokeSubCommand; +use Php\Pie\ComposerIntegration\ComposerIntegrationHandler; use Php\Pie\Container; +use Php\Pie\DependencyResolver\DependencyInstaller\PrescanSystemDependencies; +use Php\Pie\DependencyResolver\DependencyResolver; +use Php\Pie\Installing\InstallForPhpProject\FindMatchingPackages; +use Php\Pie\SelfManage\BuildTools\CheckAllBuildTools; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Tester\CommandTester; #[CoversClass(InstallCommand::class)] final class InstallCommandTest extends TestCase @@ -19,4 +27,34 @@ public function testFromLockOptionExistsOnInstallCommand(): void self::assertTrue($definition->hasOption(InstallCommand::OPTION_FROM_LOCK)); } + + public function testNoDevWithFromLockWarnsThatNoDevHasNoEffect(): void + { + $io = new BufferIO(); + + $composerIntegrationHandler = $this->createMock(ComposerIntegrationHandler::class); + $composerIntegrationHandler->expects(self::once())->method('runInstall'); + + $commandTester = new CommandTester(new InstallCommand( + Container::testFactory(), + $this->createMock(DependencyResolver::class), + $this->createMock(PrescanSystemDependencies::class), + $composerIntegrationHandler, + $this->createMock(InvokeSubCommand::class), + $this->createMock(FindMatchingPackages::class), + $io, + $this->createMock(CheckAllBuildTools::class), + )); + + $commandTester->execute([ + '--from-lock' => true, + '--no-dev' => true, + ]); + + $commandTester->assertCommandIsSuccessful(); + self::assertStringContainsString( + 'The --no-dev option has no effect when used with --from-lock', + $io->getOutput(), + ); + } }