RootPackageLoaderTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Package\Loader\RootPackageLoader;
  13. use Composer\Test\Mock\ProcessExecutorMock;
  14. class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testDetachedHeadBecomesDevHash()
  17. {
  18. if (!function_exists('proc_open')) {
  19. $this->markTestSkipped('proc_open() is not available');
  20. }
  21. $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
  22. $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
  23. ->disableOriginalConstructor()
  24. ->getMock();
  25. $self = $this;
  26. /* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
  27. $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self, $commitHash) {
  28. $self->assertStringStartsWith('git branch', $command);
  29. $output = "* (no branch) $commitHash Commit message\n";
  30. return 0;
  31. });
  32. $loader = new RootPackageLoader($manager, null, $processExecutor);
  33. $package = $loader->load(array());
  34. $this->assertEquals("dev-$commitHash", $package->getVersion());
  35. }
  36. }