Skip to content

Commit

Permalink
Merge branch '7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 9, 2018
2 parents 159a008 + 0ce3e2c commit b0afce3
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 64 deletions.
1 change: 1 addition & 0 deletions ChangeLog-7.2.md
Expand Up @@ -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

Expand Down
21 changes: 10 additions & 11 deletions src/Runner/PhptTestCase.php
Expand Up @@ -150,7 +150,7 @@ public function run(TestResult $result = null): TestResult
}

if ($result->getCollectCodeCoverageInformation()) {
$this->renderForCoverage($settings);
$this->renderForCoverage($code);
}

Timer::start();
Expand Down Expand Up @@ -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 [
Expand All @@ -484,7 +484,7 @@ private function getCoverageFiles(): array
];
}

private function renderForCoverage(array &$settings): void
private function renderForCoverage(string &$job): void
{
$files = $this->getCoverageFiles();

Expand Down Expand Up @@ -516,24 +516,23 @@ 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
{
$files = $this->getCoverageFiles();
$coverage = @\unserialize(\file_get_contents($files['coverage']));

if ($coverage === false) {
$coverage = [];
}

foreach ($files as $file) {
@\unlink($file);
}
Expand Down
1 change: 1 addition & 0 deletions src/Util/Filter.php
Expand Up @@ -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) {
Expand Down
19 changes: 11 additions & 8 deletions src/Util/PHP/AbstractPhpProcess.php
Expand Up @@ -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) {
Expand Down
10 changes: 2 additions & 8 deletions src/Util/PHP/Template/PhptTestCase.tpl.dist
Expand Up @@ -3,7 +3,6 @@ use SebastianBergmann\CodeCoverage\CodeCoverage;

$composerAutoload = {composerAutoload};
$phar = {phar};
$autoPrependFile = {autoPrependFile};

ob_start();

Expand All @@ -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();
Expand All @@ -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}';
1 change: 1 addition & 0 deletions src/Util/PHP/Template/TestCaseClass.tpl.dist
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Util/PHP/Template/TestCaseMethod.tpl.dist
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Regression/GitHub/1348.phpt
Expand Up @@ -2,7 +2,7 @@
https://github.com/sebastianbergmann/phpunit/issues/1348
--SKIPIF--
<?php
if (defined('HHVM_VERSION')) {
if (defined('HHVM_VERSION') || defined('PHPDBG_VERSION')) {
print 'skip: PHP runtime required';
}
?>
Expand Down
Expand Up @@ -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.
Expand Up @@ -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.
Expand Up @@ -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.
3 changes: 1 addition & 2 deletions tests/Regression/GitHub/873.phpt
Expand Up @@ -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
8 changes: 4 additions & 4 deletions tests/TextUI/code-coverage-phpt.phpt
Expand Up @@ -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)
3 changes: 1 addition & 2 deletions tests/TextUI/fatal-isolation.phpt
Expand Up @@ -19,7 +19,6 @@ Time: %s, Memory: %s
There was 1 error:

1) FatalTest::testFatalError
%s

%a
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
7 changes: 3 additions & 4 deletions tests/Util/PHP/AbstractPhpProcessTest.php
Expand Up @@ -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);
Expand All @@ -75,16 +75,15 @@ 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);
}

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);
Expand Down

0 comments on commit b0afce3

Please sign in to comment.