I'm working on implementing test cases for our project to be included in our build script. This CakePHP 2.4 application is largely REST based and has been set to parse json extensions in its routes.php file. Here is an example of a typical function in our application:
public function index() {
$this->paginate = array(
'fields' => array('User.username', 'User.first_name', 'User.last_name', 'UserGroup.name','Location.name','User.id'),
'conditions' => array(
'active'=>1
),
'link' => array('UserGroup','Location')
);
$this->set('response', $this->RestApi->getResponse());
$this->set('_serialize','response');
}
This would return a json structure like this:
{"sEcho":1,"iTotalRecords":16,"iTotalDisplayRecords":14,"aaData":[["admin","Administrative"],["salesman","Salesman"]]}
So I expected when writing my test cases that in calling this URL I would receive a JSON response, and one of my tests would be to properly decode it and move on with validating the data. Problem is, the call to testAction returns nothing (I'ved tried telling it to return view and contents). The only way I am able to access the response is by looking at the return vars.
Example - Not Working:
$result = $this->testAction('/users/index.json',array(
'method' => 'GET',
'return' => 'contents'
));
var_dump($result); // NULL
Example - Is Working:
$result = $this->testAction('/users/index.json',array(
'method' => 'GET',
'return' => 'vars'
));
So what's the problem with looking at vars? Well for one its a little further than a real world example of how the application works. It also makes me a little worried about the architecture if I can't get a basic unit test to work as expected.
Please advise and thanks for reading!
EDIT: I should add that even when doing a testAction against a non rest url, such as one that just returns HTML, I still get no response. No HTML etc...