PathRepositoryTest.php 4.5 KB

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