Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Test json output in Zend Framework

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?

like image 301
lyle Avatar asked Apr 05 '10 03:04

lyle


1 Answers

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();
like image 132
nuqqsa Avatar answered Oct 04 '22 22:10

nuqqsa