Search code examples
phptestingmodel-view-controllercontrollerphpunit

How to capture PHPUnit command-line output?


enter image description here

Writing a unit test to my index controller, i need to capture the html exit from the console into an array or string in order to test it.

But i have no idea how to capture the exit from my phpunit console.

Any thoughts ?


Solution

  • Thanks to John comment about ob_get_clean i got the thing done like that:

    $userController = new Application\controllers\User;
    ob_start();     
    $userController->index();       
    $output = ob_get_clean();
    echo "Output: " . $output;