2011-04-05 15:37:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
{
|
2011-11-20 14:06:12 +00:00
|
|
|
$package = $this->getPackage('foo', '1');
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2020-01-17 14:48:31 +00:00
|
|
|
$pool = $this->createPool(array($package));
|
2011-04-05 15:37:19 +00:00
|
|
|
|
|
|
|
$this->assertEquals(array($package), $pool->whatProvides('foo'));
|
|
|
|
$this->assertEquals(array($package), $pool->whatProvides('foo'));
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
$firstPackage = $this->getPackage('foo', '1');
|
|
|
|
$secondPackage = $this->getPackage('foo', '2');
|
|
|
|
|
2020-01-17 14:48:31 +00:00
|
|
|
$pool = $this->createPool(array(
|
2018-09-12 09:49:09 +00:00
|
|
|
$firstPackage,
|
|
|
|
$secondPackage,
|
|
|
|
));
|
2012-03-06 09:11:45 +00:00
|
|
|
|
|
|
|
$this->assertEquals(array($firstPackage, $secondPackage), $pool->whatProvides('foo'));
|
|
|
|
$this->assertEquals(array($secondPackage), $pool->whatProvides('foo', $this->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
|
|
|
{
|
|
|
|
$package = $this->getPackage('foo', '1');
|
|
|
|
|
2020-01-17 14:48:31 +00:00
|
|
|
$pool = $this->createPool(array($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
|
|
|
|
|
|
|
$this->assertEquals(array(), $pool->whatProvides('foo'));
|
|
|
|
}
|
2018-09-11 11:33:29 +00:00
|
|
|
|
2021-10-30 08:30:36 +00:00
|
|
|
/**
|
|
|
|
* @param array<\Composer\Package\BasePackage>|null $packages
|
|
|
|
* @return \Composer\DependencyResolver\Pool
|
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
protected function createPool($packages = array()): \Composer\DependencyResolver\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
|
|
|
}
|