2022-06-30 13:05:34 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\Repository;
|
|
|
|
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
use Composer\Repository\RepositoryUtils;
|
|
|
|
use Composer\Test\TestCase;
|
|
|
|
use Generator;
|
|
|
|
|
|
|
|
class RepositoryUtilsTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideFilterRequireTests
|
|
|
|
* @param PackageInterface[] $pkgs
|
|
|
|
* @param string[] $expected
|
|
|
|
*/
|
|
|
|
public function testFilterRequiredPackages(array $pkgs, PackageInterface $requirer, array $expected): void
|
|
|
|
{
|
|
|
|
$expected = array_map(static function (string $name) use ($pkgs): PackageInterface {
|
|
|
|
return $pkgs[$name];
|
|
|
|
}, $expected);
|
|
|
|
|
|
|
|
self::assertSame($expected, RepositoryUtils::filterRequiredPackages($pkgs, $requirer));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<PackageInterface>
|
|
|
|
*/
|
2022-11-24 13:39:08 +00:00
|
|
|
private static function getPackages(): array
|
2022-06-30 13:05:34 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$packageA = self::getPackage('required/a');
|
|
|
|
$packageB = self::getPackage('required/b');
|
|
|
|
self::configureLinks($packageB, ['require' => ['required/c' => '*']]);
|
|
|
|
$packageC = self::getPackage('required/c');
|
|
|
|
$packageCAlias = self::getAliasPackage($packageC, '2.0.0');
|
2022-06-30 13:05:34 +00:00
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$packageCircular = self::getPackage('required/circular');
|
|
|
|
self::configureLinks($packageCircular, ['require' => ['required/circular-b' => '*']]);
|
|
|
|
$packageCircularB = self::getPackage('required/circular-b');
|
|
|
|
self::configureLinks($packageCircularB, ['require' => ['required/circular' => '*']]);
|
2022-06-30 13:05:34 +00:00
|
|
|
|
|
|
|
return [
|
2022-11-24 13:39:08 +00:00
|
|
|
self::getPackage('dummy/pkg'),
|
|
|
|
self::getPackage('dummy/pkg2', '2.0.0'),
|
2022-06-30 13:05:34 +00:00
|
|
|
'a' => $packageA,
|
|
|
|
'b' => $packageB,
|
|
|
|
'c' => $packageC,
|
|
|
|
'c-alias' => $packageCAlias,
|
|
|
|
'circular' => $packageCircular,
|
|
|
|
'circular-b' => $packageCircularB,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function provideFilterRequireTests(): Generator
|
2022-06-30 13:05:34 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$pkgs = self::getPackages();
|
2022-06-30 13:05:34 +00:00
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$requirer = self::getPackage('requirer/pkg');
|
2022-06-30 13:05:34 +00:00
|
|
|
yield 'no require' => [$pkgs, $requirer, []];
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$requirer = self::getPackage('requirer/pkg');
|
|
|
|
self::configureLinks($requirer, ['require-dev' => ['required/a' => '*']]);
|
2022-06-30 13:05:34 +00:00
|
|
|
yield 'require-dev has no effect' => [$pkgs, $requirer, []];
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$requirer = self::getPackage('requirer/pkg');
|
|
|
|
self::configureLinks($requirer, ['require' => ['required/a' => '*']]);
|
2022-06-30 13:05:34 +00:00
|
|
|
yield 'simple require' => [$pkgs, $requirer, ['a']];
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$requirer = self::getPackage('requirer/pkg');
|
|
|
|
self::configureLinks($requirer, ['require' => ['required/a' => 'dev-lala']]);
|
2022-06-30 13:05:34 +00:00
|
|
|
yield 'require constraint is irrelevant' => [$pkgs, $requirer, ['a']];
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$requirer = self::getPackage('requirer/pkg');
|
|
|
|
self::configureLinks($requirer, ['require' => ['required/b' => '*']]);
|
2022-06-30 13:05:34 +00:00
|
|
|
yield 'require transitive deps and aliases are included' => [$pkgs, $requirer, ['b', 'c', 'c-alias']];
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$requirer = self::getPackage('requirer/pkg');
|
|
|
|
self::configureLinks($requirer, ['require' => ['required/circular' => '*']]);
|
2022-06-30 13:05:34 +00:00
|
|
|
yield 'circular deps are no problem' => [$pkgs, $requirer, ['circular', 'circular-b']];
|
|
|
|
}
|
|
|
|
}
|