1
0
Fork 0
composer/tests/Composer/Test/Repository/PathRepositoryTest.php

131 lines
4.5 KiB
PHP
Raw Normal View History

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.
*/
namespace Composer\Test\Repository;
2015-08-25 21:06:48 +00:00
use Composer\Package\Loader\ArrayLoader;
use Composer\Repository\PathRepository;
use Composer\Test\TestCase;
use Composer\Package\Version\VersionParser;
2015-08-25 21:06:48 +00:00
class PathRepositoryTest extends TestCase
{
/**
* @expectedException RuntimeException
*/
public function testLoadPackageFromFileSystemWithIncorrectPath()
{
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
->getMock();
$config = new \Composer\Config();
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'missing'));
$repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
$repository->getPackages();
}
2015-08-25 21:06:48 +00:00
public function testLoadPackageFromFileSystemWithVersion()
{
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
->getMock();
$config = new \Composer\Config();
$versionGuesser = null;
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-version'));
$repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
2015-08-25 21:06:48 +00:00
$repository->getPackages();
2020-03-19 13:27:23 +00:00
$this->assertSame(1, $repository->count());
$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();
$versionGuesser = null;
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'without-version'));
$repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
2015-08-25 21:06:48 +00:00
$packages = $repository->getPackages();
2020-03-19 13:27:23 +00:00
$this->assertGreaterThanOrEqual(1, $repository->count());
2015-08-25 21:06:48 +00:00
$package = $packages[0];
2020-03-19 13:27:23 +00:00
$this->assertSame('test/path-unversioned', $package->getName());
2015-08-25 21:06:48 +00:00
$packageVersion = $package->getVersion();
2017-12-03 04:41:58 +00:00
$this->assertNotEmpty($packageVersion);
2015-08-25 21:06:48 +00:00
}
public function testLoadPackageFromFileSystemWithWildcard()
{
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
->getMock();
$config = new \Composer\Config();
$versionGuesser = null;
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
$repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
$packages = $repository->getPackages();
$names = array();
2020-03-19 13:27:23 +00:00
$this->assertGreaterThanOrEqual(2, $repository->count());
$package = $packages[0];
$names[] = $package->getName();
2020-03-13 12:33:54 +00:00
$package = $packages[count($packages) - 1];
$names[] = $package->getName();
sort($names);
2020-03-19 13:27:23 +00:00
$this->assertSame(array('test/path-unversioned', 'test/path-versioned'), $names);
}
/**
* Verify relative repository URLs remain relative, see #4439
*/
public function testUrlRemainsRelative()
{
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
->getMock();
$config = new \Composer\Config();
$versionGuesser = null;
2016-12-23 18:57:00 +00:00
// realpath() does not fully expand the paths
// PHP Bug https://bugs.php.net/bug.php?id=72642
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(realpath(realpath(__DIR__)), 'Fixtures', 'path', 'with-version'));
// getcwd() not necessarily match __DIR__
// PHP Bug https://bugs.php.net/bug.php?id=73797
$relativeUrl = ltrim(substr($repositoryUrl, strlen(realpath(realpath(getcwd())))), DIRECTORY_SEPARATOR);
$repository = new PathRepository(array('url' => $relativeUrl), $ioInterface, $config);
$packages = $repository->getPackages();
2020-03-19 13:27:23 +00:00
$this->assertSame(1, $repository->count());
$package = $packages[0];
2020-03-19 13:27:23 +00:00
$this->assertSame('test/path-versioned', $package->getName());
// Convert platform specific separators back to generic URL slashes
$relativeUrl = str_replace(DIRECTORY_SEPARATOR, '/', $relativeUrl);
2020-03-19 13:27:23 +00:00
$this->assertSame($relativeUrl, $package->getDistUrl());
}
2015-08-25 21:06:48 +00:00
}