ChannelReaderTest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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\Repository\Pear;
  12. use Composer\Repository\Pear\ChannelInfo;
  13. use Composer\Repository\Pear\DependencyConstraint;
  14. use Composer\Repository\Pear\DependencyInfo;
  15. use Composer\Repository\Pear\PackageInfo;
  16. use Composer\Repository\Pear\ReleaseInfo;
  17. use Composer\Test\TestCase;
  18. use Composer\Semver\VersionParser;
  19. use Composer\Semver\Constraint\Constraint;
  20. use Composer\Package\Link;
  21. use Composer\Package\CompletePackage;
  22. use Composer\Test\Mock\HttpDownloaderMock;
  23. class ChannelReaderTest extends TestCase
  24. {
  25. public function testShouldBuildPackagesFromPearSchema()
  26. {
  27. $httpDownloader = new HttpDownloaderMock(array(
  28. 'http://pear.net/channel.xml' => file_get_contents(__DIR__ . '/Fixtures/channel.1.1.xml'),
  29. 'http://test.loc/rest11/c/categories.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.1/categories.xml'),
  30. 'http://test.loc/rest11/c/Default/packagesinfo.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.1/packagesinfo.xml'),
  31. ));
  32. $reader = new \Composer\Repository\Pear\ChannelReader($httpDownloader);
  33. $channelInfo = $reader->read('http://pear.net/');
  34. $packages = $channelInfo->getPackages();
  35. $this->assertCount(3, $packages);
  36. $this->assertEquals('HTTP_Client', $packages[0]->getPackageName());
  37. $this->assertEquals('HTTP_Request', $packages[1]->getPackageName());
  38. $this->assertEquals('MDB2', $packages[2]->getPackageName());
  39. $mdb2releases = $packages[2]->getReleases();
  40. $this->assertCount(9, $mdb2releases['2.4.0']->getDependencyInfo()->getOptionals());
  41. }
  42. public function testShouldSelectCorrectReader()
  43. {
  44. $httpDownloader = new HttpDownloaderMock(array(
  45. 'http://pear.1.0.net/channel.xml' => file_get_contents(__DIR__ . '/Fixtures/channel.1.0.xml'),
  46. 'http://test.loc/rest10/p/packages.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/packages.xml'),
  47. 'http://test.loc/rest10/p/http_client/info.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/http_client_info.xml'),
  48. 'http://test.loc/rest10/r/http_client/allreleases.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/http_client_allreleases.xml'),
  49. 'http://test.loc/rest10/r/http_client/deps.1.2.1.txt' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/http_client_deps.1.2.1.txt'),
  50. 'http://test.loc/rest10/p/http_request/info.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/http_request_info.xml'),
  51. 'http://test.loc/rest10/r/http_request/allreleases.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/http_request_allreleases.xml'),
  52. 'http://test.loc/rest10/r/http_request/deps.1.4.0.txt' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/http_request_deps.1.4.0.txt'),
  53. 'http://pear.1.1.net/channel.xml' => file_get_contents(__DIR__ . '/Fixtures/channel.1.1.xml'),
  54. 'http://test.loc/rest11/c/categories.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.1/categories.xml'),
  55. 'http://test.loc/rest11/c/Default/packagesinfo.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.1/packagesinfo.xml'),
  56. ));
  57. $reader = new \Composer\Repository\Pear\ChannelReader($httpDownloader);
  58. $pear10 = $reader->read('http://pear.1.0.net/');
  59. $this->assertCount(2, $pear10->getPackages());
  60. $pear11 = $reader->read('http://pear.1.1.net/');
  61. $this->assertCount(3, $pear11->getPackages());
  62. }
  63. public function testShouldCreatePackages()
  64. {
  65. $reader = $this->getMockBuilder('\Composer\Repository\PearRepository')
  66. ->disableOriginalConstructor()
  67. ->getMock();
  68. $ref = new \ReflectionMethod($reader, 'buildComposerPackages');
  69. $ref->setAccessible(true);
  70. $channelInfo = new ChannelInfo(
  71. 'test.loc',
  72. 'test',
  73. array(
  74. new PackageInfo(
  75. 'test.loc',
  76. 'sample',
  77. 'license',
  78. 'shortDescription',
  79. 'description',
  80. array(
  81. '1.0.0.1' => new ReleaseInfo(
  82. 'stable',
  83. new DependencyInfo(
  84. array(
  85. new DependencyConstraint(
  86. 'required',
  87. '> 5.2.0.0',
  88. 'php',
  89. ''
  90. ),
  91. new DependencyConstraint(
  92. 'conflicts',
  93. '== 2.5.6.0',
  94. 'pear.php.net',
  95. 'broken'
  96. ),
  97. ),
  98. array(
  99. '*' => array(
  100. new DependencyConstraint(
  101. 'optional',
  102. '*',
  103. 'ext',
  104. 'xml'
  105. ),
  106. ),
  107. )
  108. )
  109. ),
  110. )
  111. ),
  112. )
  113. );
  114. $packages = $ref->invoke($reader, $channelInfo, new VersionParser());
  115. $expectedPackage = new CompletePackage('pear-test.loc/sample', '1.0.0.1', '1.0.0.1');
  116. $expectedPackage->setType('pear-library');
  117. $expectedPackage->setDistType('file');
  118. $expectedPackage->setDescription('description');
  119. $expectedPackage->setLicense(array('license'));
  120. $expectedPackage->setDistUrl("http://test.loc/get/sample-1.0.0.1.tgz");
  121. $expectedPackage->setAutoload(array('classmap' => array('')));
  122. $expectedPackage->setIncludePaths(array('/'));
  123. $expectedPackage->setRequires(array(
  124. new Link('pear-test.loc/sample', 'php', $this->createConstraint('>', '5.2.0.0'), 'required', '> 5.2.0.0'),
  125. ));
  126. $expectedPackage->setConflicts(array(
  127. new Link('pear-test.loc/sample', 'pear-pear.php.net/broken', $this->createConstraint('==', '2.5.6.0'), 'conflicts', '== 2.5.6.0'),
  128. ));
  129. $expectedPackage->setSuggests(array(
  130. '*-ext-xml' => '*',
  131. ));
  132. $expectedPackage->setReplaces(array(
  133. new Link('pear-test.loc/sample', 'pear-test/sample', new Constraint('==', '1.0.0.1'), 'replaces', '== 1.0.0.1'),
  134. ));
  135. $this->assertCount(1, $packages);
  136. $this->assertEquals($expectedPackage, $packages[0], 0, 1);
  137. }
  138. private function createConstraint($operator, $version)
  139. {
  140. $constraint = new Constraint($operator, $version);
  141. $constraint->setPrettyString($operator.' '.$version);
  142. return $constraint;
  143. }
  144. }