Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

/opt/lampp/htdocs/buy/application/tests/phpunit.phar:569

OK, but incomplete, skipped, or risky tests!

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

like image 333
bobc82 Avatar asked Jul 15 '16 15:07

bobc82


People also ask

What is risky test PHPUnit?

A test that is annotated with @covers and executes code that is not listed using a @covers or @uses annotation will be marked as risky when this check is enabled.

What is a risky test?

A test that emits output, for instance by invoking print in either the test code or the tested code, will be marked as risky when this check is enabled.

What is the PHPUnit XML configuration file used to organize tests?

The <testsuite> Element.

Where do I put PHPUnit test?

You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file.


1 Answers

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.

like image 132
JSchirrmacher Avatar answered Oct 06 '22 02:10

JSchirrmacher