From cd45d71cb000017881ff72cfb91813471b120b40 Mon Sep 17 00:00:00 2001 From: Harry Sitohang Date: Thu, 15 Feb 2018 12:23:10 +0700 Subject: [PATCH] fix bug test set status code duplication --- tests/unit/ResponseTest.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/unit/ResponseTest.php b/tests/unit/ResponseTest.php index c4ced78..487d867 100644 --- a/tests/unit/ResponseTest.php +++ b/tests/unit/ResponseTest.php @@ -271,34 +271,32 @@ public function test_withStatus() public function test_setStatusCode_less_than_min_status_code() { - try { - $this->getMethodSetStatusCode()->invokeArgs($this->response, [99]); - } catch (InvalidArgumentException $exception) { - $this->assertEquals( - sprintf('Invalid status code "%s"; must be an integer between %d and %d, inclusive', 99, Response::MIN_STATUS_CODE_VALUE, Response::MAX_STATUS_CODE_VALUE), - $exception->getMessage() - ); - } + $this->run_setStatusCode($this->getMethodSetStatusCode(), 99); } public function test_setStatusCode_greater_than_max_status_code() + { + $this->run_setStatusCode($this->getMethodSetStatusCode(), 600); + } + + public function test_setStatusCode() + { + $this->run_setStatusCode($this->getMethodSetStatusCode(), 200); + } + + private function run_setStatusCode(\ReflectionMethod $method, $code) { try { - $this->getMethodSetStatusCode()->invokeArgs($this->response, [600]); + $method->invokeArgs($this->response, [$code]); + $this->assertEquals($code, $this->response->getStatusCode()); } catch (InvalidArgumentException $exception) { $this->assertEquals( - sprintf('Invalid status code "%s"; must be an integer between %d and %d, inclusive', 600, Response::MIN_STATUS_CODE_VALUE, Response::MAX_STATUS_CODE_VALUE), + sprintf('Invalid status code "%s"; must be an integer between %d and %d, inclusive', $code, Response::MIN_STATUS_CODE_VALUE, Response::MAX_STATUS_CODE_VALUE), $exception->getMessage() ); } } - public function test_setStatusCode() - { - $this->getMethodSetStatusCode()->invokeArgs($this->response, [201]); - $this->assertEquals(201, $this->response->getStatusCode()); - } - private function getMethodSetStatusCode() { $responseReflect = new ReflectionClass(Response::class);