Skip to content

Commit

Permalink
fix bug test set status code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
harryolx committed Feb 15, 2018
1 parent 6acaca6 commit cd45d71
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions tests/unit/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cd45d71

Please sign in to comment.