From 54adf0b61e3d2b32ae3d5eff482e0256138fe3f9 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 4 Dec 2017 12:25:25 +0100 Subject: [PATCH] Add regression test about VersionGuesser pretty_version handling --- .../Package/Version/VersionGuesserTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/Composer/Test/Package/Version/VersionGuesserTest.php b/tests/Composer/Test/Package/Version/VersionGuesserTest.php index fafb81c33..d5a92e2a5 100644 --- a/tests/Composer/Test/Package/Version/VersionGuesserTest.php +++ b/tests/Composer/Test/Package/Version/VersionGuesserTest.php @@ -383,6 +383,48 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase $this->assertEquals("2.0.5.0-alpha2", $versionData['version']); } + public function testTagBecomesPrettyVersion() + { + $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 branch --no-color --no-abbrev -v', $command); + $output = "* (HEAD detached at 1.0.0) c006f0c12bbbf197b5c071ffb1c0e9812bb14a4d Commit message\n"; + + return 0; + }) + ; + + $executor + ->expects($this->at(1)) + ->method('execute') + ->willReturnCallback(function ($command, &$output) use ($self) { + $self->assertEquals('git describe --exact-match --tags', $command); + $output = '1.0.0'; + + return 0; + }) + ; + + $config = new Config; + $config->merge(array('repositories' => array('packagist' => false))); + $guesser = new VersionGuesser($config, $executor, new VersionParser()); + $versionData = $guesser->guessVersion(array(), 'dummy/path'); + + $this->assertEquals('1.0.0.0', $versionData['version']); + $this->assertEquals('1.0.0', $versionData['pretty_version']); + } + public function testInvalidTagBecomesVersion() { $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')