From beff1f5cc113dd645d74686b567f15ac7ff958b4 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Tue, 18 Feb 2014 23:28:45 +0100 Subject: [PATCH] This should create relative/absolute dist URLs depending on the way (relative/absolute) the artifact directory path was given. --- .../Repository/ArtifactRepository.php | 2 +- .../Repository/ArtifactRepositoryTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Composer/Repository/ArtifactRepository.php b/src/Composer/Repository/ArtifactRepository.php index 869e4757f..6c87361c0 100644 --- a/src/Composer/Repository/ArtifactRepository.php +++ b/src/Composer/Repository/ArtifactRepository.php @@ -96,7 +96,7 @@ class ArtifactRepository extends ArrayRepository $package = JsonFile::parseJson($json, $composerFile); $package['dist'] = array( 'type' => 'zip', - 'url' => $file->getRealPath(), + 'url' => $file->getPathname(), 'reference' => $file->getBasename(), 'shasum' => sha1_file($file->getRealPath()) ); diff --git a/tests/Composer/Test/Repository/ArtifactRepositoryTest.php b/tests/Composer/Test/Repository/ArtifactRepositoryTest.php index 109b53bfb..65aeb1a76 100644 --- a/tests/Composer/Test/Repository/ArtifactRepositoryTest.php +++ b/tests/Composer/Test/Repository/ArtifactRepositoryTest.php @@ -16,6 +16,7 @@ use Composer\TestCase; use Composer\IO\NullIO; use Composer\Config; use Composer\Package\BasePackage; +use Composer\Util\Filesystem; class ArtifactRepositoryTest extends TestCase { @@ -40,4 +41,27 @@ class ArtifactRepositoryTest extends TestCase $this->assertSame($expectedPackages, $foundPackages); } + + public function testAbsoluteRepoUrlCreatesAbsoluteUrlPackages() + { + $absolutePath = __DIR__ . '/Fixtures/artifacts'; + $coordinates = array('type' => 'artifact', 'url' => $absolutePath); + $repo = new ArtifactRepository($coordinates, new NullIO(), new Config()); + + foreach ($repo->getPackages() as $package) { + $this->assertTrue(strpos($package->getDistUrl(), $absolutePath) === 0); + } + } + + public function testRelativeRepoUrlCreatesRelativeUrlPackages() + { + $relativePath = 'tests/Composer/Test/Repository/Fixtures/artifacts'; + $coordinates = array('type' => 'artifact', 'url' => $relativePath); + $repo = new ArtifactRepository($coordinates, new NullIO(), new Config()); + + foreach ($repo->getPackages() as $package) { + $this->assertTrue(strpos($package->getDistUrl(), $relativePath) === 0); + } + } + }