RootPackageLoaderTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. if (0 === strpos($command, 'git describe')) {
  31. // simulate not being on a tag
  32. return 1;
  33. }
  34. $self->assertStringStartsWith('git branch', $command);
  35. $output = "* (no branch) $commitHash Commit message\n";
  36. return 0;
  37. });
  38. $config = new Config;
  39. $config->merge(array('repositories' => array('packagist' => false)));
  40. $loader = new RootPackageLoader($manager, $config, null, $processExecutor);
  41. $package = $loader->load(array());
  42. $this->assertEquals("dev-$commitHash", $package->getVersion());
  43. }
  44. public function testTagBecomesVersion()
  45. {
  46. if (!function_exists('proc_open')) {
  47. $this->markTestSkipped('proc_open() is not available');
  48. }
  49. $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $self = $this;
  53. /* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
  54. $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) {
  55. $self->assertEquals('git describe --exact-match', $command);
  56. $output = "v2.0.5-alpha2";
  57. return 0;
  58. });
  59. $config = new Config;
  60. $config->merge(array('repositories' => array('packagist' => false)));
  61. $loader = new RootPackageLoader($manager, $config, null, $processExecutor);
  62. $package = $loader->load(array());
  63. $this->assertEquals("2.0.5.0-alpha2", $package->getVersion());
  64. }
  65. }