Version/copyright line output
| Q | A |
|---|---|
| PHPUnit version | 6.4.4 |
| PHP version | 7.1.15 |
| Installation Method | Composer |
Copyright line is always printed, even when format printer is specified, which seems odd, since printer usage assumes that user wants to retrieve output in a specified format, to pipe it forward or to parse right away. That copyright line is getting in the way, requiring an additional parsing step, that seems really redundant.
I'm writing a wrapper for phpunit CLI invocation with XML printer, and I'm getting output of
PHPUnit 6.4.4 by Sebastian Bergmann and contributors.
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
... rest of the xml
</testsuites>
which I need to trim and parse just to get to actual XML. Is there a way to disable output of that version/copyright line?
~As a temporary «hack»:~ Your printer's write() mehtod could check if the actual string matches the one generated by PHPUnit\Runner\Version::getVersionString():
class YourXmlPrinter extends PHPUnit\Util\Printer implements PHPUnit\Framework\TestListener
{
public function write(string $buffer):void
{
if (Version::getVersionString() . "\n" === $buffer) {
return;
}
}
Update
PHPUnit\TextUI\TestRunner uses the Printer::write() method for even more informal output that can break your XML structure than just the copyright line. However it looks like this method can be considered for only informal output. So it's up to your implementation of the TestListener to write to standard output and ignore (or write to a log file) everything that is passed to ::write()