2012-05-31 15:21:56 +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\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;
|
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;
|
2012-05-31 15:21:56 +00:00
|
|
|
|
|
|
|
class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2015-08-18 13:58:18 +00:00
|
|
|
protected function loadPackage($data)
|
2012-05-31 15:21:56 +00:00
|
|
|
{
|
|
|
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
|
->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;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
2013-05-21 11:14:34 +00:00
|
|
|
|
2015-08-18 13:58:18 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config);
|
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
|
|
|
|
2015-08-18 13:58:18 +00:00
|
|
|
public function testStabilityFlagsParsing()
|
2013-08-12 08:27:25 +00:00
|
|
|
{
|
2015-08-18 13:58:18 +00:00
|
|
|
$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',
|
2015-08-18 13:58:18 +00:00
|
|
|
),
|
|
|
|
'minimum-stability' => 'alpha',
|
|
|
|
));
|
2013-08-12 08:27:25 +00:00
|
|
|
|
2015-08-18 13:58:18 +00:00
|
|
|
$this->assertEquals('alpha', $package->getMinimumStability());
|
|
|
|
$this->assertEquals(array(
|
|
|
|
'bar/baz' => BasePackage::STABILITY_DEV,
|
|
|
|
'qux/quux' => BasePackage::STABILITY_RC,
|
|
|
|
'zux/complex' => BasePackage::STABILITY_DEV,
|
|
|
|
), $package->getStabilityFlags());
|
2013-08-12 08:27:25 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 22:47:17 +00:00
|
|
|
public function testNoVersionIsVisibleInPrettyVersion()
|
|
|
|
{
|
|
|
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
|
->disableOriginalConstructor()
|
2015-07-30 11:37:12 +00:00
|
|
|
->getMock()
|
|
|
|
;
|
2015-06-18 22:47:17 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
|
|
|
->setMethods(array('execute'))
|
|
|
|
->disableArgumentCloning()
|
2015-06-18 22:47:17 +00:00
|
|
|
->disableOriginalConstructor()
|
2015-07-30 11:37:12 +00:00
|
|
|
->getMock()
|
|
|
|
;
|
|
|
|
|
|
|
|
$executor
|
|
|
|
->expects($this->any())
|
2015-06-18 22:47:17 +00:00
|
|
|
->method('execute')
|
2015-07-30 11:37:12 +00:00
|
|
|
->willReturn(null)
|
|
|
|
;
|
2015-06-18 22:47:17 +00:00
|
|
|
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
2015-09-12 21:28:03 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser()));
|
2015-06-18 22:47:17 +00:00
|
|
|
$package = $loader->load(array());
|
|
|
|
|
|
|
|
$this->assertEquals("1.0.0.0", $package->getVersion());
|
|
|
|
$this->assertEquals("No version set (parsed as 1.0.0)", $package->getPrettyVersion());
|
|
|
|
}
|
|
|
|
|
2015-02-02 13:36:50 +00:00
|
|
|
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()
|
|
|
|
;
|
2015-02-02 13:36:50 +00:00
|
|
|
|
|
|
|
$self = $this;
|
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
$executor
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->willReturnCallback(function ($command) use ($self) {
|
|
|
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
2015-02-24 14:22:54 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
return 1;
|
|
|
|
})
|
|
|
|
;
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
$executor
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('execute')
|
|
|
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
|
|
|
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
|
|
|
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
;
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
$executor
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('execute')
|
|
|
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
|
|
|
$self->assertEquals('git rev-list master..latest-production', $command);
|
|
|
|
$output = "";
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
;
|
2015-02-02 13:36:50 +00:00
|
|
|
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
2015-09-12 21:28:03 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser()));
|
2015-02-02 13:36:50 +00:00
|
|
|
$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-02-02 13:36:50 +00:00
|
|
|
|
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-02-02 13:36:50 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
$executor
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('execute')
|
|
|
|
->willReturnCallback(function ($command) use ($self) {
|
|
|
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
return 1;
|
|
|
|
})
|
|
|
|
;
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
$executor
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('execute')
|
|
|
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
|
|
|
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
|
|
|
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
2015-02-02 13:36:50 +00:00
|
|
|
|
2015-07-30 11:37:12 +00:00
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
;
|
2015-02-02 13:36:50 +00:00
|
|
|
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
2015-09-12 21:28:03 +00:00
|
|
|
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser()));
|
2015-02-02 13:36:50 +00:00
|
|
|
$package = $loader->load(array('require' => array('foo/bar' => 'self.version'), "non-feature-branches" => array("latest-.*")));
|
|
|
|
|
|
|
|
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
|
|
|
|
}
|
2012-05-31 15:21:56 +00:00
|
|
|
}
|