1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-08 16:17:37 +00:00
composer/tests/Composer/Test/DependencyResolver/TransactionTest.php
Nils Adermann 5bdc0fc9c5 Request jobs replaced by root require / fixed package
The only type of request job remaining was "install" which is really a
root requirement. The only other kind of input for the solver is now a
set of fixed packages.

Rules have been updated to account for only two kinds of former job
reason: FIXED or ROOT_REQUIRE. The job property has always been
redundant and has been removed, since reasonData suffices.

Problem reasons are always rules, so the unnecessary wrapping in an
array has been removed.

We now only ever generate a single rule per root require or fixed
package, so there is no need for the solver to special handle disabling
"jobs" anymore, the rule can just be disabled as usual.

For consistency special handling of rules for jobs in problems has been
integrated into the rule class like all other rule reasons. As part of
this change the error message for root requirements has been improved a
bit to make it clearer where the package installation request came from.

The word job has also been removed from operations, which are called
operations, not jobs.
2020-01-19 23:21:07 +01:00

90 lines
3.5 KiB
PHP

<?php
/*
* 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;
use Composer\DependencyResolver\Transaction;
use Composer\Package\Link;
use Composer\Test\TestCase;
class TransactionTest extends TestCase
{
public function setUp()
{
}
public function testTransactionGenerationAndSorting()
{
$presentPackages = array(
$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(
$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'),
);
$packageD->setRequires(array(
'f/f' => new Link('d/d', 'f/f', $this->getVersionConstraint('>', '0.2'), 'requires'),
'g/provider' => new Link('d/d', 'g/provider', $this->getVersionConstraint('>', '0.2'), 'requires'),
));
$packageG->setProvides(array('g/provider' => new Link('g/g', 'g/provider', $this->getVersionConstraint('==', '1.0.0'), 'provides')));
$expectedOperations = array(
array('job' => 'uninstall', 'package' => $packageC),
array('job' => 'uninstall', 'package' => $packageE),
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' => $packageFalias1),
array('job' => 'markAliasInstalled', 'package' => $packageFalias2),
array('job' => 'install', 'package' => $packageD),
array('job' => 'markAliasUninstalled', 'package' => $packageEalias),
);
$transaction = new Transaction($presentPackages, $resultPackages);
$this->checkTransactionOperations($transaction, $expectedOperations);
}
protected function checkTransactionOperations(Transaction $transaction, array $expected)
{
$result = array();
foreach ($transaction->getOperations() as $operation) {
if ('update' === $operation->getOperationType()) {
$result[] = array(
'job' => 'update',
'from' => $operation->getInitialPackage(),
'to' => $operation->getTargetPackage(),
);
} else {
$result[] = array(
'job' => $operation->getOperationType(),
'package' => $operation->getPackage(),
);
}
}
$this->assertEquals($expected, $result);
}
}