From f9fe39e6243365b8c222ff0e840de406e72962a1 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Tue, 21 May 2013 06:14:34 -0500 Subject: [PATCH] Fixed the existing test and added a new one for git tag version guessing. --- .../Package/Loader/RootPackageLoaderTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index 6f4f53e19..dd22bcd0f 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -35,6 +35,11 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase /* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */ $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self, $commitHash) { + if (0 === strpos($command, 'git describe')) { + // simulate not being on a tag + return 1; + } + $self->assertStringStartsWith('git branch', $command); $output = "* (no branch) $commitHash Commit message\n"; @@ -49,4 +54,33 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals("dev-$commitHash", $package->getVersion()); } + + public function testTagBecomesVersion() + { + if (!function_exists('proc_open')) { + $this->markTestSkipped('proc_open() is not available'); + } + + $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager') + ->disableOriginalConstructor() + ->getMock(); + + $self = $this; + + /* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */ + $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) { + $self->assertEquals('git describe --exact-match', $command); + + $output = "v2.0.5-alpha2"; + + return 0; + }); + + $config = new Config; + $config->merge(array('repositories' => array('packagist' => false))); + $loader = new RootPackageLoader($manager, $config, null, $processExecutor); + $package = $loader->load(array()); + + $this->assertEquals("2.0.5.0-alpha2", $package->getVersion()); + } }