Skip to content

Commit

Permalink
Fix test and expectations with phpdbg sapi
Browse files Browse the repository at this point in the history
Fixes the following differences when running with phpdbg:

* phpdbg doesn't ignore the -- argument separator when passed to php
* phpdbg doesn't support display_errors=stderr, so errors go to STDOUT
* Tests that enable xdebug.scream affect process isolation in phpdbg
* Errors/Exceptions/Stacks are formatted slightly different in phpdbg
  • Loading branch information
kabel authored and sebastianbergmann committed Jul 9, 2018
1 parent caf45d9 commit 62734e7
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ before_script:

script:
- ./phpunit --coverage-clover=coverage.xml
- phpdbg -qrr ./phpunit --coverage-text
- ./phpunit --configuration ./build/travis-ci-fail.xml > /dev/null; if [ $? -eq 0 ]; then echo "SHOULD FAIL"; false; else echo "fail checked"; fi;
- xmllint --noout --schema phpunit.xsd phpunit.xml
- xmllint --noout --schema phpunit.xsd tests/_files/configuration.xml
Expand Down
12 changes: 9 additions & 3 deletions src/Util/PHP/AbstractPhpProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,18 @@ public function getCommand(array $settings, string $file = null): string
} else {
$command .= \escapeshellarg(__DIR__ . '/eval-stdin.php');
}
} elseif ($file) {
$command .= ' -f ' . \escapeshellarg($file);
} else {
if ($file) {
$command .= ' -f ' . \escapeshellarg($file);
}

if ($this->args) {
$command .= ' --';
}
}

if ($this->args) {
$command .= ' -- ' . $this->args;
$command .= ' ' . $this->args;
}

if ($this->stderrRedirection === true) {
Expand Down
1 change: 1 addition & 0 deletions src/Util/PHP/Template/TestCaseClass.tpl.dist
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.
4 changes: 2 additions & 2 deletions tests/Regression/GitHub/873.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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
%A
%SException: 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.
4 changes: 2 additions & 2 deletions tests/Util/PHP/AbstractPhpProcessTest.php
Original file line number Diff line number Diff line change
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,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);
Expand Down

0 comments on commit 62734e7

Please sign in to comment.