closes #1508 - updated tests
parent
c6cc6dd607
commit
ef37b86c81
|
@ -1,31 +0,0 @@
|
||||||
<?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\Mock;
|
|
||||||
|
|
||||||
use Composer\Util\ProcessExecutor;
|
|
||||||
|
|
||||||
class ProcessExecutorMock extends ProcessExecutor
|
|
||||||
{
|
|
||||||
private $execute;
|
|
||||||
|
|
||||||
public function __construct(\Closure $execute)
|
|
||||||
{
|
|
||||||
$this->execute = $execute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function execute($command, &$output = null, $cwd = null)
|
|
||||||
{
|
|
||||||
$execute = $this->execute;
|
|
||||||
|
|
||||||
return $execute($command, $output, $cwd);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,7 +15,6 @@ namespace Composer\Test\Package\Loader;
|
||||||
use Composer\Config;
|
use Composer\Config;
|
||||||
use Composer\Package\Loader\RootPackageLoader;
|
use Composer\Package\Loader\RootPackageLoader;
|
||||||
use Composer\Package\BasePackage;
|
use Composer\Package\BasePackage;
|
||||||
use Composer\Test\Mock\ProcessExecutorMock;
|
|
||||||
|
|
||||||
class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
@ -29,27 +28,39 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->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;
|
$self = $this;
|
||||||
|
|
||||||
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
$executor
|
||||||
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self, $commitHash) {
|
->expects($this->at(1))
|
||||||
if (0 === strpos($command, 'git describe')) {
|
->method('execute')
|
||||||
// simulate not being on a tag
|
->willReturnCallback(function ($command, &$output) use ($self, $commitHash) {
|
||||||
return 1;
|
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
||||||
}
|
|
||||||
|
|
||||||
$self->assertStringStartsWith('git branch', $command);
|
|
||||||
|
|
||||||
$output = "* (no branch) $commitHash Commit message\n";
|
$output = "* (no branch) $commitHash Commit message\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
})
|
||||||
|
;
|
||||||
|
|
||||||
$config = new Config;
|
$config = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
$loader = new RootPackageLoader($manager, $config, null, $executor);
|
||||||
$package = $loader->load(array());
|
$package = $loader->load(array());
|
||||||
|
|
||||||
$this->assertEquals("dev-$commitHash", $package->getVersion());
|
$this->assertEquals("dev-$commitHash", $package->getVersion());
|
||||||
|
@ -63,22 +74,32 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
|
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
||||||
|
->setMethods(array('execute'))
|
||||||
|
->disableArgumentCloning()
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
|
|
||||||
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
$executor
|
||||||
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self) {
|
->expects($this->at(0))
|
||||||
|
->method('execute')
|
||||||
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
$self->assertEquals('git describe --exact-match --tags', $command);
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
||||||
|
|
||||||
$output = "v2.0.5-alpha2";
|
$output = "v2.0.5-alpha2";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
})
|
||||||
|
;
|
||||||
|
|
||||||
$config = new Config;
|
$config = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
$loader = new RootPackageLoader($manager, $config, null, $executor);
|
||||||
$package = $loader->load(array());
|
$package = $loader->load(array());
|
||||||
|
|
||||||
$this->assertEquals("2.0.5.0-alpha2", $package->getVersion());
|
$this->assertEquals("2.0.5.0-alpha2", $package->getVersion());
|
||||||
|
@ -92,26 +113,43 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
|
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
||||||
|
->setMethods(array('execute'))
|
||||||
|
->disableArgumentCloning()
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
|
|
||||||
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
$executor
|
||||||
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self) {
|
->expects($this->at(0))
|
||||||
if ('git describe --exact-match --tags' === $command) {
|
->method('execute')
|
||||||
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
||||||
$output = "foo-bar";
|
$output = "foo-bar";
|
||||||
|
|
||||||
return 0;
|
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";
|
$output = "* foo 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
})
|
||||||
|
;
|
||||||
|
|
||||||
$config = new Config;
|
$config = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
$loader = new RootPackageLoader($manager, $config, null, $executor);
|
||||||
$package = $loader->load(array());
|
$package = $loader->load(array());
|
||||||
|
|
||||||
$this->assertEquals("dev-foo", $package->getVersion());
|
$this->assertEquals("dev-foo", $package->getVersion());
|
||||||
|
@ -121,21 +159,25 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
$self = $this;
|
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
||||||
|
->setMethods(array('execute'))
|
||||||
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
->disableArgumentCloning()
|
||||||
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')
|
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock()
|
||||||
$processExecutor->expects($this->any())
|
;
|
||||||
|
|
||||||
|
$executor
|
||||||
|
->expects($this->any())
|
||||||
->method('execute')
|
->method('execute')
|
||||||
->willReturn(null);
|
->willReturn(null)
|
||||||
|
;
|
||||||
|
|
||||||
$config = new Config;
|
$config = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
$loader = new RootPackageLoader($manager, $config, null, $executor);
|
||||||
$package = $loader->load(array());
|
$package = $loader->load(array());
|
||||||
|
|
||||||
$this->assertEquals("1.0.0.0", $package->getVersion());
|
$this->assertEquals("1.0.0.0", $package->getVersion());
|
||||||
|
@ -148,10 +190,6 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) {
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
$config = new Config;
|
$config = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
|
|
||||||
|
@ -188,32 +226,53 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
|
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
||||||
|
->setMethods(array('execute'))
|
||||||
|
->disableArgumentCloning()
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
|
|
||||||
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
$executor
|
||||||
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self) {
|
->expects($this->at(0))
|
||||||
if (0 === strpos($command, 'git rev-list')) {
|
->method('execute')
|
||||||
$output = "";
|
->willReturnCallback(function ($command) use ($self) {
|
||||||
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
||||||
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
})
|
||||||
|
;
|
||||||
if ('git branch --no-color --no-abbrev -v' !== $command) {
|
|
||||||
return 1; //0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$executor
|
||||||
|
->expects($this->at(1))
|
||||||
|
->method('execute')
|
||||||
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
||||||
|
|
||||||
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
})
|
||||||
|
;
|
||||||
|
|
||||||
|
$executor
|
||||||
|
->expects($this->at(2))
|
||||||
|
->method('execute')
|
||||||
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
|
$self->assertEquals('git rev-list master..latest-production', $command);
|
||||||
|
$output = "";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
$config = new Config;
|
$config = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
$loader = new RootPackageLoader($manager, $config, null, $executor);
|
||||||
$package = $loader->load(array('require' => array('foo/bar' => 'self.version')));
|
$package = $loader->load(array('require' => array('foo/bar' => 'self.version')));
|
||||||
|
|
||||||
$this->assertEquals("dev-master", $package->getPrettyVersion());
|
$this->assertEquals("dev-master", $package->getPrettyVersion());
|
||||||
|
@ -227,32 +286,42 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
|
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
||||||
|
->setMethods(array('execute'))
|
||||||
|
->disableArgumentCloning()
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
|
|
||||||
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
$executor
|
||||||
$processExecutor = new ProcessExecutorMock(function ($command, &$output = null, $cwd = null) use ($self) {
|
->expects($this->at(0))
|
||||||
if (0 === strpos($command, 'git rev-list')) {
|
->method('execute')
|
||||||
$output = "";
|
->willReturnCallback(function ($command) use ($self) {
|
||||||
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
||||||
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
})
|
||||||
|
;
|
||||||
if ('git branch --no-color --no-abbrev -v' !== $command) {
|
|
||||||
return 1; //0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$executor
|
||||||
|
->expects($this->at(1))
|
||||||
|
->method('execute')
|
||||||
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
||||||
|
|
||||||
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
})
|
||||||
|
;
|
||||||
|
|
||||||
$config = new Config;
|
$config = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
$loader = new RootPackageLoader($manager, $config, null, $executor);
|
||||||
$package = $loader->load(array('require' => array('foo/bar' => 'self.version'), "non-feature-branches" => array("latest-.*")));
|
$package = $loader->load(array('require' => array('foo/bar' => 'self.version'), "non-feature-branches" => array("latest-.*")));
|
||||||
|
|
||||||
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
|
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
|
||||||
|
|
Loading…
Reference in New Issue