phpunit Risky Test code or tested code did not (only) close its own output buffers

When I execute a phpunit test that has

@expectedException \Phalcon\Mvc\Dispatcher\Exception

thrown by \Phalcon\Mvc\Application::handle I get this message:

There was 1 risky test:

1) LicomTest\Api1\AppTest::testLicomApiAppRunMissedIndexController
Test code or tested code did not (only) close its own output buffers

/Users/xxx/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:151
/Users/xxx/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:103

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 1, Risky: 1.

I have ext-phalcon 1.3.4 and I can not upgrade now.

Any workarround to fix it?

thanks in advance



9.4k
edited May '15

Can you share the code snippit? I test expected exceptions this way. Basically, just a try/catch with a $this->fail() call if no exception is caught.

    public function testNonHttpsThrowsException()
    {
        unset($_SERVER["HTTPS"]);
        $dispatcher = DI::getDefault()->get("dispatcher");
        $stub = $this->getStub();

        try {
            $stub->beforeExecuteRoute($dispatcher);
        } catch(\Exception $e) {
            $this->assertEquals($e->getCode(), 403);
            $this->assertEquals($e->getMessage(), "Unauthorized");
            return;
        }

        $this->fail("HTTPS exception was not raised");
    }

Not sure of your exact situation, but I got a message like that once before, where perhaps the method was echo'ing data and I needed to do some obstart() obget_clean() calls.

edited May '15

Well, I do it in this way:

/**
 *
 * @small
 * @expectedException \Phalcon\Mvc\Dispatcher\Exception
 */
public function testLicomApiAppRunMissedIndexController()
{
    $api = new \Licom\Api1\App();
    $api->run();
}

Licom\Api1\App extends \Phalcon\Mvc\Application

method run() executes:

    $this->load();
    $this->handle();

method load() set inside DI a Router, Response, Request, Dispatcher and a View

method handle() is not overrided.