1
0
Fork 0

Added repository tests

pull/4365/head
Samuel ROZE 2015-08-25 22:06:48 +01:00
parent bb81e3721a
commit 6c16153302
4 changed files with 77 additions and 4 deletions

View File

@ -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);
}
/**

View File

@ -0,0 +1,4 @@
{
"name": "test/path",
"version": "0.0.2"
}

View File

@ -0,0 +1,3 @@
{
"name": "test/path"
}

View File

@ -0,0 +1,62 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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));
}
}