1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 00:53:06 +00:00

Add ability to reinstall packages by type (#12114)

Fixes #11364
This commit is contained in:
Jordi Boggiano 2024-09-21 13:37:55 +02:00 committed by GitHub
parent 58905ffe4e
commit 3a2a18175d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 87 additions and 20 deletions

View file

@ -19,49 +19,70 @@ class ReinstallCommandTest extends TestCase
{
/**
* @dataProvider caseProvider
* @param array<string> $packages
* @param array<mixed> $options
* @param string $expected
*/
public function testReinstallCommand(array $packages, string $expected): void
public function testReinstallCommand(array $options, string $expected): void
{
$this->initTempComposer([
'require' => [
'root/req' => '1.*',
'root/anotherreq' => '2.*'
],
'require-dev' => [
'root/anotherreq' => '2.*',
'root/anotherreq2' => '2.*',
'root/lala' => '2.*',
]
]);
$rootReqPackage = self::getPackage('root/req');
$anotherReqPackage = self::getPackage('root/anotherreq');
$anotherReqPackage2 = self::getPackage('root/anotherreq2');
$anotherReqPackage3 = self::getPackage('root/lala');
$rootReqPackage->setType('metapackage');
$anotherReqPackage->setType('metapackage');
$anotherReqPackage2->setType('metapackage');
$anotherReqPackage3->setType('metapackage');
$this->createComposerLock([$rootReqPackage], [$anotherReqPackage]);
$this->createInstalledJson([$rootReqPackage], [$anotherReqPackage]);
$this->createComposerLock([$rootReqPackage], [$anotherReqPackage, $anotherReqPackage2, $anotherReqPackage3]);
$this->createInstalledJson([$rootReqPackage], [$anotherReqPackage, $anotherReqPackage2, $anotherReqPackage3]);
$appTester = $this->getApplicationTester();
$appTester->run([
$appTester->run(array_merge([
'command' => 'reinstall',
'--no-progress' => true,
'--no-plugins' => true,
'packages' => $packages
]);
], $options));
self::assertSame($expected, trim($appTester->getDisplay(true)));
}
public function caseProvider(): Generator
{
yield 'reinstall a package' => [
['root/req', 'root/anotherreq'],
yield 'reinstall a package by name' => [
['packages' => ['root/req', 'root/anotherreq*']],
'- Removing root/req (1.0.0)
- Removing root/anotherreq2 (1.0.0)
- Removing root/anotherreq (1.0.0)
- Installing root/anotherreq (1.0.0)
- Installing root/anotherreq2 (1.0.0)
- Installing root/req (1.0.0)'
];
yield 'reinstall packages by type' => [
['--type' => ['metapackage']],
'- Removing root/req (1.0.0)
- Removing root/lala (1.0.0)
- Removing root/anotherreq2 (1.0.0)
- Removing root/anotherreq (1.0.0)
- Installing root/anotherreq (1.0.0)
- Installing root/anotherreq2 (1.0.0)
- Installing root/lala (1.0.0)
- Installing root/req (1.0.0)'
];
yield 'reinstall a package that is not installed' => [
['root/unknownreq'],
['packages' => ['root/unknownreq']],
'<warning>Pattern "root/unknownreq" does not match any currently installed packages.</warning>
<warning>Found no packages to reinstall, aborting.</warning>'
];