diff --git a/Test/JsonTestTrait.php b/Test/JsonTestTrait.php new file mode 100644 index 0000000..aa85fd2 --- /dev/null +++ b/Test/JsonTestTrait.php @@ -0,0 +1,44 @@ + + */ +trait JsonTestTrait +{ + protected function assertJsonResponse($response, $statusCode = 200) + { + $this->assertEquals( + $statusCode, $response->getStatusCode(), + $response->getContent() + ); + $this->assertTrue( + $response->headers->contains('Content-Type', 'application/json'), + $response->headers + ); + } + + protected function jsonRequest($verb, $endpoint, array $data = array()) + { + $data = empty($data) ? null : json_encode($data); + + return $this->client->request($verb, $endpoint, + array(), + array(), + array( + 'HTTP_ACCEPT' => 'application/json', + 'CONTENT_TYPE' => 'application/json' + ), + $data + ); + } +} diff --git a/Test/WebTestCase.php b/Test/WebTestCase.php index 9ebf12e..027c75e 100644 --- a/Test/WebTestCase.php +++ b/Test/WebTestCase.php @@ -17,30 +17,5 @@ */ abstract class WebTestCase extends BaseWebTestCase { - protected function assertJsonResponse($response, $statusCode = 200) - { - $this->assertEquals( - $statusCode, $response->getStatusCode(), - $response->getContent() - ); - $this->assertTrue( - $response->headers->contains('Content-Type', 'application/json'), - $response->headers - ); - } - - protected function jsonRequest($verb, $endpoint, array $data = array()) - { - $data = empty($data) ? null : json_encode($data); - - return $this->client->request($verb, $endpoint, - array(), - array(), - array( - 'HTTP_ACCEPT' => 'application/json', - 'CONTENT_TYPE' => 'application/json' - ), - $data - ); - } + use JsonTestTrait; }