1
0
Fork 0
composer/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php

229 lines
7.9 KiB
PHP
Raw Normal View History

<?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\Package\Loader;
use Composer\Config;
use Composer\Package\Loader\RootPackageLoader;
use Composer\Package\BasePackage;
use Composer\Package\Version\VersionGuesser;
use Composer\Semver\VersionParser;
2020-02-07 03:18:45 +00:00
use Composer\Test\TestCase;
use Prophecy\Argument;
class RootPackageLoaderTest extends TestCase
{
protected function loadPackage($data)
{
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor()
->getMock();
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config);
return $loader->load($data);
}
public function testStabilityFlagsParsing()
{
$package = $this->loadPackage(array(
'require' => array(
'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',
'or/op' => '^2.0@dev || ^2.0@dev',
'multi/lowest-wins' => '^2.0@rc || >=3.0@dev , ~3.5@alpha',
'or/op/without-flags' => 'dev-master || 2.0 , ~3.5-alpha',
'or/op/without-flags2' => '3.0-beta || 2.0 , ~3.5-alpha',
),
'minimum-stability' => 'alpha',
));
$this->assertEquals('alpha', $package->getMinimumStability());
$this->assertEquals(array(
'bar/baz' => BasePackage::STABILITY_DEV,
'qux/quux' => BasePackage::STABILITY_RC,
'zux/complex' => BasePackage::STABILITY_DEV,
'or/op' => BasePackage::STABILITY_DEV,
'multi/lowest-wins' => BasePackage::STABILITY_DEV,
'or/op/without-flags' => BasePackage::STABILITY_DEV,
'or/op/without-flags2' => BasePackage::STABILITY_ALPHA,
), $package->getStabilityFlags());
}
public function testNoVersionIsVisibleInPrettyVersion()
{
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor()
2015-07-30 11:37:12 +00:00
->getMock()
;
2015-07-30 11:37:12 +00:00
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute'))
->disableArgumentCloning()
->disableOriginalConstructor()
2015-07-30 11:37:12 +00:00
->getMock()
;
$executor
->expects($this->any())
->method('execute')
2015-07-30 11:37:12 +00:00
->willReturn(null)
;
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser()));
$package = $loader->load(array());
$this->assertEquals("1.0.0.0", $package->getVersion());
$this->assertEquals("No version set (parsed as 1.0.0)", $package->getPrettyVersion());
}
public function testPrettyVersionForRootPackageInVersionBranch()
{
// see #6845
$manager = $this->prophesize('\\Composer\\Repository\\RepositoryManager');
$versionGuesser = $this->prophesize('\\Composer\\Package\\Version\\VersionGuesser');
$versionGuesser->guessVersion(Argument::cetera())
->willReturn(array(
'name' => 'A',
'version' => '3.0.9999999.9999999-dev',
'pretty_version' => '3.0-dev',
'commit' => 'aabbccddee',
));
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager->reveal(), $config, null, $versionGuesser->reveal());
$package = $loader->load(array());
$this->assertEquals('3.0-dev', $package->getPrettyVersion());
}
public function testFeatureBranchPrettyVersion()
{
if (!function_exists('proc_open')) {
$this->markTestSkipped('proc_open() is not available');
}
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor()
2015-07-30 11:37:12 +00:00
->getMock()
;
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute'))
->disableArgumentCloning()
->disableOriginalConstructor()
->getMock()
;
$self = $this;
2015-07-30 11:37:12 +00:00
$executor
->expects($this->at(0))
->method('execute')
->willReturnCallback(function ($command, &$output) use ($self) {
$self->assertEquals('git branch -a --no-color --no-abbrev -v', $command);
2015-07-30 11:37:12 +00:00
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
2015-07-30 11:37:12 +00:00
return 0;
})
;
2015-07-30 11:37:12 +00:00
$executor
2016-02-25 14:24:21 +00:00
->expects($this->at(1))
2015-07-30 11:37:12 +00:00
->method('execute')
->willReturnCallback(function ($command, &$output) use ($self) {
$self->assertEquals('git rev-list master..latest-production', $command);
$output = "";
2015-07-30 11:37:12 +00:00
return 0;
})
;
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser()));
$package = $loader->load(array('require' => array('foo/bar' => 'self.version')));
$this->assertEquals("dev-master", $package->getPrettyVersion());
}
public function testNonFeatureBranchPrettyVersion()
{
if (!function_exists('proc_open')) {
$this->markTestSkipped('proc_open() is not available');
}
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor()
2015-07-30 11:37:12 +00:00
->getMock()
;
2015-07-30 11:37:12 +00:00
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute'))
->disableArgumentCloning()
->disableOriginalConstructor()
->getMock()
;
2015-02-24 14:22:54 +00:00
2015-07-30 11:37:12 +00:00
$self = $this;
2015-07-30 11:37:12 +00:00
$executor
->expects($this->at(0))
->method('execute')
->willReturnCallback(function ($command, &$output) use ($self) {
$self->assertEquals('git branch -a --no-color --no-abbrev -v', $command);
2015-07-30 11:37:12 +00:00
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
2015-07-30 11:37:12 +00:00
return 0;
})
;
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser()));
$package = $loader->load(array('require' => array('foo/bar' => 'self.version'), "non-feature-branches" => array("latest-.*")));
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
}
2020-10-08 10:33:16 +00:00
2020-10-13 13:16:39 +00:00
/**
* @dataProvider provideExtraBranchVersion
*/
public function testLoadExtraBranchVersion($branchVersion)
2020-10-08 10:33:16 +00:00
{
$package = $this->loadPackage(array(
'extra' => array(
2020-10-13 13:16:39 +00:00
'branch-version' => $branchVersion,
2020-10-08 10:33:16 +00:00
),
));
$this->assertEquals('1.2.x-dev', $package->getPrettyVersion());
}
2020-10-13 13:16:39 +00:00
public function provideExtraBranchVersion()
{
return array(
array('1.2'),
array('1.2.x'),
array('1.2-dev'),
array('1.2.x-dev'),
);
}
}