PathRepositoryTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. $this->assertEquals(2, $repository->count());
  57. $package = $packages[0];
  58. $this->assertEquals('test/path-versioned', $package->getName());
  59. $package = $packages[1];
  60. $this->assertEquals('test/path-unversioned', $package->getName());
  61. }
  62. /**
  63. * Verify relative repository URLs remain relative, see #4439
  64. */
  65. public function testUrlRemainsRelative()
  66. {
  67. $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
  68. ->getMock();
  69. $config = new \Composer\Config();
  70. $loader = new ArrayLoader(new VersionParser());
  71. $versionGuesser = null;
  72. $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-version'));
  73. $relativeUrl = ltrim(substr($repositoryUrl, strlen(getcwd())), DIRECTORY_SEPARATOR);
  74. $repository = new PathRepository(array('url' => $relativeUrl), $ioInterface, $config, $loader);
  75. $packages = $repository->getPackages();
  76. $this->assertEquals(1, $repository->count());
  77. $package = $packages[0];
  78. $this->assertEquals('test/path-versioned', $package->getName());
  79. $this->assertEquals(rtrim($relativeUrl, DIRECTORY_SEPARATOR), rtrim($package->getDistUrl(), DIRECTORY_SEPARATOR));
  80. }
  81. }