2015-08-25 21:06:48 +00:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
namespace Composer\Test\Repository;
|
2015-08-25 21:06:48 +00:00
|
|
|
|
|
|
|
use Composer\Package\Loader\ArrayLoader;
|
2016-10-05 08:45:22 +00:00
|
|
|
use Composer\Repository\PathRepository;
|
2015-09-24 14:32:36 +00:00
|
|
|
use Composer\Semver\VersionParser;
|
2015-08-25 21:06:48 +00:00
|
|
|
use Composer\TestCase;
|
|
|
|
|
|
|
|
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());
|
2015-09-15 14:41:07 +00:00
|
|
|
$this->assertTrue($repository->hasPackage($this->getPackage('test/path-versioned', '0.0.2')));
|
2015-08-25 21:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
2015-09-15 14:41:07 +00:00
|
|
|
$this->assertEquals('test/path-unversioned', $package->getName());
|
2015-08-25 21:06:48 +00:00
|
|
|
|
|
|
|
$packageVersion = $package->getVersion();
|
|
|
|
$this->assertTrue(!empty($packageVersion));
|
|
|
|
}
|
2015-09-15 14:41:07 +00:00
|
|
|
|
|
|
|
public function testLoadPackageFromFileSystemWithWildcard()
|
|
|
|
{
|
|
|
|
$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', '*'));
|
|
|
|
$repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config, $loader);
|
|
|
|
$packages = $repository->getPackages();
|
2016-02-12 16:02:19 +00:00
|
|
|
$names = array();
|
2015-09-15 14:41:07 +00:00
|
|
|
|
|
|
|
$this->assertEquals(2, $repository->count());
|
|
|
|
|
|
|
|
$package = $packages[0];
|
2016-02-12 16:02:19 +00:00
|
|
|
$names[] = $package->getName();
|
2015-09-15 14:41:07 +00:00
|
|
|
|
|
|
|
$package = $packages[1];
|
2016-02-12 16:02:19 +00:00
|
|
|
$names[] = $package->getName();
|
|
|
|
|
|
|
|
sort($names);
|
|
|
|
$this->assertEquals(array('test/path-unversioned', 'test/path-versioned'), $names);
|
2015-09-15 14:41:07 +00:00
|
|
|
}
|
2015-09-23 16:15:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify relative repository URLs remain relative, see #4439
|
|
|
|
*/
|
|
|
|
public function testUrlRemainsRelative()
|
|
|
|
{
|
|
|
|
$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'));
|
|
|
|
$relativeUrl = ltrim(substr($repositoryUrl, strlen(getcwd())), DIRECTORY_SEPARATOR);
|
|
|
|
|
|
|
|
$repository = new PathRepository(array('url' => $relativeUrl), $ioInterface, $config, $loader);
|
|
|
|
$packages = $repository->getPackages();
|
|
|
|
|
|
|
|
$this->assertEquals(1, $repository->count());
|
|
|
|
|
|
|
|
$package = $packages[0];
|
|
|
|
$this->assertEquals('test/path-versioned', $package->getName());
|
2016-01-26 08:08:57 +00:00
|
|
|
|
|
|
|
// Convert platform specific separators back to generic URL slashes
|
|
|
|
$relativeUrl = str_replace(DIRECTORY_SEPARATOR, '/', $relativeUrl);
|
2016-04-11 12:11:46 +00:00
|
|
|
$this->assertEquals($relativeUrl, $package->getDistUrl());
|
2015-09-23 16:15:43 +00:00
|
|
|
}
|
2015-08-25 21:06:48 +00:00
|
|
|
}
|