Browse Source

VersionGuesser test for HG

Filippo Tessarotto 8 years ago
parent
commit
04b1ddb79f
1 changed files with 67 additions and 0 deletions
  1. 67 0
      tests/Composer/Test/Package/Version/VersionGuesserTest.php

+ 67 - 0
tests/Composer/Test/Package/Version/VersionGuesserTest.php

@@ -25,6 +25,73 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
         }
     }
 
+    public function testHgGuessVersionReturnsData()
+    {
+        $branch = 'default';
+
+        $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
+            ->setMethods(array('execute'))
+            ->disableArgumentCloning()
+            ->disableOriginalConstructor()
+            ->getMock()
+        ;
+
+        $self = $this;
+        $step = 0;
+
+        $executor
+            ->expects($this->at($step))
+            ->method('execute')
+            ->willReturnCallback(function ($command, &$output) use ($self) {
+                $self->assertEquals('git branch --no-color --no-abbrev -v', $command);
+
+                return 128;
+            })
+        ;
+
+        ++$step;
+        $executor
+            ->expects($this->at($step))
+            ->method('execute')
+            ->willReturnCallback(function ($command, &$output) use ($self) {
+                $self->assertEquals('git describe --exact-match --tags', $command);
+
+                return 128;
+            })
+        ;
+
+        ++$step;
+        $executor
+            ->expects($this->at($step))
+            ->method('execute')
+            ->willReturnCallback(function ($command, &$output) use ($self) {
+                $self->assertEquals('git log --pretty="%H" -n1 HEAD', $command);
+
+                return 128;
+            })
+        ;
+
+        ++$step;
+        $executor
+            ->expects($this->at($step))
+            ->method('execute')
+            ->willReturnCallback(function ($command, &$output) use ($self, $branch) {
+                $self->assertEquals('hg branch', $command);
+                $output = $branch;
+
+                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($branch, $versionArray['version']);
+        $this->assertEmpty($versionArray['commit']);
+    }
+
     public function testGuessVersionReturnsData()
     {
         $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';