2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2011-04-05 15:37:19 +00:00
|
|
|
|
|
|
|
/*
|
2011-04-16 12:42:35 +00:00
|
|
|
* This file is part of Composer.
|
2011-04-05 15:37:19 +00:00
|
|
|
*
|
2011-04-16 12:42:35 +00:00
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
2011-04-05 15:37:19 +00:00
|
|
|
*
|
|
|
|
* 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\Pool;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-11-20 14:06:12 +00:00
|
|
|
class PoolTest extends TestCase
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPool(): void
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$package = self::getPackage('foo', '1');
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$pool = $this->createPool([$package]);
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->assertEquals([$package], $pool->whatProvides('foo'));
|
|
|
|
$this->assertEquals([$package], $pool->whatProvides('foo'));
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testWhatProvidesPackageWithConstraint(): void
|
2012-03-06 09:11:45 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$firstPackage = self::getPackage('foo', '1');
|
|
|
|
$secondPackage = self::getPackage('foo', '2');
|
2012-03-06 09:11:45 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$pool = $this->createPool([
|
2018-09-12 09:49:09 +00:00
|
|
|
$firstPackage,
|
|
|
|
$secondPackage,
|
2022-08-17 12:20:07 +00:00
|
|
|
]);
|
2012-03-06 09:11:45 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->assertEquals([$firstPackage, $secondPackage], $pool->whatProvides('foo'));
|
2022-11-24 13:39:08 +00:00
|
|
|
$this->assertEquals([$secondPackage], $pool->whatProvides('foo', self::getVersionConstraint('==', '2')));
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPackageById(): void
|
2012-01-22 21:06:09 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$package = self::getPackage('foo', '1');
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$pool = $this->createPool([$package]);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertSame($package, $pool->packageById(1));
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testWhatProvidesWhenPackageCannotBeFound(): void
|
2012-01-22 21:06:09 +00:00
|
|
|
{
|
2018-09-11 11:33:29 +00:00
|
|
|
$pool = $this->createPool();
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->assertEquals([], $pool->whatProvides('foo'));
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
2018-09-11 11:33:29 +00:00
|
|
|
|
2021-10-30 08:30:36 +00:00
|
|
|
/**
|
|
|
|
* @param array<\Composer\Package\BasePackage>|null $packages
|
|
|
|
*/
|
2022-08-17 12:20:07 +00:00
|
|
|
protected function createPool(?array $packages = []): Pool
|
2018-09-11 11:33:29 +00:00
|
|
|
{
|
2020-01-17 14:48:31 +00:00
|
|
|
return new Pool($packages);
|
2018-09-11 11:33:29 +00:00
|
|
|
}
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|