2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2020-02-13 20: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\Repository;
|
|
|
|
|
|
|
|
use Composer\Repository\InstalledRepository;
|
|
|
|
use Composer\Repository\ArrayRepository;
|
|
|
|
use Composer\Repository\InstalledArrayRepository;
|
|
|
|
use Composer\Package\Link;
|
2020-06-05 14:41:37 +00:00
|
|
|
use Composer\Semver\Constraint\MatchAllConstraint;
|
2020-02-13 20:44:24 +00:00
|
|
|
use Composer\Test\TestCase;
|
|
|
|
|
|
|
|
class InstalledRepositoryTest extends TestCase
|
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testFindPackagesWithReplacersAndProviders(): void
|
2020-02-13 20:44:24 +00:00
|
|
|
{
|
|
|
|
$arrayRepoOne = new InstalledArrayRepository;
|
|
|
|
$arrayRepoOne->addPackage($foo = $this->getPackage('foo', '1'));
|
|
|
|
$arrayRepoOne->addPackage($foo2 = $this->getPackage('foo', '2'));
|
|
|
|
|
|
|
|
$arrayRepoTwo = new InstalledArrayRepository;
|
|
|
|
$arrayRepoTwo->addPackage($bar = $this->getPackage('bar', '1'));
|
|
|
|
$arrayRepoTwo->addPackage($bar2 = $this->getPackage('bar', '2'));
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$foo->setReplaces(['provided' => new Link('foo', 'provided', new MatchAllConstraint())]);
|
|
|
|
$bar2->setProvides(['provided' => new Link('bar', 'provided', new MatchAllConstraint())]);
|
2020-02-13 20:44:24 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$repo = new InstalledRepository([$arrayRepoOne, $arrayRepoTwo]);
|
2020-02-13 20:44:24 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->assertEquals([$foo2], $repo->findPackagesWithReplacersAndProviders('foo', '2'));
|
|
|
|
$this->assertEquals([$bar], $repo->findPackagesWithReplacersAndProviders('bar', '1'));
|
|
|
|
$this->assertEquals([$foo, $bar2], $repo->findPackagesWithReplacersAndProviders('provided'));
|
2020-02-13 20:44:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testAddRepository(): void
|
2020-02-13 20:44:24 +00:00
|
|
|
{
|
|
|
|
$arrayRepoOne = new ArrayRepository;
|
|
|
|
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('LogicException');
|
2020-02-13 20:44:24 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
new InstalledRepository([$arrayRepoOne]);
|
2020-02-13 20:44:24 +00:00
|
|
|
}
|
|
|
|
}
|