PathRepositoryTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\Package\Loader\ArrayLoader;
  13. use Composer\Repository\PathRepository;
  14. use Composer\Semver\VersionParser;
  15. use Composer\Test\TestCase;
  16. class PathRepositoryTest extends TestCase
  17. {
  18. /**
  19. * @expectedException RuntimeException
  20. */
  21. public function testLoadPackageFromFileSystemWithIncorrectPath()
  22. {
  23. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  24. ->getMock();
  25. $config = new \Composer\Config();
  26. $versionGuesser = null;
  27. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'missing'));
  28. $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
  29. $repository->getPackages();
  30. }
  31. public function testLoadPackageFromFileSystemWithVersion()
  32. {
  33. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  34. ->getMock();
  35. $config = new \Composer\Config();
  36. $versionGuesser = null;
  37. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-version'));
  38. $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
  39. $repository->getPackages();
  40. $this->assertEquals(1, $repository->count());
  41. $this->assertTrue($repository->hasPackage($this->getPackage('test/path-versioned', '0.0.2')));
  42. }
  43. public function testLoadPackageFromFileSystemWithoutVersion()
  44. {
  45. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  46. ->getMock();
  47. $config = new \Composer\Config();
  48. $versionGuesser = null;
  49. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'without-version'));
  50. $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
  51. $packages = $repository->getPackages();
  52. $this->assertEquals(1, $repository->count());
  53. $package = $packages[0];
  54. $this->assertEquals('test/path-unversioned', $package->getName());
  55. $packageVersion = $package->getVersion();
  56. $this->assertNotEmpty($packageVersion);
  57. }
  58. public function testLoadPackageFromFileSystemWithWildcard()
  59. {
  60. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  61. ->getMock();
  62. $config = new \Composer\Config();
  63. $versionGuesser = null;
  64. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
  65. $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
  66. $packages = $repository->getPackages();
  67. $names = array();
  68. $this->assertEquals(2, $repository->count());
  69. $package = $packages[0];
  70. $names[] = $package->getName();
  71. $package = $packages[1];
  72. $names[] = $package->getName();
  73. sort($names);
  74. $this->assertEquals(array('test/path-unversioned', 'test/path-versioned'), $names);
  75. }
  76. /**
  77. * Verify relative repository URLs remain relative, see #4439
  78. */
  79. public function testUrlRemainsRelative()
  80. {
  81. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  82. ->getMock();
  83. $config = new \Composer\Config();
  84. $versionGuesser = null;
  85. // realpath() does not fully expand the paths
  86. // PHP Bug https://bugs.php.net/bug.php?id=72642
  87. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(realpath(realpath(__DIR__)), 'Fixtures', 'path', 'with-version'));
  88. // getcwd() not necessarily match __DIR__
  89. // PHP Bug https://bugs.php.net/bug.php?id=73797
  90. $relativeUrl = ltrim(substr($repositoryUrl, strlen(realpath(realpath(getcwd())))), DIRECTORY_SEPARATOR);
  91. $repository = new PathRepository(array('url' => $relativeUrl), $ioInterface, $config);
  92. $packages = $repository->getPackages();
  93. $this->assertEquals(1, $repository->count());
  94. $package = $packages[0];
  95. $this->assertEquals('test/path-versioned', $package->getName());
  96. // Convert platform specific separators back to generic URL slashes
  97. $relativeUrl = str_replace(DIRECTORY_SEPARATOR, '/', $relativeUrl);
  98. $this->assertEquals($relativeUrl, $package->getDistUrl());
  99. }
  100. }