diff --git a/ChangeLog-7.2.md b/ChangeLog-7.2.md index 0b1a1397d6f..b778c36d8a4 100644 --- a/ChangeLog-7.2.md +++ b/ChangeLog-7.2.md @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 7.2 release series are documented in this fil ### Fixed * Fixed [#3189](https://github.com/sebastianbergmann/phpunit/issues/3189): PHPUnit 7.2 potentially leaves a messy libxmlerror state +* Fixed [#3199](https://github.com/sebastianbergmann/phpunit/pull/3199): Code Coverage for PHPT tests does not work when PHPDBG is used ## [7.2.6] - 2018-06-21 diff --git a/src/Runner/PhptTestCase.php b/src/Runner/PhptTestCase.php index 8fd4daa6780..2e8f7f29f00 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(); @@ -475,7 +475,7 @@ private function render(string $code): string private function getCoverageFiles(): array { - $baseDir = \dirname($this->filename) . \DIRECTORY_SEPARATOR; + $baseDir = \dirname(\realpath($this->filename)) . \DIRECTORY_SEPARATOR; $basename = \basename($this->filename, 'phpt'); return [ @@ -484,7 +484,7 @@ private function getCoverageFiles(): array ]; } - private function renderForCoverage(array &$settings): void + private function renderForCoverage(string &$job): void { $files = $this->getCoverageFiles(); @@ -516,17 +516,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 @@ -534,6 +529,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/Filter.php b/src/Util/Filter.php index e317471ab52..e57055bafd3 100644 --- a/src/Util/Filter.php +++ b/src/Util/Filter.php @@ -54,6 +54,7 @@ public static function getFilteredStacktrace(\Throwable $t): string foreach ($eTrace as $frame) { if (isset($frame['file']) && \is_file($frame['file']) && + (empty($GLOBALS['__PHPUNIT_ISOLATION_BLACKLIST']) || !\in_array($frame['file'], $GLOBALS['__PHPUNIT_ISOLATION_BLACKLIST'])) && !$blacklist->isBlacklisted($frame['file']) && ($prefix === false || \strpos($frame['file'], $prefix) !== 0) && $frame['file'] !== $script) { diff --git a/src/Util/PHP/AbstractPhpProcess.php b/src/Util/PHP/AbstractPhpProcess.php index 99a7907450c..fba0b9600b8 100644 --- a/src/Util/PHP/AbstractPhpProcess.php +++ b/src/Util/PHP/AbstractPhpProcess.php @@ -180,19 +180,22 @@ public function getCommand(array $settings, string $file = null): string $command .= $this->settingsToParameters($settings); if (\PHP_SAPI === 'phpdbg') { - $command .= ' -qrr '; + $command .= ' -qrr'; - if ($file) { - $command .= '-e ' . \escapeshellarg($file); - } else { - $command .= \escapeshellarg(__DIR__ . '/eval-stdin.php'); + if (!$file) { + $command .= 's='; } - } elseif ($file) { - $command .= ' -f ' . \escapeshellarg($file); + } + + if ($file) { + $command .= ' ' . \escapeshellarg($file); } if ($this->args) { - $command .= ' -- ' . $this->args; + if (!$file) { + $command .= ' --'; + } + $command .= ' ' . $this->args; } if ($this->stderrRedirection === true) { 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}'; diff --git a/src/Util/PHP/Template/TestCaseClass.tpl.dist b/src/Util/PHP/Template/TestCaseClass.tpl.dist index d00bd780c57..75ceda3820d 100644 --- a/src/Util/PHP/Template/TestCaseClass.tpl.dist +++ b/src/Util/PHP/Template/TestCaseClass.tpl.dist @@ -58,6 +58,7 @@ function __phpunit_run_isolated_test() $output = $test->getActualOutput(); } + ini_set('xdebug.scream', 0); @rewind(STDOUT); /* @ as not every STDOUT target stream is rewindable */ if ($stdout = stream_get_contents(STDOUT)) { $output = $stdout . $output; diff --git a/src/Util/PHP/Template/TestCaseMethod.tpl.dist b/src/Util/PHP/Template/TestCaseMethod.tpl.dist index 28d9b9890f0..b39938d3b09 100644 --- a/src/Util/PHP/Template/TestCaseMethod.tpl.dist +++ b/src/Util/PHP/Template/TestCaseMethod.tpl.dist @@ -60,6 +60,7 @@ function __phpunit_run_isolated_test() $output = $test->getActualOutput(); } + ini_set('xdebug.scream', '0'); @rewind(STDOUT); /* @ as not every STDOUT target stream is rewindable */ if ($stdout = stream_get_contents(STDOUT)) { $output = $stdout . $output; diff --git a/tests/Regression/GitHub/1348.phpt b/tests/Regression/GitHub/1348.phpt index 1df41a25300..f49d9da7271 100644 --- a/tests/Regression/GitHub/1348.phpt +++ b/tests/Regression/GitHub/1348.phpt @@ -2,7 +2,7 @@ https://github.com/sebastianbergmann/phpunit/issues/1348 --SKIPIF-- diff --git a/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap-php73.phpt b/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap-php73.phpt index 96a18a76fcd..2b5e4f9f0ac 100644 --- a/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap-php73.phpt +++ b/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap-php73.phpt @@ -28,20 +28,10 @@ Time: %s, Memory: %s There were 2 errors: 1) Issue2591_SeparateFunctionNoPreserveTest::testChangedGlobalString -PHPUnit\Framework\Exception: PHP Fatal error: Uncaught Error: Class 'PHPUnit\Framework\TestCase' not found in %s/SeparateFunctionNoPreserveTest.php:%d -Stack trace: -#0 Standard input code(31): require_once() -#1 Standard input code(110): __phpunit_run_isolated_test() -#2 {main} - thrown in %s on line %d - +PHPUnit\Framework\Exception: %sUncaught Error%sin %s +%a 2) Issue2591_SeparateFunctionNoPreserveTest::testGlobalString -PHPUnit\Framework\Exception: PHP Fatal error: Uncaught Error: Class 'PHPUnit\Framework\TestCase' not found in %s:%d -Stack trace: -#0 Standard input code(31): require_once() -#1 Standard input code(110): __phpunit_run_isolated_test() -#2 {main} - thrown in %s on line %d - +PHPUnit\Framework\Exception: %sUncaught Error%sin %s +%a ERRORS! Tests: 2, Assertions: 0, Errors: 2. diff --git a/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap-xdebug.phpt b/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap-xdebug.phpt index 3182f878510..21e65dd07c9 100644 --- a/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap-xdebug.phpt +++ b/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap-xdebug.phpt @@ -26,14 +26,12 @@ Time: %s, Memory: %s There were 2 errors: 1) Issue2591_SeparateFunctionNoPreserveTest::testChangedGlobalString -PHPUnit\Framework\Exception: PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found %s -PHP Stack trace: +PHPUnit\Framework\Exception:%sPHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found %s +%SPHP Stack trace:%S %a - 2) Issue2591_SeparateFunctionNoPreserveTest::testGlobalString -PHPUnit\Framework\Exception: PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found %s -PHP Stack trace: +PHPUnit\Framework\Exception:%sPHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found %s +%SPHP Stack trace:%S %a - ERRORS! Tests: 2, Assertions: 0, Errors: 2. diff --git a/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap.phpt b/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap.phpt index 465004db7ad..b82f22466a0 100644 --- a/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap.phpt +++ b/tests/Regression/GitHub/2591-separate-function-no-preserve-no-bootstrap.phpt @@ -28,10 +28,10 @@ Time: %s, Memory: %s There were 2 errors: 1) Issue2591_SeparateFunctionNoPreserveTest::testChangedGlobalString -PHPUnit\Framework\Exception: PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found %s - +PHPUnit\Framework\Exception:%sPHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found %s +%A 2) Issue2591_SeparateFunctionNoPreserveTest::testGlobalString -PHPUnit\Framework\Exception: PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found %s - +PHPUnit\Framework\Exception:%sPHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found %s +%A ERRORS! Tests: 2, Assertions: 0, Errors: 2. diff --git a/tests/Regression/GitHub/873.phpt b/tests/Regression/GitHub/873.phpt index 96ea6b5410c..f0048978471 100644 --- a/tests/Regression/GitHub/873.phpt +++ b/tests/Regression/GitHub/873.phpt @@ -16,7 +16,6 @@ require __DIR__ . '/../../bootstrap.php'; PHPUnit\TextUI\Command::main(); ?> --EXPECTF-- - -Fatal error: Uncaught Exception: PHPUnit suppresses exceptions thrown outside of test case function in %s:%i +%AException: PHPUnit suppresses exceptions thrown outside of test case function in %s:%i Stack trace: %a diff --git a/tests/TextUI/code-coverage-phpt.phpt b/tests/TextUI/code-coverage-phpt.phpt index f1d577e54ed..c32817b7be5 100644 --- a/tests/TextUI/code-coverage-phpt.phpt +++ b/tests/TextUI/code-coverage-phpt.phpt @@ -34,10 +34,10 @@ Code Coverage Report:%w %w Summary:%w Classes: 100.00% (2/2)%w - Methods: 100.00% (6/6)%w - Lines: 100.00% (12/12) + Methods: 100.00% (%d/%d)%w + Lines: 100.00% (%d/%d) CoveredClass - Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 7/ 7) + Methods: 100.00% ( %d/ %d) Lines: 100.00% ( %d/ %d) CoveredParentClass - Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 5/ 5) + Methods: 100.00% ( %d/ %d) Lines: 100.00% ( %d/ %d) diff --git a/tests/TextUI/fatal-isolation.phpt b/tests/TextUI/fatal-isolation.phpt index 4aa908a6ab3..bfa7340879e 100644 --- a/tests/TextUI/fatal-isolation.phpt +++ b/tests/TextUI/fatal-isolation.phpt @@ -19,7 +19,6 @@ Time: %s, Memory: %s There was 1 error: 1) FatalTest::testFatalError -%s - +%a ERRORS! Tests: 1, Assertions: 0, Errors: 1. diff --git a/tests/Util/PHP/AbstractPhpProcessTest.php b/tests/Util/PHP/AbstractPhpProcessTest.php index 5544a0985e9..862d5ea2dbd 100644 --- a/tests/Util/PHP/AbstractPhpProcessTest.php +++ b/tests/Util/PHP/AbstractPhpProcessTest.php @@ -55,7 +55,7 @@ public function testShouldUseGivenSettingsToCreateCommand(): void 'display_errors=1', ]; - $expectedCommandFormat = '%s -d %callow_url_fopen=1%c -d %cauto_append_file=%c -d %cdisplay_errors=1%c'; + $expectedCommandFormat = '%s -d %callow_url_fopen=1%c -d %cauto_append_file=%c -d %cdisplay_errors=1%c%S'; $actualCommand = $this->phpProcess->getCommand($settings); $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); @@ -75,7 +75,7 @@ public function testShouldUseArgsToCreateCommand(): void { $this->phpProcess->setArgs('foo=bar'); - $expectedCommandFormat = '%s -- foo=bar'; + $expectedCommandFormat = '%s foo=bar'; $actualCommand = $this->phpProcess->getCommand([]); $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand); @@ -83,8 +83,7 @@ public function testShouldUseArgsToCreateCommand(): void public function testShouldHaveFileToCreateCommand(): void { - $argumentEscapingCharacter = \DIRECTORY_SEPARATOR === '\\' ? '"' : '\''; - $expectedCommandFormat = \sprintf('%%s -%%c %1$sfile.php%1$s', $argumentEscapingCharacter); + $expectedCommandFormat = '%s %cfile.php%c'; $actualCommand = $this->phpProcess->getCommand([], 'file.php'); $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand);