diff --git a/tests/Composer/Test/Command/UpdateCommandTest.php b/tests/Composer/Test/Command/UpdateCommandTest.php index 5b58e52d9..7b5c41280 100644 --- a/tests/Composer/Test/Command/UpdateCommandTest.php +++ b/tests/Composer/Test/Command/UpdateCommandTest.php @@ -12,6 +12,8 @@ namespace Composer\Test\Command; +use Composer\Package\Link; +use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Test\TestCase; use InvalidArgumentException; @@ -135,4 +137,97 @@ OUTPUT $appTester->setInputs(['']); $appTester->run(['command' => 'update', '--interactive' => true]); } + + /** + * @dataProvider provideInteractiveUpdates + * @param array $packageNames + */ + public function testInteractiveTmp(array $packageNames, string $expected): void + { + $this->initTempComposer([ + 'repositories' => [ + 'packages' => [ + 'type' => 'package', + 'package' => [ + ['name' => 'root/req', 'version' => '1.0.0', 'require' => ['dep/pkg' => '^1']], + ['name' => 'dep/pkg', 'version' => '1.0.0'], + ['name' => 'dep/pkg', 'version' => '1.0.1'], + ['name' => 'dep/pkg', 'version' => '1.0.2'], + ['name' => 'another-dep/pkg', 'version' => '1.0.2'], + ], + ], + ], + 'require' => [ + 'root/req' => '1.*', + ], + ]); + + $rootPackage = self::getPackage('root/req'); + $packages = [$rootPackage]; + + foreach ($packageNames as $pkg => $ver) { + $currentPkg = self::getPackage($pkg, $ver); + array_push($packages, $currentPkg); + } + + $rootPackage->setRequires([ + 'dep/pkg' => new Link( + 'root/req', + 'dep/pkg', + new MatchAllConstraint(), + Link::TYPE_REQUIRE, + '^1' + ), + 'another-dep/pkg' => new Link( + 'root/req', + 'another-dep/pkg', + new MatchAllConstraint(), + Link::TYPE_REQUIRE, + '^1' + ), + ]); + + $this->createComposerLock($packages); + $this->createInstalledJson($packages); + + $appTester = $this->getApplicationTester(); + $appTester->setInputs(array_merge(array_keys($packageNames), ['', 'yes'])); + $appTester->run([ + 'command' => 'update', '--interactive' => true, + '--no-audit' => true, + '--dry-run' => true, + ]); + + self::assertStringEndsWith( + trim($expected), + trim($appTester->getDisplay(true)) + ); + } + + public function provideInteractiveUpdates(): \Generator + { + yield [ + ['dep/pkg' => '1.0.1'], + << 1.0.2) +Installing dependencies from lock file (including require-dev) +Package operations: 1 install, 1 update, 0 removals + - Upgrading dep/pkg (1.0.1 => 1.0.2) + - Installing another-dep/pkg (1.0.2) +OUTPUT + ]; + + yield [ + ['dep/pkg' => '1.0.1', 'another-dep/pkg' => '1.0.2'], + << 1.0.2) +Installing dependencies from lock file (including require-dev) +Package operations: 0 installs, 1 update, 0 removals + - Upgrading dep/pkg (1.0.1 => 1.0.2) +OUTPUT + ]; + } }