diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index cdadbb518..a907c5adb 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -16,6 +16,7 @@ use Composer\Config; use Composer\IO\IOInterface; use Composer\Json\JsonFile; use Composer\Package\Loader\ArrayLoader; +use Composer\Package\Loader\LoaderInterface; use Composer\Package\Version\VersionGuesser; use Composer\Package\Version\VersionParser; use Composer\Util\ProcessExecutor; @@ -83,19 +84,22 @@ class PathRepository extends ArrayRepository * @param array $packageConfig * @param IOInterface $io * @param Config $config + * @param LoaderInterface $loader + * @param Filesystem $filesystem + * @param VersionGuesser $versionGuesser */ - public function __construct(array $packageConfig, IOInterface $io, Config $config) + public function __construct(array $packageConfig, IOInterface $io, Config $config, LoaderInterface $loader = null, Filesystem $filesystem = null, VersionGuesser $versionGuesser = null) { if (!isset($packageConfig['url'])) { throw new \RuntimeException('You must specify the `url` configuration for the path repository'); } - $this->fileSystem = new Filesystem(); - $this->loader = new ArrayLoader(); + $this->fileSystem = $filesystem ?: new Filesystem(); + $this->loader = $loader ?: new ArrayLoader(); $this->config = $config; $this->packageConfig = $packageConfig; $this->path = realpath(rtrim($packageConfig['url'], '/')) . '/'; - $this->versionGuesser = new VersionGuesser(new ProcessExecutor($io), new VersionParser(), $this->path); + $this->versionGuesser = $versionGuesser ?: new VersionGuesser(new ProcessExecutor($io), new VersionParser(), $this->path); } /** diff --git a/tests/Composer/Test/Repository/Fixtures/path/with-version/composer.json b/tests/Composer/Test/Repository/Fixtures/path/with-version/composer.json new file mode 100644 index 000000000..fa853d690 --- /dev/null +++ b/tests/Composer/Test/Repository/Fixtures/path/with-version/composer.json @@ -0,0 +1,4 @@ +{ + "name": "test/path", + "version": "0.0.2" +} \ No newline at end of file diff --git a/tests/Composer/Test/Repository/Fixtures/path/without-version/composer.json b/tests/Composer/Test/Repository/Fixtures/path/without-version/composer.json new file mode 100644 index 000000000..2fcbad12a --- /dev/null +++ b/tests/Composer/Test/Repository/Fixtures/path/without-version/composer.json @@ -0,0 +1,3 @@ +{ + "name": "test/path" +} \ No newline at end of file diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php new file mode 100644 index 000000000..fb64e458b --- /dev/null +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -0,0 +1,62 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Repository; + +use Composer\Package\Loader\ArrayLoader; +use Composer\Package\Version\VersionParser; +use Composer\TestCase; +use Composer\IO\NullIO; +use Composer\Config; +use Composer\Package\BasePackage; + +class PathRepositoryTest extends TestCase +{ + public function testLoadPackageFromFileSystemWithVersion() + { + $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') + ->getMock(); + + $config = new \Composer\Config(); + $loader = new ArrayLoader(new VersionParser()); + $versionGuesser = null; + + $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-version')); + $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config, $loader); + $repository->getPackages(); + + $this->assertEquals(1, $repository->count()); + $this->assertTrue($repository->hasPackage($this->getPackage('test/path', '0.0.2'))); + } + + public function testLoadPackageFromFileSystemWithoutVersion() + { + $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') + ->getMock(); + + $config = new \Composer\Config(); + $loader = new ArrayLoader(new VersionParser()); + $versionGuesser = null; + + $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'without-version')); + $repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config, $loader); + $packages = $repository->getPackages(); + + $this->assertEquals(1, $repository->count()); + + $package = $packages[0]; + $this->assertEquals('test/path', $package->getName()); + + $packageVersion = $package->getVersion(); + $this->assertTrue(!empty($packageVersion)); + } +}