2023-06-23 07:47:36 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Command;
|
|
|
|
|
|
|
|
use Composer\Test\TestCase;
|
|
|
|
use Generator;
|
|
|
|
|
|
|
|
class ReinstallCommandTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider caseProvider
|
2024-09-21 11:37:55 +00:00
|
|
|
* @param array<mixed> $options
|
2023-06-23 07:47:36 +00:00
|
|
|
* @param string $expected
|
|
|
|
*/
|
2024-09-21 11:37:55 +00:00
|
|
|
public function testReinstallCommand(array $options, string $expected): void
|
2023-06-23 07:47:36 +00:00
|
|
|
{
|
|
|
|
$this->initTempComposer([
|
|
|
|
'require' => [
|
|
|
|
'root/req' => '1.*',
|
2024-09-21 11:37:55 +00:00
|
|
|
],
|
|
|
|
'require-dev' => [
|
|
|
|
'root/anotherreq' => '2.*',
|
|
|
|
'root/anotherreq2' => '2.*',
|
|
|
|
'root/lala' => '2.*',
|
2023-06-23 07:47:36 +00:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
$rootReqPackage = self::getPackage('root/req');
|
|
|
|
$anotherReqPackage = self::getPackage('root/anotherreq');
|
2024-09-21 11:37:55 +00:00
|
|
|
$anotherReqPackage2 = self::getPackage('root/anotherreq2');
|
|
|
|
$anotherReqPackage3 = self::getPackage('root/lala');
|
2023-06-23 07:47:36 +00:00
|
|
|
$rootReqPackage->setType('metapackage');
|
|
|
|
$anotherReqPackage->setType('metapackage');
|
2024-09-21 11:37:55 +00:00
|
|
|
$anotherReqPackage2->setType('metapackage');
|
|
|
|
$anotherReqPackage3->setType('metapackage');
|
2023-06-23 07:47:36 +00:00
|
|
|
|
2024-09-21 11:37:55 +00:00
|
|
|
$this->createComposerLock([$rootReqPackage], [$anotherReqPackage, $anotherReqPackage2, $anotherReqPackage3]);
|
|
|
|
$this->createInstalledJson([$rootReqPackage], [$anotherReqPackage, $anotherReqPackage2, $anotherReqPackage3]);
|
2023-06-23 07:47:36 +00:00
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
2024-09-21 11:37:55 +00:00
|
|
|
$appTester->run(array_merge([
|
2023-06-23 07:47:36 +00:00
|
|
|
'command' => 'reinstall',
|
|
|
|
'--no-progress' => true,
|
|
|
|
'--no-plugins' => true,
|
2024-09-21 11:37:55 +00:00
|
|
|
], $options));
|
2023-06-23 07:47:36 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, trim($appTester->getDisplay(true)));
|
2023-06-23 07:47:36 +00:00
|
|
|
}
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
public function caseProvider(): Generator
|
2023-06-23 07:47:36 +00:00
|
|
|
{
|
2024-09-21 11:37:55 +00:00
|
|
|
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']],
|
2023-06-23 07:47:36 +00:00
|
|
|
'- Removing root/req (1.0.0)
|
2024-09-21 11:37:55 +00:00
|
|
|
- Removing root/lala (1.0.0)
|
|
|
|
- Removing root/anotherreq2 (1.0.0)
|
2023-06-23 07:47:36 +00:00
|
|
|
- Removing root/anotherreq (1.0.0)
|
|
|
|
- Installing root/anotherreq (1.0.0)
|
2024-09-21 11:37:55 +00:00
|
|
|
- Installing root/anotherreq2 (1.0.0)
|
|
|
|
- Installing root/lala (1.0.0)
|
2023-06-23 07:47:36 +00:00
|
|
|
- Installing root/req (1.0.0)'
|
|
|
|
];
|
|
|
|
|
|
|
|
yield 'reinstall a package that is not installed' => [
|
2024-09-21 11:37:55 +00:00
|
|
|
['packages' => ['root/unknownreq']],
|
2023-06-23 07:47:36 +00:00
|
|
|
'<warning>Pattern "root/unknownreq" does not match any currently installed packages.</warning>
|
|
|
|
<warning>Found no packages to reinstall, aborting.</warning>'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|