RootPackageLoaderTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Package\Loader;
  12. use Composer\Config;
  13. use Composer\Package\Loader\RootPackageLoader;
  14. use Composer\Test\Mock\ProcessExecutorMock;
  15. use Composer\Repository\RepositoryManager;
  16. class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
  17. {
  18. public function testDetachedHeadBecomesDevHash()
  19. {
  20. if (!function_exists('proc_open')) {
  21. $this->markTestSkipped('proc_open() is not available');
  22. }
  23. $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
  24. $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
  25. ->disableOriginalConstructor()
  26. ->getMock();
  27. $self = $this;
  28. /* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
  29. $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self, $commitHash) {
  30. $self->assertStringStartsWith('git branch', $command);
  31. $output = "* (no branch) $commitHash Commit message\n";
  32. return 0;
  33. });
  34. $config = new Config;
  35. $config->merge(array('repositories' => array('packagist' => false)));
  36. $loader = new RootPackageLoader($manager, $config, null, $processExecutor);
  37. $package = $loader->load(array());
  38. $this->assertEquals("dev-$commitHash", $package->getVersion());
  39. }
  40. }