2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2015-08-25 21:06:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
use Composer\Repository\PathRepository;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2022-04-28 19:20:40 +00:00
|
|
|
use Composer\Util\HttpDownloader;
|
|
|
|
use Composer\Util\Loop;
|
2022-02-22 15:47:09 +00:00
|
|
|
use Composer\Util\Platform;
|
2022-04-28 19:20:40 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
2015-08-25 21:06:48 +00:00
|
|
|
|
|
|
|
class PathRepositoryTest extends TestCase
|
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testLoadPackageFromFileSystemWithIncorrectPath(): void
|
2019-10-08 14:48:04 +00:00
|
|
|
{
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('RuntimeException');
|
2019-10-08 14:48:04 +00:00
|
|
|
|
|
|
|
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'missing'));
|
2022-04-28 19:20:40 +00:00
|
|
|
$repository = $this->createPathRepo(array('url' => $repositoryUrl));
|
2019-10-08 14:48:04 +00:00
|
|
|
$repository->getPackages();
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testLoadPackageFromFileSystemWithVersion(): void
|
2015-08-25 21:06:48 +00:00
|
|
|
{
|
|
|
|
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-version'));
|
2022-04-28 19:20:40 +00:00
|
|
|
$repository = $this->createPathRepo(array('url' => $repositoryUrl));
|
2015-08-25 21:06:48 +00:00
|
|
|
$repository->getPackages();
|
|
|
|
|
2020-03-19 13:27:23 +00:00
|
|
|
$this->assertSame(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
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testLoadPackageFromFileSystemWithoutVersion(): void
|
2015-08-25 21:06:48 +00:00
|
|
|
{
|
|
|
|
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'without-version'));
|
2022-04-28 19:20:40 +00:00
|
|
|
$repository = $this->createPathRepo(array('url' => $repositoryUrl));
|
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
|
|
|
}
|
2015-09-15 14:41:07 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testLoadPackageFromFileSystemWithWildcard(): void
|
2020-10-08 10:33:16 +00:00
|
|
|
{
|
2015-09-15 14:41:07 +00:00
|
|
|
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
|
2022-04-28 19:20:40 +00:00
|
|
|
$repository = $this->createPathRepo(array('url' => $repositoryUrl));
|
2020-10-08 10:33:16 +00:00
|
|
|
$packages = $repository->getPackages();
|
2016-02-12 16:02:19 +00:00
|
|
|
$names = array();
|
2015-09-15 14:41:07 +00:00
|
|
|
|
2021-02-17 22:43:35 +00:00
|
|
|
$this->assertGreaterThanOrEqual(2, $repository->count());
|
2015-09-15 14:41:07 +00:00
|
|
|
|
|
|
|
$package = $packages[0];
|
2016-02-12 16:02:19 +00:00
|
|
|
$names[] = $package->getName();
|
2020-10-08 10:33:16 +00:00
|
|
|
|
2015-09-15 14:41:07 +00:00
|
|
|
$package = $packages[1];
|
2016-02-12 16:02:19 +00:00
|
|
|
$names[] = $package->getName();
|
2020-10-08 10:33:16 +00:00
|
|
|
|
2016-02-12 16:02:19 +00:00
|
|
|
sort($names);
|
2021-01-27 13:03:44 +00:00
|
|
|
$this->assertEquals(array('test/path-unversioned', 'test/path-versioned'), $names);
|
2020-10-08 10:33:16 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testLoadPackageWithExplicitVersions(): void
|
2015-09-15 14:41:07 +00:00
|
|
|
{
|
2021-01-21 19:39:55 +00:00
|
|
|
$options = array(
|
|
|
|
'versions' => array(
|
|
|
|
'test/path-unversioned' => '4.3.2.1',
|
|
|
|
'test/path-versioned' => '3.2.1.0',
|
|
|
|
),
|
|
|
|
);
|
2015-09-15 14:41:07 +00:00
|
|
|
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
|
2022-04-28 19:20:40 +00:00
|
|
|
$repository = $this->createPathRepo(array('url' => $repositoryUrl, 'options' => $options));
|
2015-09-15 14:41:07 +00:00
|
|
|
$packages = $repository->getPackages();
|
|
|
|
|
2021-01-21 19:39:55 +00:00
|
|
|
$versions = array();
|
|
|
|
|
|
|
|
$this->assertEquals(2, $repository->count());
|
|
|
|
|
|
|
|
$package = $packages[0];
|
|
|
|
$versions[$package->getName()] = $package->getVersion();
|
2015-09-15 14:41:07 +00:00
|
|
|
|
2021-01-21 19:39:55 +00:00
|
|
|
$package = $packages[1];
|
|
|
|
$versions[$package->getName()] = $package->getVersion();
|
2020-10-08 10:33:16 +00:00
|
|
|
|
2021-01-21 19:39:55 +00:00
|
|
|
ksort($versions);
|
|
|
|
$this->assertSame(array('test/path-unversioned' => '4.3.2.1', 'test/path-versioned' => '3.2.1.0'), $versions);
|
2015-09-15 14:41:07 +00:00
|
|
|
}
|
2015-09-23 16:15:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify relative repository URLs remain relative, see #4439
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUrlRemainsRelative(): void
|
2015-09-23 16:15:43 +00:00
|
|
|
{
|
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
|
2022-02-22 15:47:09 +00:00
|
|
|
$relativeUrl = ltrim(substr($repositoryUrl, strlen(realpath(realpath(Platform::getCwd())))), DIRECTORY_SEPARATOR);
|
2015-09-23 16:15:43 +00:00
|
|
|
|
2022-04-28 19:20:40 +00:00
|
|
|
$repository = $this->createPathRepo(array('url' => $relativeUrl));
|
2015-09-23 16:15:43 +00:00
|
|
|
$packages = $repository->getPackages();
|
|
|
|
|
2020-03-19 13:27:23 +00:00
|
|
|
$this->assertSame(1, $repository->count());
|
2015-09-23 16:15:43 +00:00
|
|
|
|
|
|
|
$package = $packages[0];
|
2020-03-19 13:27:23 +00:00
|
|
|
$this->assertSame('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);
|
2020-03-19 13:27:23 +00:00
|
|
|
$this->assertSame($relativeUrl, $package->getDistUrl());
|
2015-09-23 16:15:43 +00:00
|
|
|
}
|
2022-02-07 12:54:17 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testReferenceNone(): void
|
2022-02-07 12:54:17 +00:00
|
|
|
{
|
|
|
|
$options = array(
|
|
|
|
'reference' => 'none',
|
|
|
|
);
|
|
|
|
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
|
2022-04-28 19:20:40 +00:00
|
|
|
$repository = $this->createPathRepo(array('url' => $repositoryUrl, 'options' => $options));
|
2022-02-07 12:54:17 +00:00
|
|
|
$packages = $repository->getPackages();
|
|
|
|
|
|
|
|
$this->assertGreaterThanOrEqual(2, $repository->count());
|
|
|
|
|
|
|
|
foreach ($packages as $package) {
|
|
|
|
$this->assertEquals($package->getDistReference(), null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testReferenceConfig(): void
|
2022-02-07 12:54:17 +00:00
|
|
|
{
|
|
|
|
$options = array(
|
|
|
|
'reference' => 'config',
|
|
|
|
'relative' => true,
|
|
|
|
);
|
|
|
|
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
|
2022-04-28 19:20:40 +00:00
|
|
|
$repository = $this->createPathRepo(array('url' => $repositoryUrl, 'options' => $options));
|
2022-02-07 12:54:17 +00:00
|
|
|
$packages = $repository->getPackages();
|
|
|
|
|
|
|
|
$this->assertGreaterThanOrEqual(2, $repository->count());
|
|
|
|
|
|
|
|
foreach ($packages as $package) {
|
|
|
|
$this->assertEquals(
|
|
|
|
$package->getDistReference(),
|
|
|
|
sha1(file_get_contents($package->getDistUrl() . '/composer.json') . serialize($options))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 19:20:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<mixed> $options
|
|
|
|
*/
|
|
|
|
private function createPathRepo(array $options): PathRepository
|
|
|
|
{
|
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
|
|
|
|
|
|
|
$config = new \Composer\Config();
|
|
|
|
$proc = new ProcessExecutor();
|
|
|
|
$loop = new Loop(new HttpDownloader($io, $config), $proc);
|
|
|
|
|
|
|
|
|
|
|
|
return new PathRepository($options, $io, $config, null, null, $proc);
|
|
|
|
}
|
2015-08-25 21:06:48 +00:00
|
|
|
}
|