PathRepositoryTest.php 4.2 KB

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