RootPackageLoaderTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. use Composer\Repository\RepositoryManager;
  15. class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function testDetachedHeadBecomesDevHash()
  18. {
  19. if (!function_exists('proc_open')) {
  20. $this->markTestSkipped('proc_open() is not available');
  21. }
  22. $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
  23. $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
  24. ->disableOriginalConstructor()
  25. ->getMock();
  26. $self = $this;
  27. /* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
  28. $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self, $commitHash) {
  29. $self->assertStringStartsWith('git branch', $command);
  30. $output = "* (no branch) $commitHash Commit message\n";
  31. return 0;
  32. });
  33. $loader = new RootPackageLoader($manager, null, $processExecutor);
  34. $package = $loader->load(array());
  35. $this->assertEquals("dev-$commitHash", $package->getVersion());
  36. }
  37. public function testAllowsDisabledDefaultRepository()
  38. {
  39. $loader = new RootPackageLoader(
  40. new RepositoryManager(
  41. $this->getMock('Composer\\IO\\IOInterface'),
  42. $this->getMock('Composer\\Config')
  43. )
  44. );
  45. $repos = array(array('packagist' => false));
  46. $package = $loader->load(array('repositories' => $repos));
  47. $this->assertEquals($repos, $package->getRepositories());
  48. }
  49. }