Browse Source

Add regression test about VersionGuesser pretty_version handling

Alessandro Lai 7 years ago
parent
commit
54adf0b61e
1 changed files with 42 additions and 0 deletions
  1. 42 0
      tests/Composer/Test/Package/Version/VersionGuesserTest.php

+ 42 - 0
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')