From 97955a6acea1d4de1849768290c9e0aff12ec5a5 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 31 May 2012 16:21:41 +0100 Subject: [PATCH 1/2] Mock ProcessExecutor --- .../Test/Mock/ProcessExecutorMock.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/Composer/Test/Mock/ProcessExecutorMock.php diff --git a/tests/Composer/Test/Mock/ProcessExecutorMock.php b/tests/Composer/Test/Mock/ProcessExecutorMock.php new file mode 100644 index 000000000..13ea9792b --- /dev/null +++ b/tests/Composer/Test/Mock/ProcessExecutorMock.php @@ -0,0 +1,31 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test\Mock; + +use Composer\Util\ProcessExecutor; + +class ProcessExecutorMock extends ProcessExecutor +{ + private $execute; + + public function __construct(\Closure $execute) + { + $this->execute = $execute; + } + + public function execute($command, &$output = null, $cwd = null) + { + $execute = $this->execute; + + return $execute($command, $output, $cwd); + } +} From 5e4b2fcc8d1084ce7bee99f13baade081aa859c7 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 31 May 2012 16:21:56 +0100 Subject: [PATCH 2/2] Test for detached heads yielding an invalid version --- .../Package/Loader/RootPackageLoaderTest.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php new file mode 100644 index 000000000..73f64b242 --- /dev/null +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -0,0 +1,48 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test\Package\Loader; + +use Composer\Package\Loader\RootPackageLoader; +use Composer\Test\Mock\ProcessExecutorMock; + +class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function testDetachedHeadBecomesDevHash() + { + if (!function_exists('proc_open')) { + $this->markTestSkipped('proc_open() is not available'); + } + + $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; + + $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, $commitHash) { + $self->assertStringStartsWith('git branch', $command); + + $output = "* (no branch) $commitHash Commit message\n"; + + return 0; + }); + + $loader = new RootPackageLoader($manager, null, $processExecutor); + $package = $loader->load(array()); + + $this->assertEquals("dev-$commitHash", $package->getVersion()); + } +}