views:

158

answers:

1

The Zend Tutorial lists many assertions to check the output generated by a request.

http://framework.zend.com/manual/en/zend.test.phpunit.html

But they all seem to assume that the output is html. I need to test json output instead.

Are there any assertions helpful to check json, or is there at least a generic way to make assertions against the output? Anything that doesn't rely on the request outputting html?

+1  A: 

There are no assertion methods specific to JSON implemented in Zend_Test_PHPUnit. However, the first test you would might want to do is check that the JSON is valid, thus convert it to its original type (array/object). From then on you are in position to use PHPUnit's generic assertions to validate its contents.

UPDATE: To get the raw response body you can do the following (when extending Zend_Test_PHPUnit_ControllerTestCase):

$this->getResponse()->getBody();
nuqqsa
There's a response object that offers ways to check whether it's a redirect, or an exception and so on, and offers to parse it as html, but I can't find any way to get the raw response.
lyle
Please see the update in the answer.
nuqqsa
Yep, that's it, thank you! :) I always assumed 'getBody' would refer to the <body> tag of the html output, looks like that was lost in translation.
lyle