From 6ce4f947eae4dfe21c692242a53fc92f6dc1519e Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Tue, 4 Apr 2017 10:31:47 +0200 Subject: [PATCH] refactored WebTestCase into a trait --- Test/JsonTestTrait.php | 44 ++++++++++++++++++++++++++++++++++++++++++ Test/WebTestCase.php | 27 +------------------------- 2 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 Test/JsonTestTrait.php 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; }