From c39e958a6f7b3a2c3b36e3b2d39d7731e2ab34da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 21 Mar 2013 09:06:11 +0100 Subject: [PATCH] Added test for ComposerRepository::whatProvides --- .../Repository/ComposerRepositoryTest.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/Composer/Test/Repository/ComposerRepositoryTest.php b/tests/Composer/Test/Repository/ComposerRepositoryTest.php index 5061218e2..bad24d6d4 100644 --- a/tests/Composer/Test/Repository/ComposerRepositoryTest.php +++ b/tests/Composer/Test/Repository/ComposerRepositoryTest.php @@ -16,6 +16,8 @@ use Composer\Repository\ComposerRepository; use Composer\IO\NullIO; use Composer\Test\Mock\FactoryMock; use Composer\Test\TestCase; +use Composer\Package\Loader\ArrayLoader; +use Composer\Package\Version\VersionParser; class ComposerRepositoryTest extends TestCase { @@ -93,4 +95,74 @@ class ComposerRepositoryTest extends TestCase ), ); } + + public function testWhatProvides() + { + $repo = $this->getMockBuilder('Composer\Repository\ComposerRepository') + ->disableOriginalConstructor() + ->setMethods(array('fetchFile')) + ->getMock(); + + $cache = $this->getMockBuilder('Composer\Cache')->disableOriginalConstructor()->getMock(); + $cache->expects($this->any()) + ->method('sha256') + ->will($this->returnValue(false)); + + $properties = array( + 'cache' => $cache, + 'loader' => new ArrayLoader(), + 'providerListing' => array('p/a.json' => array('sha256' => 'xxx')) + ); + + foreach ($properties as $property => $value) { + $ref = new \ReflectionProperty($repo, $property); + $ref->setAccessible(true); + $ref->setValue($repo, $value); + } + + $repo->expects($this->any()) + ->method('fetchFile') + ->will($this->returnValue(array( + 'packages' => array( + array(array( + 'uid' => 1, + 'name' => 'a', + 'version' => 'dev-master', + 'extra' => array('branch-alias' => array('dev-master' => '1.0.x-dev')), + )), + array(array( + 'uid' => 2, + 'name' => 'a', + 'version' => 'dev-develop', + 'extra' => array('branch-alias' => array('dev-develop' => '1.1.x-dev')), + )), + array(array( + 'uid' => 3, + 'name' => 'a', + 'version' => '0.6', + )), + ) + ))); + + $pool = $this->getMock('Composer\DependencyResolver\Pool'); + $pool->expects($this->any()) + ->method('isPackageAcceptable') + ->will($this->returnValue(true)); + + $versionParser = new VersionParser(); + $repo->setRootAliases(array( + 'a' => array( + $versionParser->normalize('0.6') => array('alias' => 'dev-feature', 'alias_normalized' => $versionParser->normalize('dev-feature')), + $versionParser->normalize('1.1.x-dev') => array('alias' => '1.0', 'alias_normalized' => $versionParser->normalize('1.0')), + ), + )); + + $packages = $repo->whatProvides($pool, 'a'); + + $this->assertCount(7, $packages); + $this->assertEquals(array('1', '1-alias', '2', '2-alias', '2-root', '3', '3-root'), array_keys($packages)); + $this->assertInstanceOf('Composer\Package\AliasPackage', $packages['2-root']); + $this->assertSame($packages['2'], $packages['2-root']->getAliasOf()); + $this->assertSame($packages['2'], $packages['2-alias']->getAliasOf()); + } }