ChannelReaderTest.php 6.6 KB

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