C3Test.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. use Codeception\Configuration;
  3. class C3Test extends \PHPUnit\Framework\TestCase
  4. {
  5. /**
  6. * @var string
  7. */
  8. public $c3 = null;
  9. /**
  10. * @var string
  11. */
  12. public $c3_dir = null;
  13. protected function setUp()
  14. {
  15. if (!extension_loaded('xdebug')) {
  16. $this->markTestSkipped('xdebug extension required for c3test.');
  17. }
  18. $this->c3 = Configuration::dataDir() . 'claypit/c3.php';
  19. $this->c3_dir = Codeception\Configuration::outputDir() . 'c3tmp/';
  20. @mkdir($this->c3_dir, 0777, true);
  21. $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE'] = 'test';
  22. $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG'] = 'debug';
  23. }
  24. protected function tearDown()
  25. {
  26. unset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG']);
  27. unset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE']);
  28. \Codeception\Util\FileSystem::deleteDir($this->c3_dir);
  29. }
  30. public function testC3CodeCoverageStarted()
  31. {
  32. if (defined('HHVM_VERSION')) {
  33. $this->markTestSkipped('This test fails on HHVM');
  34. }
  35. $_SERVER['REQUEST_URI'] = '/';
  36. include $this->c3;
  37. $this->assertInstanceOf('PHP_CodeCoverage', $codeCoverage);
  38. }
  39. public function testCodeCoverageRestrictedAccess()
  40. {
  41. unset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE']);
  42. include $this->c3;
  43. $this->assertFalse(isset($config_file));
  44. $this->assertFalse(isset($requested_c3_report));
  45. }
  46. public function testCodeCoverageCleanup()
  47. {
  48. $_SERVER['REQUEST_URI'] = '/c3/report/clear';
  49. $cc_file = $this->c3_dir . 'dummy.txt';
  50. file_put_contents($cc_file, 'nothing');
  51. include $this->c3;
  52. $this->assertEquals('clear', $route);
  53. $this->assertFileNotExists($cc_file);
  54. }
  55. public function testCodeCoverageHtmlReport()
  56. {
  57. if (defined('HHVM_VERSION')) {
  58. $this->markTestSkipped('Remote coverage HTML report does not work on HHVM');
  59. }
  60. $_SERVER['REQUEST_URI'] = '/c3/report/html';
  61. include $this->c3;
  62. $this->assertEquals('html', $route);
  63. $this->assertFileExists($this->c3_dir . 'codecoverage.tar');
  64. }
  65. public function testCodeCoverageXmlReport()
  66. {
  67. $_SERVER['REQUEST_URI'] = '/c3/report/clover';
  68. include $this->c3;
  69. $this->assertEquals('clover', $route);
  70. $this->assertFileExists($this->c3_dir . 'codecoverage.clover.xml');
  71. }
  72. public function testCodeCoverageSerializedReport()
  73. {
  74. $_SERVER['REQUEST_URI'] = '/c3/report/serialized';
  75. include $this->c3;
  76. $this->assertEquals('serialized', $route);
  77. $this->assertInstanceOf('PHP_CodeCoverage', $codeCoverage);
  78. }
  79. }