2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2011-10-21 12:44:24 +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;
|
|
|
|
|
|
|
|
use Composer\Repository\ArrayRepository;
|
2020-01-15 13:52:44 +00:00
|
|
|
use Composer\Repository\LockArrayRepository;
|
2011-10-21 12:44:24 +00:00
|
|
|
use Composer\DependencyResolver\DefaultPolicy;
|
|
|
|
use Composer\Package\Link;
|
2012-04-20 20:10:58 +00:00
|
|
|
use Composer\Package\AliasPackage;
|
2018-09-11 11:33:29 +00:00
|
|
|
use Composer\Repository\RepositorySet;
|
2015-09-24 14:32:36 +00:00
|
|
|
use Composer\Semver\Constraint\Constraint;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2011-10-21 12:44:24 +00:00
|
|
|
|
2011-11-20 14:06:12 +00:00
|
|
|
class DefaultPolicyTest extends TestCase
|
2011-10-21 12:44:24 +00:00
|
|
|
{
|
2018-09-11 11:33:29 +00:00
|
|
|
/** @var RepositorySet */
|
|
|
|
protected $repositorySet;
|
2016-09-27 16:03:14 +00:00
|
|
|
/** @var ArrayRepository */
|
2011-10-21 12:44:24 +00:00
|
|
|
protected $repo;
|
2020-01-15 13:52:44 +00:00
|
|
|
/** @var LockArrayRepository */
|
2018-09-13 13:23:05 +00:00
|
|
|
protected $repoLocked;
|
2016-09-27 16:03:14 +00:00
|
|
|
/** @var DefaultPolicy */
|
2011-10-21 12:44:24 +00:00
|
|
|
protected $policy;
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2011-10-21 12:44:24 +00:00
|
|
|
{
|
2020-01-30 19:21:17 +00:00
|
|
|
$this->repositorySet = new RepositorySet('dev');
|
2011-10-21 12:44:24 +00:00
|
|
|
$this->repo = new ArrayRepository;
|
2020-01-15 13:52:44 +00:00
|
|
|
$this->repoLocked = new LockArrayRepository;
|
2011-10-21 12:44:24 +00:00
|
|
|
|
|
|
|
$this->policy = new DefaultPolicy;
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSelectSingle(): void
|
2011-10-21 12:44:24 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA = self::getPackage('A', '1.0'));
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2011-10-21 12:44:24 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA->getId()];
|
|
|
|
$expected = [$packageA->getId()];
|
2011-10-21 12:44:24 +00:00
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2011-10-21 12:44:24 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2011-10-21 12:44:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSelectNewest(): void
|
2011-10-21 12:44:24 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA1 = self::getPackage('A', '1.0'));
|
|
|
|
$this->repo->addPackage($packageA2 = self::getPackage('A', '2.0'));
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2011-10-21 12:44:24 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA1->getId(), $packageA2->getId()];
|
|
|
|
$expected = [$packageA2->getId()];
|
2011-10-21 12:44:24 +00:00
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2011-10-21 12:44:24 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2011-10-21 12:44:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSelectNewestPicksLatest(): void
|
2013-03-28 20:02:55 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA1 = self::getPackage('A', '1.0.0'));
|
|
|
|
$this->repo->addPackage($packageA2 = self::getPackage('A', '1.0.1-alpha'));
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2013-03-28 20:02:55 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA1->getId(), $packageA2->getId()];
|
|
|
|
$expected = [$packageA2->getId()];
|
2013-03-28 20:02:55 +00:00
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2013-03-28 20:02:55 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2013-03-28 20:02:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSelectNewestPicksLatestStableWithPreferStable(): void
|
2013-03-28 20:02:55 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA1 = self::getPackage('A', '1.0.0'));
|
|
|
|
$this->repo->addPackage($packageA2 = self::getPackage('A', '1.0.1-alpha'));
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2013-03-28 20:02:55 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA1->getId(), $packageA2->getId()];
|
|
|
|
$expected = [$packageA1->getId()];
|
2013-03-28 20:02:55 +00:00
|
|
|
|
|
|
|
$policy = new DefaultPolicy(true);
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $policy->selectPreferredPackages($pool, $literals);
|
2013-03-28 20:02:55 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2013-03-28 20:02:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSelectNewestWithDevPicksNonDev(): void
|
2013-05-23 16:12:54 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA1 = self::getPackage('A', 'dev-foo'));
|
|
|
|
$this->repo->addPackage($packageA2 = self::getPackage('A', '1.0.0'));
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2013-05-23 16:12:54 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA1->getId(), $packageA2->getId()];
|
|
|
|
$expected = [$packageA2->getId()];
|
2013-05-23 16:12:54 +00:00
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2013-05-23 16:12:54 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2013-05-23 16:12:54 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 08:25:04 +00:00
|
|
|
public function testSelectNewestWithPreferredVersionPicksPreferredVersionIfAvailable(): void
|
|
|
|
{
|
|
|
|
$this->repo->addPackage($packageA1 = self::getPackage('A', '1.0.0'));
|
|
|
|
$this->repo->addPackage($packageA2 = self::getPackage('A', '1.1.0'));
|
|
|
|
$this->repo->addPackage($packageA2b = self::getPackage('A', '1.1.0'));
|
|
|
|
$this->repo->addPackage($packageA3 = self::getPackage('A', '1.2.0'));
|
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
|
|
|
|
|
|
|
$literals = [$packageA1->getId(), $packageA2->getId(), $packageA2b->getId(), $packageA3->getId()];
|
|
|
|
$expected = [$packageA2->getId(), $packageA2b->getId()];
|
|
|
|
|
|
|
|
$policy = new DefaultPolicy(false, false, ['a' => '1.1.0.0']);
|
|
|
|
$selected = $policy->selectPreferredPackages($pool, $literals);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2023-10-26 08:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSelectNewestWithPreferredVersionPicksNewestOtherwise(): void
|
|
|
|
{
|
|
|
|
$this->repo->addPackage($packageA1 = self::getPackage('A', '1.0.0'));
|
|
|
|
$this->repo->addPackage($packageA2 = self::getPackage('A', '1.2.0'));
|
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
|
|
|
|
|
|
|
$literals = [$packageA1->getId(), $packageA2->getId()];
|
|
|
|
$expected = [$packageA2->getId()];
|
|
|
|
|
|
|
|
$policy = new DefaultPolicy(false, false, ['a' => '1.1.0.0']);
|
|
|
|
$selected = $policy->selectPreferredPackages($pool, $literals);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2023-10-26 08:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSelectNewestWithPreferredVersionPicksLowestIfPreferLowest(): void
|
|
|
|
{
|
|
|
|
$this->repo->addPackage($packageA1 = self::getPackage('A', '1.0.0'));
|
|
|
|
$this->repo->addPackage($packageA2 = self::getPackage('A', '1.2.0'));
|
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
|
|
|
|
|
|
|
$literals = [$packageA1->getId(), $packageA2->getId()];
|
|
|
|
$expected = [$packageA1->getId()];
|
|
|
|
|
|
|
|
$policy = new DefaultPolicy(false, true, ['a' => '1.1.0.0']);
|
|
|
|
$selected = $policy->selectPreferredPackages($pool, $literals);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2023-10-26 08:25:04 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRepositoryOrderingAffectsPriority(): void
|
2016-09-27 16:03:14 +00:00
|
|
|
{
|
|
|
|
$repo1 = new ArrayRepository;
|
|
|
|
$repo2 = new ArrayRepository;
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$repo1->addPackage($package1 = self::getPackage('A', '1.0'));
|
|
|
|
$repo1->addPackage($package2 = self::getPackage('A', '1.1'));
|
|
|
|
$repo2->addPackage($package3 = self::getPackage('A', '1.1'));
|
|
|
|
$repo2->addPackage($package4 = self::getPackage('A', '1.2'));
|
2016-09-27 16:03:14 +00:00
|
|
|
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($repo1);
|
|
|
|
$this->repositorySet->addRepository($repo2);
|
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2016-09-27 16:03:14 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$package1->getId(), $package2->getId(), $package3->getId(), $package4->getId()];
|
|
|
|
$expected = [$package2->getId()];
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2016-09-27 16:03:14 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2016-09-27 16:03:14 +00:00
|
|
|
|
2020-01-30 19:21:17 +00:00
|
|
|
$this->repositorySet = new RepositorySet('dev');
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($repo2);
|
|
|
|
$this->repositorySet->addRepository($repo1);
|
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2016-09-27 16:03:14 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [$package4->getId()];
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2016-09-27 16:03:14 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2011-10-21 12:44:24 +00:00
|
|
|
}
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSelectLocalReposFirst(): void
|
2012-04-20 20:10:58 +00:00
|
|
|
{
|
2016-09-27 16:03:14 +00:00
|
|
|
$repoImportant = new ArrayRepository;
|
2012-04-20 20:10:58 +00:00
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA = self::getPackage('A', 'dev-master'));
|
2012-04-20 20:10:58 +00:00
|
|
|
$this->repo->addPackage($packageAAlias = new AliasPackage($packageA, '2.1.9999999.9999999-dev', '2.1.x-dev'));
|
2022-11-24 13:39:08 +00:00
|
|
|
$repoImportant->addPackage($packageAImportant = self::getPackage('A', 'dev-feature-a'));
|
2016-09-27 16:03:14 +00:00
|
|
|
$repoImportant->addPackage($packageAAliasImportant = new AliasPackage($packageAImportant, '2.1.9999999.9999999-dev', '2.1.x-dev'));
|
2022-11-24 13:39:08 +00:00
|
|
|
$repoImportant->addPackage($packageA2Important = self::getPackage('A', 'dev-master'));
|
2016-09-27 16:03:14 +00:00
|
|
|
$repoImportant->addPackage($packageA2AliasImportant = new AliasPackage($packageA2Important, '2.1.9999999.9999999-dev', '2.1.x-dev'));
|
2012-04-20 20:10:58 +00:00
|
|
|
$packageAAliasImportant->setRootPackageAlias(true);
|
|
|
|
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($repoImportant);
|
|
|
|
$this->repositorySet->addRepository($this->repo);
|
2018-09-13 13:23:05 +00:00
|
|
|
$this->repositorySet->addRepository($this->repoLocked);
|
2018-09-11 11:33:29 +00:00
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2012-04-20 20:10:58 +00:00
|
|
|
|
2018-09-11 11:33:29 +00:00
|
|
|
$packages = $pool->whatProvides('a', new Constraint('=', '2.1.9999999.9999999-dev'));
|
2024-09-21 11:53:33 +00:00
|
|
|
self::assertNotEmpty($packages);
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [];
|
2012-04-20 20:10:58 +00:00
|
|
|
foreach ($packages as $package) {
|
2012-05-19 18:38:56 +00:00
|
|
|
$literals[] = $package->getId();
|
2012-04-20 20:10:58 +00:00
|
|
|
}
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$expected = [$packageAAliasImportant->getId()];
|
2012-04-20 20:10:58 +00:00
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2012-04-20 20:10:58 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2012-04-20 20:10:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSelectAllProviders(): void
|
2011-10-21 12:58:31 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA = self::getPackage('A', '1.0'));
|
|
|
|
$this->repo->addPackage($packageB = self::getPackage('B', '2.0'));
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$packageA->setProvides(['x' => new Link('A', 'X', new Constraint('==', '1.0'), Link::TYPE_PROVIDE)]);
|
|
|
|
$packageB->setProvides(['x' => new Link('B', 'X', new Constraint('==', '1.0'), Link::TYPE_PROVIDE)]);
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackages(['A', 'B'], $this->repoLocked);
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA->getId(), $packageB->getId()];
|
2011-10-21 12:58:31 +00:00
|
|
|
$expected = $literals;
|
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2011-10-21 12:58:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPreferNonReplacingFromSameRepo(): void
|
2011-10-21 12:58:31 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA = self::getPackage('A', '1.0'));
|
|
|
|
$this->repo->addPackage($packageB = self::getPackage('B', '2.0'));
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$packageB->setReplaces(['a' => new Link('B', 'A', new Constraint('==', '1.0'), Link::TYPE_REPLACE)]);
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackages(['A', 'B'], $this->repoLocked);
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA->getId(), $packageB->getId()];
|
2012-05-19 18:38:56 +00:00
|
|
|
$expected = $literals;
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
2011-10-21 12:58:31 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2011-10-21 12:58:31 +00:00
|
|
|
}
|
2011-11-18 23:27:35 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPreferReplacingPackageFromSameVendor(): void
|
2013-04-17 13:39:42 +00:00
|
|
|
{
|
2013-04-17 15:37:22 +00:00
|
|
|
// test with default order
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageB = self::getPackage('vendor-b/replacer', '1.0'));
|
|
|
|
$this->repo->addPackage($packageA = self::getPackage('vendor-a/replacer', '1.0'));
|
2013-04-17 13:39:42 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$packageA->setReplaces(['vendor-a/package' => new Link('vendor-a/replacer', 'vendor-a/package', new Constraint('==', '1.0'), Link::TYPE_REPLACE)]);
|
|
|
|
$packageB->setReplaces(['vendor-a/package' => new Link('vendor-b/replacer', 'vendor-a/package', new Constraint('==', '1.0'), Link::TYPE_REPLACE)]);
|
2013-04-17 13:39:42 +00:00
|
|
|
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackages(['vendor-a/replacer', 'vendor-b/replacer'], $this->repoLocked);
|
2013-04-17 13:39:42 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA->getId(), $packageB->getId()];
|
2013-04-17 13:39:42 +00:00
|
|
|
$expected = $literals;
|
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals, 'vendor-a/package');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $selected);
|
2013-04-17 13:39:42 +00:00
|
|
|
|
2013-04-17 15:37:22 +00:00
|
|
|
// test with reversed order in repo
|
|
|
|
$repo = new ArrayRepository;
|
|
|
|
$repo->addPackage($packageA = clone $packageA);
|
|
|
|
$repo->addPackage($packageB = clone $packageB);
|
|
|
|
|
2020-01-30 19:21:17 +00:00
|
|
|
$repositorySet = new RepositorySet('dev');
|
2018-09-11 11:33:29 +00:00
|
|
|
$repositorySet->addRepository($this->repo);
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackages(['vendor-a/replacer', 'vendor-b/replacer'], $this->repoLocked);
|
2013-04-17 15:37:22 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA->getId(), $packageB->getId()];
|
2013-04-17 15:37:22 +00:00
|
|
|
$expected = $literals;
|
2013-04-17 13:39:42 +00:00
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $this->policy->selectPreferredPackages($pool, $literals, 'vendor-a/package');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2013-04-17 13:39:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSelectLowest(): void
|
2014-11-21 13:01:01 +00:00
|
|
|
{
|
|
|
|
$policy = new DefaultPolicy(false, true);
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->repo->addPackage($packageA1 = self::getPackage('A', '1.0'));
|
|
|
|
$this->repo->addPackage($packageA2 = self::getPackage('A', '2.0'));
|
2018-09-11 11:33:29 +00:00
|
|
|
$this->repositorySet->addRepository($this->repo);
|
|
|
|
|
2020-01-15 13:56:58 +00:00
|
|
|
$pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked);
|
2014-11-21 13:01:01 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$literals = [$packageA1->getId(), $packageA2->getId()];
|
|
|
|
$expected = [$packageA1->getId()];
|
2014-11-21 13:01:01 +00:00
|
|
|
|
2018-09-13 13:23:05 +00:00
|
|
|
$selected = $policy->selectPreferredPackages($pool, $literals);
|
2014-11-21 13:01:01 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($expected, $selected);
|
2014-11-21 13:01:01 +00:00
|
|
|
}
|
2011-10-21 12:44:24 +00:00
|
|
|
}
|