How catch all action output into a string?


I want to write some tests for a controller.

Actions of the controller prints JSON.

I tried to use functional tests with Selenium.

But Selenium class hasn’t method get a content of a page.

Also I tried to use caching. But the get method returns nothing.


    'cache' => array(





    $this->c->actionGetinfo($this->cs->skey, 'ios', '2000-10-10');


    echo "\nXXXXX\n" . Yii::app()->cache->get('xxx')  . "\nendxxx\n";

I’ve solved my problem.

There is my solution:

override Controller method afterRender

function afterRender($view, $output) {

$this->buffer = $output;


replace echo json_encode( array(…) )


class ClientController extends Controller {

public $layout = ‘//layout/json’;

$this->render(‘json’, array(‘answer’ => array …)));


<?= CJSON::encode($answer); ?>


<?= $content; ?>