ChannelReaderTest.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. $rfs = 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($rfs);
  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. $rfs = 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($rfs);
  58. $reader->read('http://pear.1.0.net/');
  59. $reader->read('http://pear.1.1.net/');
  60. }
  61. public function testShouldCreatePackages()
  62. {
  63. $reader = $this->getMockBuilder('\Composer\Repository\PearRepository')
  64. ->disableOriginalConstructor()
  65. ->getMock();
  66. $ref = new \ReflectionMethod($reader, 'buildComposerPackages');
  67. $ref->setAccessible(true);
  68. $channelInfo = new ChannelInfo(
  69. 'test.loc',
  70. 'test',
  71. array(
  72. new PackageInfo(
  73. 'test.loc',
  74. 'sample',
  75. 'license',
  76. 'shortDescription',
  77. 'description',
  78. array(
  79. '1.0.0.1' => new ReleaseInfo(
  80. 'stable',
  81. new DependencyInfo(
  82. array(
  83. new DependencyConstraint(
  84. 'required',
  85. '> 5.2.0.0',
  86. 'php',
  87. ''
  88. ),
  89. new DependencyConstraint(
  90. 'conflicts',
  91. '== 2.5.6.0',
  92. 'pear.php.net',
  93. 'broken'
  94. ),
  95. ),
  96. array(
  97. '*' => array(
  98. new DependencyConstraint(
  99. 'optional',
  100. '*',
  101. 'ext',
  102. 'xml'
  103. ),
  104. ),
  105. )
  106. )
  107. ),
  108. )
  109. ),
  110. )
  111. );
  112. $packages = $ref->invoke($reader, $channelInfo, new VersionParser());
  113. $expectedPackage = new CompletePackage('pear-test.loc/sample', '1.0.0.1', '1.0.0.1');
  114. $expectedPackage->setType('pear-library');
  115. $expectedPackage->setDistType('file');
  116. $expectedPackage->setDescription('description');
  117. $expectedPackage->setLicense(array('license'));
  118. $expectedPackage->setDistUrl("http://test.loc/get/sample-1.0.0.1.tgz");
  119. $expectedPackage->setAutoload(array('classmap' => array('')));
  120. $expectedPackage->setIncludePaths(array('/'));
  121. $expectedPackage->setRequires(array(
  122. new Link('pear-test.loc/sample', 'php', $this->createConstraint('>', '5.2.0.0'), 'required', '> 5.2.0.0'),
  123. ));
  124. $expectedPackage->setConflicts(array(
  125. new Link('pear-test.loc/sample', 'pear-pear.php.net/broken', $this->createConstraint('==', '2.5.6.0'), 'conflicts', '== 2.5.6.0'),
  126. ));
  127. $expectedPackage->setSuggests(array(
  128. '*-ext-xml' => '*',
  129. ));
  130. $expectedPackage->setReplaces(array(
  131. new Link('pear-test.loc/sample', 'pear-test/sample', new Constraint('==', '1.0.0.1'), 'replaces', '== 1.0.0.1'),
  132. ));
  133. $this->assertCount(1, $packages);
  134. $this->assertEquals($expectedPackage, $packages[0], 0, 1);
  135. }
  136. private function createConstraint($operator, $version)
  137. {
  138. $constraint = new Constraint($operator, $version);
  139. $constraint->setPrettyString($operator.' '.$version);
  140. return $constraint;
  141. }
  142. }