1
0
Fork 0

Add Update Interactive tests (#12065)

* Add Update Interactive tests

* Fix type + remove extra comma

* Used `php-cs-fixer`

* Normalize for windows + fix use of `Generator`
pull/12091/head
Mohamed Hubail 2024-08-21 19:14:40 +03:00 committed by GitHub
parent 8715c7b8d6
commit 47b924d27c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 95 additions and 0 deletions

View File

@ -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<mixed> $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'],
<<<OUTPUT
Lock file operations: 1 install, 1 update, 0 removals
- Locking another-dep/pkg (1.0.2)
- Upgrading 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'],
<<<OUTPUT
Lock file operations: 0 installs, 1 update, 0 removals
- Upgrading dep/pkg (1.0.1 => 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
];
}
}