diff --git a/src/Runner/PhptTestCase.php b/src/Runner/PhptTestCase.php index 70940704975..a2b501630ce 100644 --- a/src/Runner/PhptTestCase.php +++ b/src/Runner/PhptTestCase.php @@ -150,7 +150,7 @@ public function run(TestResult $result = null): TestResult } if ($result->getCollectCodeCoverageInformation()) { - $this->renderForCoverage($settings); + $this->renderForCoverage($code); } Timer::start(); @@ -488,7 +488,7 @@ private function getCoverageFiles(): array ]; } - private function renderForCoverage(array &$settings): void + private function renderForCoverage(string &$job): void { $files = $this->getCoverageFiles(); @@ -520,17 +520,12 @@ private function renderForCoverage(array &$settings): void 'phar' => $phar, 'globals' => $globals, 'job' => $files['job'], - 'coverageFile' => $files['coverage'], - 'autoPrependFile' => \var_export( - !empty($settings['auto_prepend_file']) ? $settings['auto_prepend_file'] : false, - true - ) + 'coverageFile' => $files['coverage'] ] ); - \file_put_contents($files['job'], $template->render()); - - $settings['auto_prepend_file'] = $files['job']; + \file_put_contents($files['job'], $job); + $job = $template->render(); } private function cleanupForCoverage(): array @@ -538,6 +533,10 @@ private function cleanupForCoverage(): array $files = $this->getCoverageFiles(); $coverage = @\unserialize(\file_get_contents($files['coverage'])); + if ($coverage === false) { + $coverage = []; + } + foreach ($files as $file) { @\unlink($file); } diff --git a/src/Util/PHP/Template/PhptTestCase.tpl.dist b/src/Util/PHP/Template/PhptTestCase.tpl.dist index 83261136eb0..14c3e7e6ef5 100644 --- a/src/Util/PHP/Template/PhptTestCase.tpl.dist +++ b/src/Util/PHP/Template/PhptTestCase.tpl.dist @@ -3,7 +3,6 @@ use SebastianBergmann\CodeCoverage\CodeCoverage; $composerAutoload = {composerAutoload}; $phar = {phar}; -$autoPrependFile = {autoPrependFile}; ob_start(); @@ -28,7 +27,7 @@ if (class_exists('SebastianBergmann\CodeCoverage\CodeCoverage')) { $coverage->start(__FILE__); } -register_shutdown_function(function() use ($coverage, $autoPrependFile) { +register_shutdown_function(function() use ($coverage) { $output = null; if ($coverage) { $output = $coverage->stop(); @@ -38,9 +37,4 @@ register_shutdown_function(function() use ($coverage, $autoPrependFile) { ob_end_clean(); -if ($autoPrependFile) { - require $autoPrependFile; - $includes = get_included_files(); - $GLOBALS['__PHPUNIT_ISOLATION_BLACKLIST'][] = array_pop($includes); - unset($includes); -} +require '{job}';