PoolTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\DependencyResolver;
  12. use Composer\DependencyResolver\Pool;
  13. use Composer\Repository\ArrayRepository;
  14. use Composer\Package\BasePackage;
  15. use Composer\Test\TestCase;
  16. class PoolTest extends TestCase
  17. {
  18. public function testPool()
  19. {
  20. $package = $this->getPackage('foo', '1');
  21. $pool = $this->createPool(array($package));
  22. $this->assertEquals(array($package), $pool->whatProvides('foo'));
  23. $this->assertEquals(array($package), $pool->whatProvides('foo'));
  24. }
  25. public function testWhatProvidesPackageWithConstraint()
  26. {
  27. $firstPackage = $this->getPackage('foo', '1');
  28. $secondPackage = $this->getPackage('foo', '2');
  29. $pool = $this->createPool(array(
  30. $firstPackage,
  31. $secondPackage,
  32. ));
  33. $this->assertEquals(array($firstPackage, $secondPackage), $pool->whatProvides('foo'));
  34. $this->assertEquals(array($secondPackage), $pool->whatProvides('foo', $this->getVersionConstraint('==', '2')));
  35. }
  36. public function testPackageById()
  37. {
  38. $package = $this->getPackage('foo', '1');
  39. $pool = $this->createPool(array($package));
  40. $this->assertSame($package, $pool->packageById(1));
  41. }
  42. public function testWhatProvidesWhenPackageCannotBeFound()
  43. {
  44. $pool = $this->createPool();
  45. $this->assertEquals(array(), $pool->whatProvides('foo'));
  46. }
  47. protected function createPool(array $packages = array())
  48. {
  49. return new Pool($packages);
  50. }
  51. }