2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2019-11-08 16:51:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\DependencyResolver;
|
|
|
|
|
2021-09-05 14:02:10 +00:00
|
|
|
use Composer\DependencyResolver\Operation\InstallOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\UninstallOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\UpdateOperation;
|
2019-11-08 16:51:18 +00:00
|
|
|
use Composer\DependencyResolver\Transaction;
|
|
|
|
use Composer\Package\Link;
|
2022-02-23 15:57:47 +00:00
|
|
|
use Composer\Package\PackageInterface;
|
2019-11-08 16:51:18 +00:00
|
|
|
use Composer\Test\TestCase;
|
|
|
|
|
|
|
|
class TransactionTest extends TestCase
|
|
|
|
{
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2019-11-08 16:51:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testTransactionGenerationAndSorting(): void
|
2019-11-08 16:51:18 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$presentPackages = [
|
2019-11-08 16:51:18 +00:00
|
|
|
$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'),
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
|
|
|
$resultPackages = [
|
2019-11-08 16:51:18 +00:00
|
|
|
$packageA,
|
|
|
|
$packageAalias,
|
|
|
|
$packageBnew = $this->getPackage('b/b', '2.1.3'),
|
|
|
|
$packageD = $this->getPackage('d/d', '1.2.3'),
|
|
|
|
$packageF = $this->getPackage('f/f', '1.0.0'),
|
|
|
|
$packageFalias1 = $this->getAliasPackage($packageF, 'dev-foo'),
|
|
|
|
$packageG = $this->getPackage('g/g', '1.0.0'),
|
|
|
|
$packageA0first = $this->getPackage('a0/first', '1.2.3'),
|
|
|
|
$packageFalias2 = $this->getAliasPackage($packageF, 'dev-bar'),
|
2020-10-25 13:06:45 +00:00
|
|
|
$plugin = $this->getPackage('x/plugin', '1.0.0'),
|
|
|
|
$plugin2Dep = $this->getPackage('x/plugin2-dep', '1.0.0'),
|
|
|
|
$plugin2 = $this->getPackage('x/plugin2', '1.0.0'),
|
|
|
|
$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'),
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2019-11-08 16:51:18 +00:00
|
|
|
|
2020-10-25 13:06:45 +00:00
|
|
|
$plugin->setType('composer-installer');
|
2022-08-17 12:20:07 +00:00
|
|
|
foreach ([$plugin2, $dlModifyingPlugin, $dlModifyingPlugin2] as $pluginPackage) {
|
2020-10-25 13:06:45 +00:00
|
|
|
$pluginPackage->setType('composer-plugin');
|
|
|
|
}
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$plugin2->setRequires([
|
2020-10-25 13:06:45 +00:00
|
|
|
'x/plugin2-dep' => new Link('x/plugin2', 'x/plugin2-dep', $this->getVersionConstraint('=', '1.0.0'), Link::TYPE_REQUIRE),
|
2022-08-17 12:20:07 +00:00
|
|
|
]);
|
|
|
|
$dlModifyingPlugin2->setRequires([
|
2020-10-25 13:06:45 +00:00
|
|
|
'x/downloads-modifying2-dep' => new Link('x/downloads-modifying2', 'x/downloads-modifying2-dep', $this->getVersionConstraint('=', '1.0.0'), Link::TYPE_REQUIRE),
|
2022-08-17 12:20:07 +00:00
|
|
|
]);
|
|
|
|
$dlModifyingPlugin->setExtra(['plugin-modifies-downloads' => true]);
|
|
|
|
$dlModifyingPlugin2->setExtra(['plugin-modifies-downloads' => true]);
|
2020-10-25 13:06:45 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$packageD->setRequires([
|
2020-09-15 08:44:28 +00:00
|
|
|
'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),
|
2022-08-17 12:20:07 +00:00
|
|
|
]);
|
|
|
|
$packageG->setProvides(['g/provider' => new Link('g/g', 'g/provider', $this->getVersionConstraint('==', '1.0.0'), Link::TYPE_PROVIDE)]);
|
2019-11-08 16:51:18 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$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],
|
|
|
|
];
|
2019-11-08 16:51:18 +00:00
|
|
|
|
|
|
|
$transaction = new Transaction($presentPackages, $resultPackages);
|
|
|
|
$this->checkTransactionOperations($transaction, $expectedOperations);
|
|
|
|
}
|
|
|
|
|
2021-10-30 08:30:36 +00:00
|
|
|
/**
|
2022-02-23 15:57:47 +00:00
|
|
|
* @param array<array{job: string, package?: PackageInterface, from?: PackageInterface, to?: PackageInterface}> $expected
|
2021-10-30 08:30:36 +00:00
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
protected function checkTransactionOperations(Transaction $transaction, array $expected): void
|
2019-11-08 16:51:18 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$result = [];
|
2019-11-08 16:51:18 +00:00
|
|
|
foreach ($transaction->getOperations() as $operation) {
|
2021-09-05 14:02:10 +00:00
|
|
|
if ($operation instanceof UpdateOperation) {
|
2022-08-17 12:20:07 +00:00
|
|
|
$result[] = [
|
2019-11-08 16:51:18 +00:00
|
|
|
'job' => 'update',
|
|
|
|
'from' => $operation->getInitialPackage(),
|
|
|
|
'to' => $operation->getTargetPackage(),
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2021-09-05 14:02:10 +00:00
|
|
|
} elseif ($operation instanceof InstallOperation || $operation instanceof UninstallOperation || $operation instanceof MarkAliasInstalledOperation || $operation instanceof MarkAliasUninstalledOperation) {
|
2022-08-17 12:20:07 +00:00
|
|
|
$result[] = [
|
2020-01-19 22:11:36 +00:00
|
|
|
'job' => $operation->getOperationType(),
|
2019-11-08 16:51:18 +00:00
|
|
|
'package' => $operation->getPackage(),
|
2022-08-17 12:20:07 +00:00
|
|
|
];
|
2021-09-05 14:02:10 +00:00
|
|
|
} else {
|
|
|
|
throw new \UnexpectedValueException('Unknown operation type: '.get_class($operation));
|
2019-11-08 16:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
}
|