PearRepositoryTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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;
  12. use Composer\Repository\PearRepository;
  13. use Composer\Test\TestCase;
  14. /**
  15. * @group legacy
  16. */
  17. class PearRepositoryTest extends TestCase
  18. {
  19. /**
  20. * @var PearRepository
  21. */
  22. private $repository;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. private $remoteFilesystem;
  27. public function testComposerShouldSetIncludePath()
  28. {
  29. $url = 'pear.phpmd.org';
  30. if (!@file_get_contents('http://'.$url)) {
  31. $this->markTestSkipped('Repository '.$url.' appears to be unreachable');
  32. }
  33. $expectedPackages = array(
  34. array('name' => 'pear-pear.phpmd.org/PHP_PMD', 'version' => '1.3.3'),
  35. );
  36. $repoConfig = array(
  37. 'url' => $url,
  38. );
  39. $this->createRepository($repoConfig);
  40. foreach ($expectedPackages as $expectedPackage) {
  41. $package = $this->repository->findPackage($expectedPackage['name'], $expectedPackage['version']);
  42. $this->assertInstanceOf(
  43. 'Composer\Package\PackageInterface',
  44. $package,
  45. 'Expected package ' . $expectedPackage['name'] . ', version ' . $expectedPackage['version'] .
  46. ' not found in pear channel ' . $url
  47. );
  48. $this->assertSame(array('/'), $package->getIncludePaths());
  49. }
  50. }
  51. /**
  52. * @dataProvider repositoryDataProvider
  53. * @param string $url
  54. * @param array $expectedPackages
  55. */
  56. public function testRepositoryRead($url, array $expectedPackages)
  57. {
  58. $repoConfig = array(
  59. 'url' => $url,
  60. );
  61. if (!@file_get_contents('http://'.$url)) {
  62. $this->markTestSkipped('Repository '.$url.' appears to be unreachable');
  63. }
  64. $this->createRepository($repoConfig);
  65. foreach ($expectedPackages as $expectedPackage) {
  66. $this->assertInstanceOf(
  67. 'Composer\Package\PackageInterface',
  68. $this->repository->findPackage($expectedPackage['name'], $expectedPackage['version']),
  69. 'Expected package ' . $expectedPackage['name'] . ', version ' . $expectedPackage['version'] .
  70. ' not found in pear channel ' . $url
  71. );
  72. }
  73. }
  74. public function repositoryDataProvider()
  75. {
  76. return array(
  77. array(
  78. 'pear.php.net',
  79. array(
  80. array('name' => 'pear-pear.php.net/PEAR', 'version' => '1.9.4'),
  81. ),
  82. ),
  83. array(
  84. 'pear.pdepend.org',
  85. array(
  86. array('name' => 'pear-pear.pdepend.org/PHP_Depend', 'version' => '1.0.5'),
  87. ),
  88. ),
  89. array(
  90. 'pear.phpmd.org',
  91. array(
  92. array('name' => 'pear-pear.phpmd.org/PHP_PMD', 'version' => '1.3.3'),
  93. ),
  94. ),
  95. array(
  96. 'pear.doctrine-project.org',
  97. array(
  98. array('name' => 'pear-pear.doctrine-project.org/DoctrineORM', 'version' => '2.2.2'),
  99. ),
  100. ),
  101. array(
  102. 'pear.symfony-project.com',
  103. array(
  104. array('name' => 'pear-pear.symfony-project.com/YAML', 'version' => '1.0.6'),
  105. ),
  106. ),
  107. array(
  108. 'pear.pirum-project.org',
  109. array(
  110. array('name' => 'pear-pear.pirum-project.org/Pirum', 'version' => '1.1.4'),
  111. ),
  112. ),
  113. );
  114. }
  115. private function createRepository($repoConfig)
  116. {
  117. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  118. ->getMock();
  119. $config = new \Composer\Config();
  120. $this->remoteFilesystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')
  121. ->disableOriginalConstructor()
  122. ->getMock();
  123. $this->repository = new PearRepository($repoConfig, $ioInterface, $config, null);
  124. }
  125. protected function tearDown()
  126. {
  127. $this->repository = null;
  128. $this->remoteFilesystem = null;
  129. }
  130. }