phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

No <system-out> with @runTestsInSeparateProcesses and --log-junit

Open DelphiXE5 opened this issue 3 years ago • 2 comments

Q A
PHPUnit version 9.5.4
PHP version 7.4.19
Installation Method Composer / PHAR

Summary

There is no <system-out> Tag in Junit logging if the Testcase is run in a separate process. (@runTestsInSeparateProcesses)

Current behavior

If you have a print/echo/var_dump etc. in a TestCase that is run in separated processes you get no in junit-log.

How to reproduce

Write a test case with @runTestsInSeparateProcesses, make an print in a test function, and fail afterward. Run it with --log-junit option. This should give you an output in the console but no <system-out> in the xml.

Expected behavior

If you have a print/echo/var_dump etc. in a TestCase that is run in separated processes you get a <system-out> in junit-log.

Error Analytics

The "normal" behavior is achieved with setting the private $output variable in TestCase during runBare(). But if the Test is run in a separate process the process returns only the result and the output of the test (which is run like normal and has the private $output variable set). Then the function processChildResult() takes the handling of the output. But there is no remapping of the output to the actual test that is relevant for the Logger. The output only gets printed to the console (https://github.com/sebastianbergmann/phpunit/blob/add3f7e459eba2764088f49bb249de70c855666c/src/Util/PHP/AbstractPhpProcess.php#L363-L365).

Suggested Solution

Remap the output to $test that is passed into processChildResult(). This could be done through a setter in TestCase or with reflection. I suggest the setter method.

https://github.com/sebastianbergmann/phpunit/blob/add3f7e459eba2764088f49bb249de70c855666c/src/Util/PHP/AbstractPhpProcess.php#L297 Replace with the following line with:

$test->setOutput($childResult['output']);

And add the following function to https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/TestCase.php:

public function setOutput(string $output): void {
    $this->output = $output;
}

DelphiXE5 avatar Apr 08 '22 08:04 DelphiXE5

Reopened #4690

DelphiXE5 avatar Apr 08 '22 08:04 DelphiXE5

PR: #4954

DelphiXE5 avatar Apr 08 '22 08:04 DelphiXE5

In PHPUnit 10, the JUnit XML logfile no longer has <system-out> elements that contain the output printed to stdout by a test.

I do not think that the changes (adding a new method to TestCase, for instance) that would be required to make <system-out> work for tests run in isolated processes in PHPUnit 9.6 should be made.

sebastianbergmann avatar Feb 04 '23 07:02 sebastianbergmann