|
@@ -15,144 +15,43 @@ namespace Composer\Test\Package\Loader;
|
|
|
use Composer\Config;
|
|
|
use Composer\Package\Loader\RootPackageLoader;
|
|
|
use Composer\Package\BasePackage;
|
|
|
+use Composer\Package\Version\VersionGuesser;
|
|
|
+use Composer\Package\Version\VersionParser;
|
|
|
|
|
|
class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
- public function testDetachedHeadBecomesDevHash()
|
|
|
+ protected function loadPackage($data)
|
|
|
{
|
|
|
- if (!function_exists('proc_open')) {
|
|
|
- $this->markTestSkipped('proc_open() is not available');
|
|
|
- }
|
|
|
-
|
|
|
- $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
|
|
|
-
|
|
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
->disableOriginalConstructor()
|
|
|
- ->getMock()
|
|
|
- ;
|
|
|
-
|
|
|
- $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
|
|
- ->setMethods(array('execute'))
|
|
|
- ->disableArgumentCloning()
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock()
|
|
|
- ;
|
|
|
-
|
|
|
- $executor
|
|
|
- ->expects($this->at(0))
|
|
|
- ->method('execute')
|
|
|
- ->with('git describe --exact-match --tags')
|
|
|
- ->willReturn(1)
|
|
|
- ;
|
|
|
-
|
|
|
- $self = $this;
|
|
|
-
|
|
|
- $executor
|
|
|
- ->expects($this->at(1))
|
|
|
- ->method('execute')
|
|
|
- ->willReturnCallback(function ($command, &$output) use ($self, $commitHash) {
|
|
|
- $self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
|
|
- $output = "* (no branch) $commitHash Commit message\n";
|
|
|
-
|
|
|
- return 0;
|
|
|
- })
|
|
|
- ;
|
|
|
+ ->getMock();
|
|
|
|
|
|
$config = new Config;
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
- $loader = new RootPackageLoader($manager, $config, null, $executor);
|
|
|
- $package = $loader->load(array());
|
|
|
-
|
|
|
- $this->assertEquals("dev-$commitHash", $package->getVersion());
|
|
|
- }
|
|
|
-
|
|
|
- public function testTagBecomesVersion()
|
|
|
- {
|
|
|
- if (!function_exists('proc_open')) {
|
|
|
- $this->markTestSkipped('proc_open() is not available');
|
|
|
- }
|
|
|
|
|
|
- $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock()
|
|
|
- ;
|
|
|
-
|
|
|
- $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
|
|
- ->setMethods(array('execute'))
|
|
|
- ->disableArgumentCloning()
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock()
|
|
|
- ;
|
|
|
-
|
|
|
- $self = $this;
|
|
|
-
|
|
|
- $executor
|
|
|
- ->expects($this->at(0))
|
|
|
- ->method('execute')
|
|
|
- ->willReturnCallback(function ($command, &$output) use ($self) {
|
|
|
- $self->assertEquals('git describe --exact-match --tags', $command);
|
|
|
- $output = "v2.0.5-alpha2";
|
|
|
-
|
|
|
- return 0;
|
|
|
- })
|
|
|
- ;
|
|
|
-
|
|
|
- $config = new Config;
|
|
|
- $config->merge(array('repositories' => array('packagist' => false)));
|
|
|
- $loader = new RootPackageLoader($manager, $config, null, $executor);
|
|
|
- $package = $loader->load(array());
|
|
|
+ $loader = new RootPackageLoader($manager, $config);
|
|
|
|
|
|
- $this->assertEquals("2.0.5.0-alpha2", $package->getVersion());
|
|
|
+ return $loader->load($data);
|
|
|
}
|
|
|
|
|
|
- public function testInvalidTagBecomesVersion()
|
|
|
+ public function testStabilityFlagsParsing()
|
|
|
{
|
|
|
- if (!function_exists('proc_open')) {
|
|
|
- $this->markTestSkipped('proc_open() is not available');
|
|
|
- }
|
|
|
-
|
|
|
- $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock()
|
|
|
- ;
|
|
|
-
|
|
|
- $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
|
|
- ->setMethods(array('execute'))
|
|
|
- ->disableArgumentCloning()
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock()
|
|
|
- ;
|
|
|
-
|
|
|
- $self = $this;
|
|
|
-
|
|
|
- $executor
|
|
|
- ->expects($this->at(0))
|
|
|
- ->method('execute')
|
|
|
- ->willReturnCallback(function ($command, &$output) use ($self) {
|
|
|
- $self->assertEquals('git describe --exact-match --tags', $command);
|
|
|
- $output = "foo-bar";
|
|
|
-
|
|
|
- return 0;
|
|
|
- })
|
|
|
- ;
|
|
|
-
|
|
|
- $executor
|
|
|
- ->expects($this->at(1))
|
|
|
- ->method('execute')
|
|
|
- ->willReturnCallback(function ($command, &$output) use ($self) {
|
|
|
- $self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
|
|
- $output = "* foo 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n";
|
|
|
-
|
|
|
- return 0;
|
|
|
- })
|
|
|
- ;
|
|
|
-
|
|
|
- $config = new Config;
|
|
|
- $config->merge(array('repositories' => array('packagist' => false)));
|
|
|
- $loader = new RootPackageLoader($manager, $config, null, $executor);
|
|
|
- $package = $loader->load(array());
|
|
|
+ $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',
|
|
|
+ 'zux/complex' => '~1.0,>=1.0.2@dev'
|
|
|
+ ),
|
|
|
+ 'minimum-stability' => 'alpha',
|
|
|
+ ));
|
|
|
|
|
|
- $this->assertEquals("dev-foo", $package->getVersion());
|
|
|
+ $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());
|
|
|
}
|
|
|
|
|
|
public function testNoVersionIsVisibleInPrettyVersion()
|
|
@@ -177,46 +76,14 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
$config = new Config;
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
- $loader = new RootPackageLoader($manager, $config, null, $executor);
|
|
|
+ $loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($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());
|
|
|
}
|
|
|
|
|
|
- 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',
|
|
|
- 'zux/complex' => '~1.0,>=1.0.2@dev'
|
|
|
- ),
|
|
|
- '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,
|
|
|
- ), $package->getStabilityFlags());
|
|
|
- }
|
|
|
|
|
|
public function testFeatureBranchPrettyVersion()
|
|
|
{
|
|
@@ -272,7 +139,7 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
$config = new Config;
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
- $loader = new RootPackageLoader($manager, $config, null, $executor);
|
|
|
+ $loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($executor, new VersionParser()));
|
|
|
$package = $loader->load(array('require' => array('foo/bar' => 'self.version')));
|
|
|
|
|
|
$this->assertEquals("dev-master", $package->getPrettyVersion());
|
|
@@ -321,7 +188,7 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
$config = new Config;
|
|
|
$config->merge(array('repositories' => array('packagist' => false)));
|
|
|
- $loader = new RootPackageLoader($manager, $config, null, $executor);
|
|
|
+ $loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($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());
|