bobc82 bobc82 - 5 months ago 71
PHP Question

phpunit - Help needed about risky tests

i'm implementing some tests for a site.
In a particular test, this result occurred:

"event": "test",
"suite": "Example_V_test",
"test": "Example_V_test::test_3",
"status": "error",
"time": 13.469105958939,
"trace": [
"file": "\/opt\/lampp\/htdocs\/buy\/application\/tests\/phpunit.phar",
"line": 569,
"function": "main",
"class": "PHPUnit_TextUI_Command",
"type": "::"
"message": "Risky Test: Test code or tested code did not (only) close its own output buffers",
"output": ""
}R 3 / 3 (100%)

Time: 25.76 seconds, Memory: 59.25MB

There was 1 risky test:

1) Example_V_test::test_3
Test code or tested code did not (only) close its own output buffers


OK, but incomplete, skipped, or risky tests!

My question is this: how to find the line of code that cause this 'issue'?


The message is reported if PHPUnit detects that the output buffering level at the end of a test method is different from the level at the beginning. This is due to the fact that it uses its own output buffer and checks that the test produces no output.

Because there is no option in PHPUnit to ignore this, you need to find the reason why the output buffering in your code was started but not ended (or ended too much) and fix that.

That might be really difficult to achieve because there is no hint, where output buffering is started, but you could use a full-text search on your source code (and libs) to identify candidates. Then look for Exceptions, which might break the normal program flow and so prevent ob_end_flush() (or similar) to be called.