RuntimeTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/environment.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Environment;
  11. use PHPUnit\Framework\TestCase;
  12. /**
  13. * @covers \SebastianBergmann\Environment\Runtime
  14. */
  15. final class RuntimeTest extends TestCase
  16. {
  17. /**
  18. * @var \SebastianBergmann\Environment\Runtime
  19. */
  20. private $env;
  21. protected function setUp(): void
  22. {
  23. $this->env = new Runtime;
  24. }
  25. /**
  26. * @requires extension xdebug
  27. */
  28. public function testCanCollectCodeCoverageWhenXdebugExtensionIsEnabled(): void
  29. {
  30. $this->assertTrue($this->env->canCollectCodeCoverage());
  31. }
  32. /**
  33. * @requires extension pcov
  34. */
  35. public function testCanCollectCodeCoverageWhenPcovExtensionIsEnabled(): void
  36. {
  37. $this->assertTrue($this->env->canCollectCodeCoverage());
  38. }
  39. public function testCanCollectCodeCoverageWhenRunningOnPhpdbg(): void
  40. {
  41. $this->markTestSkippedWhenNotRunningOnPhpdbg();
  42. $this->assertTrue($this->env->canCollectCodeCoverage());
  43. }
  44. public function testBinaryCanBeRetrieved(): void
  45. {
  46. $this->assertNotEmpty($this->env->getBinary());
  47. }
  48. /**
  49. * @requires PHP
  50. */
  51. public function testIsHhvmReturnsFalseWhenRunningOnPhp(): void
  52. {
  53. $this->assertFalse($this->env->isHHVM());
  54. }
  55. /**
  56. * @requires PHP
  57. */
  58. public function testIsPhpReturnsTrueWhenRunningOnPhp(): void
  59. {
  60. $this->markTestSkippedWhenRunningOnPhpdbg();
  61. $this->assertTrue($this->env->isPHP());
  62. }
  63. /**
  64. * @requires extension pcov
  65. */
  66. public function testPCOVCanBeDetected(): void
  67. {
  68. $this->assertTrue($this->env->hasPCOV());
  69. }
  70. public function testPhpdbgCanBeDetected(): void
  71. {
  72. $this->markTestSkippedWhenNotRunningOnPhpdbg();
  73. $this->assertTrue($this->env->hasPHPDBGCodeCoverage());
  74. }
  75. /**
  76. * @requires extension xdebug
  77. */
  78. public function testXdebugCanBeDetected(): void
  79. {
  80. $this->markTestSkippedWhenRunningOnPhpdbg();
  81. $this->assertTrue($this->env->hasXdebug());
  82. }
  83. public function testNameAndVersionCanBeRetrieved(): void
  84. {
  85. $this->assertNotEmpty($this->env->getNameWithVersion());
  86. }
  87. public function testGetNameReturnsPhpdbgWhenRunningOnPhpdbg(): void
  88. {
  89. $this->markTestSkippedWhenNotRunningOnPhpdbg();
  90. $this->assertSame('PHPDBG', $this->env->getName());
  91. }
  92. /**
  93. * @requires PHP
  94. */
  95. public function testGetNameReturnsPhpdbgWhenRunningOnPhp(): void
  96. {
  97. $this->markTestSkippedWhenRunningOnPhpdbg();
  98. $this->assertSame('PHP', $this->env->getName());
  99. }
  100. public function testNameAndCodeCoverageDriverCanBeRetrieved(): void
  101. {
  102. $this->assertNotEmpty($this->env->getNameWithVersionAndCodeCoverageDriver());
  103. }
  104. /**
  105. * @requires PHP
  106. */
  107. public function testGetVersionReturnsPhpVersionWhenRunningPhp(): void
  108. {
  109. $this->assertSame(\PHP_VERSION, $this->env->getVersion());
  110. }
  111. /**
  112. * @requires PHP
  113. */
  114. public function testGetVendorUrlReturnsPhpDotNetWhenRunningPhp(): void
  115. {
  116. $this->assertSame('https://secure.php.net/', $this->env->getVendorUrl());
  117. }
  118. private function markTestSkippedWhenNotRunningOnPhpdbg(): void
  119. {
  120. if ($this->isRunningOnPhpdbg()) {
  121. return;
  122. }
  123. $this->markTestSkipped('PHPDBG is required.');
  124. }
  125. private function markTestSkippedWhenRunningOnPhpdbg(): void
  126. {
  127. if (!$this->isRunningOnPhpdbg()) {
  128. return;
  129. }
  130. $this->markTestSkipped('Cannot run on PHPDBG');
  131. }
  132. private function isRunningOnPhpdbg(): bool
  133. {
  134. return \PHP_SAPI === 'phpdbg';
  135. }
  136. }