RootPackageLoaderTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. $loader = new RootPackageLoader($manager, new Config, null, $processExecutor);
  35. $package = $loader->load(array());
  36. $this->assertEquals("dev-$commitHash", $package->getVersion());
  37. }
  38. public function testAllowsDisabledDefaultRepository()
  39. {
  40. $loader = new RootPackageLoader(
  41. new RepositoryManager(
  42. $this->getMock('Composer\\IO\\IOInterface'),
  43. $this->getMock('Composer\\Config')
  44. ),
  45. new Config()
  46. );
  47. $repos = array(array('packagist' => false));
  48. $package = $loader->load(array('repositories' => $repos));
  49. $this->assertEquals($repos, $package->getRepositories());
  50. }
  51. }