mirror of
https://github.com/composer/composer
synced 2025-05-10 17:12:51 +00:00
Added repository tests
This commit is contained in:
parent
bb81e3721a
commit
6c16153302
4 changed files with 77 additions and 4 deletions
|
@ -16,6 +16,7 @@ use Composer\Config;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
use Composer\Package\Loader\ArrayLoader;
|
use Composer\Package\Loader\ArrayLoader;
|
||||||
|
use Composer\Package\Loader\LoaderInterface;
|
||||||
use Composer\Package\Version\VersionGuesser;
|
use Composer\Package\Version\VersionGuesser;
|
||||||
use Composer\Package\Version\VersionParser;
|
use Composer\Package\Version\VersionParser;
|
||||||
use Composer\Util\ProcessExecutor;
|
use Composer\Util\ProcessExecutor;
|
||||||
|
@ -83,19 +84,22 @@ class PathRepository extends ArrayRepository
|
||||||
* @param array $packageConfig
|
* @param array $packageConfig
|
||||||
* @param IOInterface $io
|
* @param IOInterface $io
|
||||||
* @param Config $config
|
* @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'])) {
|
if (!isset($packageConfig['url'])) {
|
||||||
throw new \RuntimeException('You must specify the `url` configuration for the path repository');
|
throw new \RuntimeException('You must specify the `url` configuration for the path repository');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fileSystem = new Filesystem();
|
$this->fileSystem = $filesystem ?: new Filesystem();
|
||||||
$this->loader = new ArrayLoader();
|
$this->loader = $loader ?: new ArrayLoader();
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->packageConfig = $packageConfig;
|
$this->packageConfig = $packageConfig;
|
||||||
$this->path = realpath(rtrim($packageConfig['url'], '/')) . '/';
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"name": "test/path",
|
||||||
|
"version": "0.0.2"
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"name": "test/path"
|
||||||
|
}
|
62
tests/Composer/Test/Repository/PathRepositoryTest.php
Normal file
62
tests/Composer/Test/Repository/PathRepositoryTest.php
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue