PoolTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\TestCase;
  16. class PoolTest extends TestCase
  17. {
  18. public function testPool()
  19. {
  20. $pool = $this->createPool();
  21. $package = $this->getPackage('foo', '1');
  22. $pool->setPackages(array($package));
  23. $this->assertEquals(array($package), $pool->whatProvides('foo'));
  24. $this->assertEquals(array($package), $pool->whatProvides('foo'));
  25. }
  26. public function testWhatProvidesPackageWithConstraint()
  27. {
  28. $pool = $this->createPool();
  29. $firstPackage = $this->getPackage('foo', '1');
  30. $secondPackage = $this->getPackage('foo', '2');
  31. $pool->setPackages(array(
  32. $firstPackage,
  33. $secondPackage,
  34. ));
  35. $this->assertEquals(array($firstPackage, $secondPackage), $pool->whatProvides('foo'));
  36. $this->assertEquals(array($secondPackage), $pool->whatProvides('foo', $this->getVersionConstraint('==', '2')));
  37. }
  38. public function testPackageById()
  39. {
  40. $pool = $this->createPool();
  41. $package = $this->getPackage('foo', '1');
  42. $pool->setPackages(array($package));
  43. $this->assertSame($package, $pool->packageById(1));
  44. }
  45. public function testWhatProvidesWhenPackageCannotBeFound()
  46. {
  47. $pool = $this->createPool();
  48. $this->assertEquals(array(), $pool->whatProvides('foo'));
  49. }
  50. protected function createPool()
  51. {
  52. return new Pool(array('stable' => BasePackage::STABILITY_STABLE));
  53. }
  54. }