We’re looking at moving our Integration Tests for our API to CakePHP’s PHPUnit. We need to test that the returned values from the API are sane (valid JSON, etc…)
The helper methods on the IntegrationTestCase abstract class look useful, but from what I can tell there’s no way to actually read the response to one of these requests. Am I missing something?
It seems that without the helper methods provided by IntegrationTestCase it would be much harder to make requests. So what’s my best option here?
I just realised that I can do this by simply accessing $this->_response. At first I didn’t think I could do this because its visibility is protected, but then I realised that I can access it because my test inherits from IntegrationTestCase.
You can use the following methods along with some others
$this->assertResponseEquals('A complete string what you gona get') $this->assertResponseContains('A string what should be included in the repsonse') $this->assertResponseNotContains('A string what should not be in the response, like "You are loged in"') $this->assertEquals('rrd', $this -> viewVariable('username')); $this->assertContentType('application/json')
Perhaps the most basic assertion is $this->assertResponseOk()