1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00
This commit is contained in:
Jordi Boggiano 2022-08-17 15:20:07 +03:00 committed by GitHub
parent 6e205a0c84
commit 131da999ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
357 changed files with 5943 additions and 9174 deletions

View file

@ -30,15 +30,15 @@ class TransactionTest extends TestCase
public function testTransactionGenerationAndSorting(): void
{
$presentPackages = array(
$presentPackages = [
$packageA = $this->getPackage('a/a', 'dev-master'),
$packageAalias = $this->getAliasPackage($packageA, '1.0.x-dev'),
$packageB = $this->getPackage('b/b', '1.0.0'),
$packageE = $this->getPackage('e/e', 'dev-foo'),
$packageEalias = $this->getAliasPackage($packageE, '1.0.x-dev'),
$packageC = $this->getPackage('c/c', '1.0.0'),
);
$resultPackages = array(
];
$resultPackages = [
$packageA,
$packageAalias,
$packageBnew = $this->getPackage('b/b', '2.1.3'),
@ -54,71 +54,69 @@ class TransactionTest extends TestCase
$dlModifyingPlugin = $this->getPackage('x/downloads-modifying', '1.0.0'),
$dlModifyingPlugin2Dep = $this->getPackage('x/downloads-modifying2-dep', '1.0.0'),
$dlModifyingPlugin2 = $this->getPackage('x/downloads-modifying2', '1.0.0'),
);
];
$plugin->setType('composer-installer');
foreach (array($plugin2, $dlModifyingPlugin, $dlModifyingPlugin2) as $pluginPackage) {
foreach ([$plugin2, $dlModifyingPlugin, $dlModifyingPlugin2] as $pluginPackage) {
$pluginPackage->setType('composer-plugin');
}
$plugin2->setRequires(array(
$plugin2->setRequires([
'x/plugin2-dep' => new Link('x/plugin2', 'x/plugin2-dep', $this->getVersionConstraint('=', '1.0.0'), Link::TYPE_REQUIRE),
));
$dlModifyingPlugin2->setRequires(array(
]);
$dlModifyingPlugin2->setRequires([
'x/downloads-modifying2-dep' => new Link('x/downloads-modifying2', 'x/downloads-modifying2-dep', $this->getVersionConstraint('=', '1.0.0'), Link::TYPE_REQUIRE),
));
$dlModifyingPlugin->setExtra(array('plugin-modifies-downloads' => true));
$dlModifyingPlugin2->setExtra(array('plugin-modifies-downloads' => true));
]);
$dlModifyingPlugin->setExtra(['plugin-modifies-downloads' => true]);
$dlModifyingPlugin2->setExtra(['plugin-modifies-downloads' => true]);
$packageD->setRequires(array(
$packageD->setRequires([
'f/f' => new Link('d/d', 'f/f', $this->getVersionConstraint('>', '0.2'), Link::TYPE_REQUIRE),
'g/provider' => new Link('d/d', 'g/provider', $this->getVersionConstraint('>', '0.2'), Link::TYPE_REQUIRE),
));
$packageG->setProvides(array('g/provider' => new Link('g/g', 'g/provider', $this->getVersionConstraint('==', '1.0.0'), Link::TYPE_PROVIDE)));
]);
$packageG->setProvides(['g/provider' => new Link('g/g', 'g/provider', $this->getVersionConstraint('==', '1.0.0'), Link::TYPE_PROVIDE)]);
$expectedOperations = array(
array('job' => 'uninstall', 'package' => $packageC),
array('job' => 'uninstall', 'package' => $packageE),
array('job' => 'markAliasUninstalled', 'package' => $packageEalias),
array('job' => 'install', 'package' => $dlModifyingPlugin),
array('job' => 'install', 'package' => $dlModifyingPlugin2Dep),
array('job' => 'install', 'package' => $dlModifyingPlugin2),
array('job' => 'install', 'package' => $plugin),
array('job' => 'install', 'package' => $plugin2Dep),
array('job' => 'install', 'package' => $plugin2),
array('job' => 'install', 'package' => $packageA0first),
array('job' => 'update', 'from' => $packageB, 'to' => $packageBnew),
array('job' => 'install', 'package' => $packageG),
array('job' => 'install', 'package' => $packageF),
array('job' => 'markAliasInstalled', 'package' => $packageFalias2),
array('job' => 'markAliasInstalled', 'package' => $packageFalias1),
array('job' => 'install', 'package' => $packageD),
);
$expectedOperations = [
['job' => 'uninstall', 'package' => $packageC],
['job' => 'uninstall', 'package' => $packageE],
['job' => 'markAliasUninstalled', 'package' => $packageEalias],
['job' => 'install', 'package' => $dlModifyingPlugin],
['job' => 'install', 'package' => $dlModifyingPlugin2Dep],
['job' => 'install', 'package' => $dlModifyingPlugin2],
['job' => 'install', 'package' => $plugin],
['job' => 'install', 'package' => $plugin2Dep],
['job' => 'install', 'package' => $plugin2],
['job' => 'install', 'package' => $packageA0first],
['job' => 'update', 'from' => $packageB, 'to' => $packageBnew],
['job' => 'install', 'package' => $packageG],
['job' => 'install', 'package' => $packageF],
['job' => 'markAliasInstalled', 'package' => $packageFalias2],
['job' => 'markAliasInstalled', 'package' => $packageFalias1],
['job' => 'install', 'package' => $packageD],
];
$transaction = new Transaction($presentPackages, $resultPackages);
$this->checkTransactionOperations($transaction, $expectedOperations);
}
/**
* @param \Composer\DependencyResolver\Transaction $transaction
* @param array<array{job: string, package?: PackageInterface, from?: PackageInterface, to?: PackageInterface}> $expected
* @return void
*/
protected function checkTransactionOperations(Transaction $transaction, array $expected): void
{
$result = array();
$result = [];
foreach ($transaction->getOperations() as $operation) {
if ($operation instanceof UpdateOperation) {
$result[] = array(
$result[] = [
'job' => 'update',
'from' => $operation->getInitialPackage(),
'to' => $operation->getTargetPackage(),
);
];
} elseif ($operation instanceof InstallOperation || $operation instanceof UninstallOperation || $operation instanceof MarkAliasInstalledOperation || $operation instanceof MarkAliasUninstalledOperation) {
$result[] = array(
$result[] = [
'job' => $operation->getOperationType(),
'package' => $operation->getPackage(),
);
];
} else {
throw new \UnexpectedValueException('Unknown operation type: '.get_class($operation));
}