1
0
Fork 0

Re-add unit test for FETCH_HEAD parsing

pull/6312/head
Nicole Cordes 2017-03-31 15:37:39 +02:00
parent 313e6b914d
commit c2fe198ebc
1 changed files with 38 additions and 10 deletions

View File

@ -158,16 +158,15 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("dev-$commitHash", $versionData['version']); $this->assertEquals("dev-$commitHash", $versionData['version']);
} }
public function testDetachedHeadBecomesDevHashGit2() public function testDetachedFetchHeadBecomesDevHashGit2()
{ {
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; $commitHash = 'da53c52eddd5f32ffca64a7b3801bea';
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor') $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute')) ->setMethods(['execute'])
->disableArgumentCloning() ->disableArgumentCloning()
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock();
;
$self = $this; $self = $this;
@ -176,16 +175,45 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
->method('execute') ->method('execute')
->willReturnCallback(function ($command, &$output) use ($self, $commitHash) { ->willReturnCallback(function ($command, &$output) use ($self, $commitHash) {
$self->assertEquals('git branch --no-color --no-abbrev -v', $command); $self->assertEquals('git branch --no-color --no-abbrev -v', $command);
$output = "* (HEAD detached at " . substr($commitHash, 0, 9) . ") $commitHash Commit message\n"; $output = "* (HEAD detached at FETCH_HEAD) $commitHash Commit message\n";
return 0; return 0;
}) });
;
$config = new Config; $config = new Config;
$config->merge(array('repositories' => array('packagist' => false))); $config->merge(['repositories' => ['packagist' => false]]);
$guesser = new VersionGuesser($config, $executor, new VersionParser()); $guesser = new VersionGuesser($config, $executor, new VersionParser());
$versionData = $guesser->guessVersion(array(), 'dummy/path'); $versionData = $guesser->guessVersion([], 'dummy/path');
$this->assertEquals("dev-$commitHash", $versionData['version']);
}
public function testDetachedCommitHeadBecomesDevHashGit2()
{
$commitHash = 'da53c52eddd5f32ffca64a7b3801bea';
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(['execute'])
->disableArgumentCloning()
->disableOriginalConstructor()
->getMock();
$self = $this;
$executor
->expects($this->at(0))
->method('execute')
->willReturnCallback(function ($command, &$output) use ($self, $commitHash) {
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
$output = "* (HEAD detached at da53c52ed) $commitHash Commit message\n";
return 0;
});
$config = new Config;
$config->merge(['repositories' => ['packagist' => false]]);
$guesser = new VersionGuesser($config, $executor, new VersionParser());
$versionData = $guesser->guessVersion([], 'dummy/path');
$this->assertEquals("dev-$commitHash", $versionData['version']); $this->assertEquals("dev-$commitHash", $versionData['version']);
} }