PoolTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. $pool = new Pool;
  21. $repo = new ArrayRepository;
  22. $package = $this->getPackage('foo', '1');
  23. $repo->addPackage($package);
  24. $pool->addRepository($repo);
  25. $this->assertEquals(array($package), $pool->whatProvides('foo'));
  26. $this->assertEquals(array($package), $pool->whatProvides('foo'));
  27. }
  28. public function testPoolIgnoresIrrelevantPackages()
  29. {
  30. $pool = new Pool('stable', array('bar' => BasePackage::STABILITY_BETA));
  31. $repo = new ArrayRepository;
  32. $repo->addPackage($package = $this->getPackage('bar', '1'));
  33. $repo->addPackage($betaPackage = $this->getPackage('bar', '1-beta'));
  34. $repo->addPackage($alphaPackage = $this->getPackage('bar', '1-alpha'));
  35. $repo->addPackage($package2 = $this->getPackage('foo', '1'));
  36. $repo->addPackage($rcPackage2 = $this->getPackage('foo', '1rc'));
  37. $pool->addRepository($repo);
  38. $this->assertEquals(array($package, $betaPackage), $pool->whatProvides('bar'));
  39. $this->assertEquals(array($package2), $pool->whatProvides('foo'));
  40. }
  41. /**
  42. * @expectedException \RuntimeException
  43. */
  44. public function testGetPriorityForNotRegisteredRepository()
  45. {
  46. $pool = new Pool;
  47. $repository = new ArrayRepository;
  48. $pool->getPriority($repository);
  49. }
  50. public function testGetPriorityWhenRepositoryIsRegistered()
  51. {
  52. $pool = new Pool;
  53. $firstRepository = new ArrayRepository;
  54. $pool->addRepository($firstRepository);
  55. $secondRepository = new ArrayRepository;
  56. $pool->addRepository($secondRepository);
  57. $firstPriority = $pool->getPriority($firstRepository);
  58. $secondPriority = $pool->getPriority($secondRepository);
  59. $this->assertEquals(0, $firstPriority);
  60. $this->assertEquals(-1, $secondPriority);
  61. }
  62. public function testWhatProvidesSamePackageForDifferentRepositories()
  63. {
  64. $pool = new Pool;
  65. $firstRepository = new ArrayRepository;
  66. $secondRepository = new ArrayRepository;
  67. $firstPackage = $this->getPackage('foo', '1');
  68. $secondPackage = $this->getPackage('foo', '1');
  69. $thirdPackage = $this->getPackage('foo', '2');
  70. $firstRepository->addPackage($firstPackage);
  71. $secondRepository->addPackage($secondPackage);
  72. $secondRepository->addPackage($thirdPackage);
  73. $pool->addRepository($firstRepository);
  74. $pool->addRepository($secondRepository);
  75. $this->assertEquals(array($firstPackage, $secondPackage, $thirdPackage), $pool->whatProvides('foo'));
  76. }
  77. public function testWhatProvidesPackageWithConstraint()
  78. {
  79. $pool = new Pool;
  80. $repository = new ArrayRepository;
  81. $firstPackage = $this->getPackage('foo', '1');
  82. $secondPackage = $this->getPackage('foo', '2');
  83. $repository->addPackage($firstPackage);
  84. $repository->addPackage($secondPackage);
  85. $pool->addRepository($repository);
  86. $this->assertEquals(array($firstPackage, $secondPackage), $pool->whatProvides('foo'));
  87. $this->assertEquals(array($secondPackage), $pool->whatProvides('foo', $this->getVersionConstraint('==', '2')));
  88. }
  89. public function testPackageById()
  90. {
  91. $pool = new Pool;
  92. $repository = new ArrayRepository;
  93. $package = $this->getPackage('foo', '1');
  94. $repository->addPackage($package);
  95. $pool->addRepository($repository);
  96. $this->assertSame($package, $pool->packageById(1));
  97. }
  98. public function testWhatProvidesWhenPackageCannotBeFound()
  99. {
  100. $pool = new Pool;
  101. $this->assertEquals(array(), $pool->whatProvides('foo'));
  102. }
  103. }