2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2012-05-31 15:21:56 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Package\Loader;
|
|
|
|
|
2012-06-23 10:55:05 +00:00
|
|
|
use Composer\Config;
|
2012-05-31 15:21:56 +00:00
|
|
|
use Composer\Package\Loader\RootPackageLoader;
|
2013-07-28 17:40:09 +00:00
|
|
|
use Composer\Package\BasePackage;
|
2021-11-01 20:44:12 +00:00
|
|
|
use Composer\Package\RootAliasPackage;
|
2020-10-25 21:22:19 +00:00
|
|
|
use Composer\Package\RootPackage;
|
2015-08-18 13:58:18 +00:00
|
|
|
use Composer\Package\Version\VersionGuesser;
|
2015-09-24 14:32:36 +00:00
|
|
|
use Composer\Semver\VersionParser;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\TestCase;
|
2022-03-17 13:52:14 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
2012-05-31 15:21:56 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class RootPackageLoaderTest extends TestCase
|
2012-05-31 15:21:56 +00:00
|
|
|
{
|
2021-11-01 20:44:12 +00:00
|
|
|
/**
|
|
|
|
* @param array<string, mixed> $data
|
|
|
|
*
|
|
|
|
* @return RootPackage|RootAliasPackage
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
protected function loadPackage(array $data): \Composer\Package\PackageInterface
|
2012-05-31 15:21:56 +00:00
|
|
|
{
|
2021-08-19 11:00:30 +00:00
|
|
|
$manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')
|
2012-05-31 15:21:56 +00:00
|
|
|
->disableOriginalConstructor()
|
2015-08-18 13:58:18 +00:00
|
|
|
->getMock();
|
2012-05-31 15:21:56 +00:00
|
|
|
|
2012-06-24 11:03:55 +00:00
|
|
|
$config = new Config;
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['repositories' => ['packagist' => false]]);
|
2022-03-17 13:52:14 +00:00
|
|
|
$processExecutor = new ProcessExecutor();
|
|
|
|
$processExecutor->enableAsync();
|
|
|
|
$guesser = new VersionGuesser($config, $processExecutor, new VersionParser());
|
2013-05-21 11:14:34 +00:00
|
|
|
|
2022-03-17 13:52:14 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config, null, $guesser);
|
2013-05-21 11:14:34 +00:00
|
|
|
|
2015-08-18 13:58:18 +00:00
|
|
|
return $loader->load($data);
|
2013-05-21 11:14:34 +00:00
|
|
|
}
|
2013-08-12 00:33:18 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testStabilityFlagsParsing(): void
|
2013-08-12 08:27:25 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$package = $this->loadPackage([
|
|
|
|
'require' => [
|
2015-08-18 13:58:18 +00:00
|
|
|
'foo/bar' => '~2.1.0-beta2',
|
|
|
|
'bar/baz' => '1.0.x-dev as 1.2.0',
|
|
|
|
'qux/quux' => '1.0.*@rc',
|
2015-09-28 09:51:14 +00:00
|
|
|
'zux/complex' => '~1.0,>=1.0.2@dev',
|
2015-10-27 14:59:48 +00:00
|
|
|
'or/op' => '^2.0@dev || ^2.0@dev',
|
|
|
|
'multi/lowest-wins' => '^2.0@rc || >=3.0@dev , ~3.5@alpha',
|
2020-03-11 08:34:40 +00:00
|
|
|
'or/op-without-flags' => 'dev-master || 2.0 , ~3.5-alpha',
|
|
|
|
'or/op-without-flags2' => '3.0-beta || 2.0 , ~3.5-alpha',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2015-08-18 13:58:18 +00:00
|
|
|
'minimum-stability' => 'alpha',
|
2022-08-17 12:20:07 +00:00
|
|
|
]);
|
2013-08-12 08:27:25 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('alpha', $package->getMinimumStability());
|
|
|
|
self::assertEquals([
|
2015-08-18 13:58:18 +00:00
|
|
|
'bar/baz' => BasePackage::STABILITY_DEV,
|
|
|
|
'qux/quux' => BasePackage::STABILITY_RC,
|
|
|
|
'zux/complex' => BasePackage::STABILITY_DEV,
|
2015-10-27 14:59:48 +00:00
|
|
|
'or/op' => BasePackage::STABILITY_DEV,
|
|
|
|
'multi/lowest-wins' => BasePackage::STABILITY_DEV,
|
2020-03-11 08:34:40 +00:00
|
|
|
'or/op-without-flags' => BasePackage::STABILITY_DEV,
|
|
|
|
'or/op-without-flags2' => BasePackage::STABILITY_ALPHA,
|
2022-08-17 12:20:07 +00:00
|
|
|
], $package->getStabilityFlags());
|
2013-08-12 08:27:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testNoVersionIsVisibleInPrettyVersion(): void
|
2015-06-18 22:47:17 +00:00
|
|
|
{
|
2021-08-19 11:00:30 +00:00
|
|
|
$manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')
|
2015-06-18 22:47:17 +00:00
|
|
|
->disableOriginalConstructor()
|
2015-07-30 11:37:12 +00:00
|
|
|
->getMock()
|
|
|
|
;
|
2015-06-18 22:47:17 +00:00
|
|
|
|
|
|
|
$config = new Config;
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['repositories' => ['packagist' => false]]);
|
2021-12-09 16:09:07 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $process = $this->getProcessExecutorMock(), new VersionParser()));
|
2022-08-17 12:20:07 +00:00
|
|
|
$process->expects([], false, ['return' => 1]);
|
2021-08-19 11:00:30 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$package = $loader->load([]);
|
2015-06-18 22:47:17 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals("1.0.0.0", $package->getVersion());
|
|
|
|
self::assertEquals(RootPackage::DEFAULT_PRETTY_VERSION, $package->getPrettyVersion());
|
2015-06-18 22:47:17 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPrettyVersionForRootPackageInVersionBranch(): void
|
2017-11-30 14:07:08 +00:00
|
|
|
{
|
|
|
|
// see #6845
|
2021-12-10 11:57:08 +00:00
|
|
|
$manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')->disableOriginalConstructor()->getMock();
|
|
|
|
$versionGuesser = $this->getMockBuilder('Composer\\Package\\Version\\VersionGuesser')->disableOriginalConstructor()->getMock();
|
|
|
|
$versionGuesser->expects($this->atLeastOnce())
|
|
|
|
->method('guessVersion')
|
2022-08-17 12:20:07 +00:00
|
|
|
->willReturn([
|
2017-11-30 14:07:08 +00:00
|
|
|
'name' => 'A',
|
|
|
|
'version' => '3.0.9999999.9999999-dev',
|
|
|
|
'pretty_version' => '3.0-dev',
|
|
|
|
'commit' => 'aabbccddee',
|
2022-08-17 12:20:07 +00:00
|
|
|
]);
|
2017-11-30 14:07:08 +00:00
|
|
|
$config = new Config;
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['repositories' => ['packagist' => false]]);
|
2021-12-10 11:57:08 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config, null, $versionGuesser);
|
2022-08-17 12:20:07 +00:00
|
|
|
$package = $loader->load([]);
|
2017-11-30 14:07:08 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('3.0-dev', $package->getPrettyVersion());
|
2017-11-30 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testFeatureBranchPrettyVersion(): void
|
2015-02-02 13:36:50 +00:00
|
|
|
{
|
|
|
|
if (!function_exists('proc_open')) {
|
|
|
|
$this->markTestSkipped('proc_open() is not available');
|
|
|
|
}
|
|
|
|
|
2021-08-19 11:00:30 +00:00
|
|
|
$manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')
|
2015-02-02 13:36:50 +00:00
|
|
|
->disableOriginalConstructor()
|
2015-07-30 11:37:12 +00:00
|
|
|
->getMock()
|
|
|
|
;
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$process = $this->getProcessExecutorMock();
|
2022-08-17 12:20:07 +00:00
|
|
|
$process->expects([
|
|
|
|
[
|
2022-01-06 12:56:12 +00:00
|
|
|
'cmd' => ['git', 'branch', '-a', '--no-color', '--no-abbrev', '-v'],
|
2021-08-19 11:00:30 +00:00
|
|
|
'stdout' => "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n",
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2024-06-10 13:09:06 +00:00
|
|
|
['cmd' => ['git', 'rev-list', 'master..latest-production']],
|
2022-08-17 12:20:07 +00:00
|
|
|
], true);
|
2015-02-02 13:36:50 +00:00
|
|
|
|
|
|
|
$config = new Config;
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['repositories' => ['packagist' => false]]);
|
2021-08-19 11:00:30 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $process, new VersionParser()));
|
2022-08-17 12:20:07 +00:00
|
|
|
$package = $loader->load(['require' => ['foo/bar' => 'self.version']]);
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals("dev-master", $package->getPrettyVersion());
|
2015-02-02 13:36:50 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testNonFeatureBranchPrettyVersion(): void
|
2015-02-02 13:36:50 +00:00
|
|
|
{
|
|
|
|
if (!function_exists('proc_open')) {
|
|
|
|
$this->markTestSkipped('proc_open() is not available');
|
|
|
|
}
|
|
|
|
|
2021-08-19 11:00:30 +00:00
|
|
|
$manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')
|
2015-07-30 11:37:12 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
|
|
|
;
|
2015-02-24 14:22:54 +00:00
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
$process = $this->getProcessExecutorMock();
|
2022-08-17 12:20:07 +00:00
|
|
|
$process->expects([
|
|
|
|
[
|
2022-01-06 12:56:12 +00:00
|
|
|
'cmd' => ['git', 'branch', '-a', '--no-color', '--no-abbrev', '-v'],
|
2021-10-27 14:18:24 +00:00
|
|
|
'stdout' => "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n",
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
], true);
|
2015-02-02 13:36:50 +00:00
|
|
|
|
|
|
|
$config = new Config;
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['repositories' => ['packagist' => false]]);
|
2021-08-19 11:00:30 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $process, new VersionParser()));
|
2022-08-17 12:20:07 +00:00
|
|
|
$package = $loader->load(['require' => ['foo/bar' => 'self.version'], "non-feature-branches" => ["latest-.*"]]);
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals("dev-latest-production", $package->getPrettyVersion());
|
2015-02-02 13:36:50 +00:00
|
|
|
}
|
2012-05-31 15:21:56 +00:00
|
|
|
}
|