PlatformRepositoryTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Repository;
  12. use Composer\Repository\PlatformRepository;
  13. use Composer\Test\TestCase;
  14. use Composer\Util\Platform;
  15. use Symfony\Component\Process\ExecutableFinder;
  16. class PlatformRepositoryTest extends TestCase {
  17. public function testHHVMVersionWhenExecutingInHHVM() {
  18. if (!defined('HHVM_VERSION_ID')) {
  19. $this->markTestSkipped('Not running with HHVM');
  20. return;
  21. }
  22. $repository = new PlatformRepository();
  23. $package = $repository->findPackage('hhvm', '*');
  24. $this->assertNotNull($package, 'failed to find HHVM package');
  25. $this->assertSame(
  26. sprintf('%d.%d.%d',
  27. HHVM_VERSION_ID / 10000,
  28. (HHVM_VERSION_ID / 100) % 100,
  29. HHVM_VERSION_ID % 100
  30. ),
  31. $package->getPrettyVersion()
  32. );
  33. }
  34. public function testHHVMVersionWhenExecutingInPHP() {
  35. if (defined('HHVM_VERSION_ID')) {
  36. $this->markTestSkipped('Running with HHVM');
  37. return;
  38. }
  39. if (PHP_VERSION_ID < 50400) {
  40. $this->markTestSkipped('Test only works on PHP 5.4+');
  41. return;
  42. }
  43. if (Platform::isWindows()) {
  44. $this->markTestSkipped('Test does not run on Windows');
  45. return;
  46. }
  47. $finder = new ExecutableFinder();
  48. $hhvm = $finder->find('hhvm');
  49. if ($hhvm === null) {
  50. $this->markTestSkipped('HHVM is not installed');
  51. }
  52. $process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
  53. $process->expects($this->once())->method('execute')->will($this->returnCallback(
  54. function($command, &$out) {
  55. $this->assertContains('HHVM_VERSION', $command);
  56. $out = '4.0.1-dev';
  57. return 0;
  58. }
  59. ));
  60. $repository = new PlatformRepository(array(), array(), $process);
  61. $package = $repository->findPackage('hhvm', '*');
  62. $this->assertNotNull($package, 'failed to find HHVM package');
  63. $this->assertSame('4.0.1.0-dev', $package->getVersion());
  64. }
  65. }