PathRepositoryTest.php 4.0 KB

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