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;
|
2012-05-31 15:21:56 +00:00
|
|
|
use Composer\Test\Mock\ProcessExecutorMock;
|
2012-04-27 00:29:43 +00:00
|
|
|
use Composer\Repository\RepositoryManager;
|
2012-05-31 15:21:56 +00:00
|
|
|
|
|
|
|
class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testDetachedHeadBecomesDevHash()
|
|
|
|
{
|
|
|
|
if (!function_exists('proc_open')) {
|
|
|
|
$this->markTestSkipped('proc_open() is not available');
|
|
|
|
}
|
|
|
|
|
|
|
|
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
|
|
|
|
|
|
|
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$self = $this;
|
|
|
|
|
|
|
|
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
2014-06-10 14:02:44 +00:00
|
|
|
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self, $commitHash) {
|
2013-05-21 11:14:34 +00:00
|
|
|
if (0 === strpos($command, 'git describe')) {
|
|
|
|
// simulate not being on a tag
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:56 +00:00
|
|
|
$self->assertStringStartsWith('git branch', $command);
|
|
|
|
|
|
|
|
$output = "* (no branch) $commitHash Commit message\n";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2012-06-24 11:03:55 +00:00
|
|
|
$config = new Config;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
|
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
2012-05-31 15:21:56 +00:00
|
|
|
$package = $loader->load(array());
|
|
|
|
|
|
|
|
$this->assertEquals("dev-$commitHash", $package->getVersion());
|
|
|
|
}
|
2013-07-28 17:40:09 +00:00
|
|
|
|
2013-05-21 11:14:34 +00:00
|
|
|
public function testTagBecomesVersion()
|
|
|
|
{
|
|
|
|
if (!function_exists('proc_open')) {
|
|
|
|
$this->markTestSkipped('proc_open() is not available');
|
|
|
|
}
|
|
|
|
|
|
|
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$self = $this;
|
|
|
|
|
|
|
|
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
2014-06-10 14:02:44 +00:00
|
|
|
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self) {
|
2013-05-21 14:59:41 +00:00
|
|
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
2013-05-21 11:14:34 +00:00
|
|
|
|
|
|
|
$output = "v2.0.5-alpha2";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
|
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
|
|
|
$package = $loader->load(array());
|
|
|
|
|
|
|
|
$this->assertEquals("2.0.5.0-alpha2", $package->getVersion());
|
|
|
|
}
|
2013-08-12 00:33:18 +00:00
|
|
|
|
2013-08-12 08:27:25 +00:00
|
|
|
public function testInvalidTagBecomesVersion()
|
|
|
|
{
|
|
|
|
if (!function_exists('proc_open')) {
|
|
|
|
$this->markTestSkipped('proc_open() is not available');
|
|
|
|
}
|
|
|
|
|
|
|
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$self = $this;
|
|
|
|
|
|
|
|
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
2014-06-10 14:02:44 +00:00
|
|
|
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self) {
|
2013-08-12 08:27:25 +00:00
|
|
|
if ('git describe --exact-match --tags' === $command) {
|
|
|
|
$output = "foo-bar";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = "* foo 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
|
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
|
|
|
$package = $loader->load(array());
|
|
|
|
|
|
|
|
$this->assertEquals("dev-foo", $package->getVersion());
|
|
|
|
}
|
|
|
|
|
2013-07-28 17:40:09 +00:00
|
|
|
protected function loadPackage($data)
|
|
|
|
{
|
|
|
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2014-06-10 14:02:44 +00:00
|
|
|
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) {
|
2013-07-28 17:40:09 +00:00
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
$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',
|
2014-12-22 11:22:29 +00:00
|
|
|
'zux/complex' => '~1.0,>=1.0.2@dev'
|
2013-07-28 17:40:09 +00:00
|
|
|
),
|
|
|
|
'minimum-stability' => 'alpha',
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEquals('alpha', $package->getMinimumStability());
|
|
|
|
$this->assertEquals(array(
|
|
|
|
'bar/baz' => BasePackage::STABILITY_DEV,
|
|
|
|
'qux/quux' => BasePackage::STABILITY_RC,
|
2014-12-22 11:22:29 +00:00
|
|
|
'zux/complex' => BasePackage::STABILITY_DEV,
|
2013-07-28 17:40:09 +00:00
|
|
|
), $package->getStabilityFlags());
|
|
|
|
}
|
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()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$self = $this;
|
|
|
|
|
|
|
|
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
|
|
|
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) {
|
|
|
|
if (0 === strpos($command, 'git rev-list')) {
|
|
|
|
$output = "";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('git branch --no-color --no-abbrev -v' !== $command) {
|
|
|
|
return 1; //0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
|
|
|
|
|
|
|
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
|
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
|
|
|
$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()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$self = $this;
|
|
|
|
|
|
|
|
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
|
|
|
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) {
|
|
|
|
if (0 === strpos($command, 'git rev-list')) {
|
|
|
|
$output = "";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('git branch --no-color --no-abbrev -v' !== $command) {
|
|
|
|
return 1; //0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
|
|
|
|
|
|
|
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
|
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
|
|
|
$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
|
|
|
}
|