PathRepositoryTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\Repository;
  12. use Composer\Package\Loader\ArrayLoader;
  13. use Composer\Semver\VersionParser;
  14. use Composer\TestCase;
  15. class PathRepositoryTest extends TestCase
  16. {
  17. public function testLoadPackageFromFileSystemWithVersion()
  18. {
  19. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  20. ->getMock();
  21. $config = new \Composer\Config();
  22. $loader = new ArrayLoader(new VersionParser());
  23. $versionGuesser = null;
  24. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-version'));
  25. $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config, $loader);
  26. $repository->getPackages();
  27. $this->assertEquals(1, $repository->count());
  28. $this->assertTrue($repository->hasPackage($this->getPackage('test/path-versioned', '0.0.2')));
  29. }
  30. public function testLoadPackageFromFileSystemWithoutVersion()
  31. {
  32. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  33. ->getMock();
  34. $config = new \Composer\Config();
  35. $loader = new ArrayLoader(new VersionParser());
  36. $versionGuesser = null;
  37. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'without-version'));
  38. $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config, $loader);
  39. $packages = $repository->getPackages();
  40. $this->assertEquals(1, $repository->count());
  41. $package = $packages[0];
  42. $this->assertEquals('test/path-unversioned', $package->getName());
  43. $packageVersion = $package->getVersion();
  44. $this->assertTrue(!empty($packageVersion));
  45. }
  46. public function testLoadPackageFromFileSystemWithWildcard()
  47. {
  48. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  49. ->getMock();
  50. $config = new \Composer\Config();
  51. $loader = new ArrayLoader(new VersionParser());
  52. $versionGuesser = null;
  53. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
  54. $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config, $loader);
  55. $packages = $repository->getPackages();
  56. $names = array();
  57. $this->assertEquals(2, $repository->count());
  58. $package = $packages[0];
  59. $names[] = $package->getName();
  60. $package = $packages[1];
  61. $names[] = $package->getName();
  62. sort($names);
  63. $this->assertEquals(array('test/path-unversioned', 'test/path-versioned'), $names);
  64. }
  65. /**
  66. * Verify relative repository URLs remain relative, see #4439
  67. */
  68. public function testUrlRemainsRelative()
  69. {
  70. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  71. ->getMock();
  72. $config = new \Composer\Config();
  73. $loader = new ArrayLoader(new VersionParser());
  74. $versionGuesser = null;
  75. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-version'));
  76. $relativeUrl = ltrim(substr($repositoryUrl, strlen(getcwd())), DIRECTORY_SEPARATOR);
  77. $repository = new PathRepository(array('url' => $relativeUrl), $ioInterface, $config, $loader);
  78. $packages = $repository->getPackages();
  79. $this->assertEquals(1, $repository->count());
  80. $package = $packages[0];
  81. $this->assertEquals('test/path-versioned', $package->getName());
  82. // Convert platform specific separators back to generic URL slashes
  83. $relativeUrl = str_replace(DIRECTORY_SEPARATOR, '/', $relativeUrl);
  84. $this->assertEquals(rtrim($relativeUrl, '/'), rtrim($package->getDistUrl(), '/'));
  85. }
  86. }