1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

#4828 Using version guesser to pull out the commit has for git repositories. The return value is now an array with version and commit values.

This commit is contained in:
Sash 2016-02-22 21:13:39 +00:00
parent 4c0e163977
commit f6899e5c38
4 changed files with 111 additions and 45 deletions

View file

@ -25,6 +25,47 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
}
}
public function testGuessVersionReturnsData()
{
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
$anotherCommitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
$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, $anotherCommitHash) {
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
$output = "* master $commitHash Commit message\n(no branch) $anotherCommitHash Commit message\n";
return 0;
})
;
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$guesser = new VersionGuesser($config, $executor, new VersionParser());
$versionArray = $guesser->guessVersion(array(), 'dummy/path');
$this->assertEquals("dev-master", $versionArray['version']);
$this->assertEquals($commitHash, $versionArray['commit']);
}
public function testDetachedHeadBecomesDevHash()
{
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
@ -59,7 +100,7 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$guesser = new VersionGuesser($config, $executor, new VersionParser());
$version = $guesser->guessVersion(array(), 'dummy/path');
$version = $guesser->guessVersion(array(), 'dummy/path')['version'];
$this->assertEquals("dev-$commitHash", $version);
}
@ -89,7 +130,7 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$guesser = new VersionGuesser($config, $executor, new VersionParser());
$version = $guesser->guessVersion(array(), 'dummy/path');
$version = $guesser->guessVersion(array(), 'dummy/path')['version'];
$this->assertEquals("2.0.5.0-alpha2", $version);
}
@ -130,7 +171,7 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$guesser = new VersionGuesser($config, $executor, new VersionParser());
$version = $guesser->guessVersion(array(), 'dummy/path');
$version = $guesser->guessVersion(array(), 'dummy/path')['version'];
$this->assertEquals("dev-foo", $version);
}