Skip to content

Commit

Permalink
update test setStatusCode
Browse files Browse the repository at this point in the history
  • Loading branch information
harryolx committed Feb 15, 2018
1 parent e06013e commit 6acaca6
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions tests/unit/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,35 +269,45 @@ public function test_withStatus()
$this->assertEquals(200, $this->response->getStatusCode());
}

public function test_setStatusCode()
public function test_setStatusCode_less_than_min_status_code()
{
$responseReflect = new ReflectionClass(Response::class);
$method = $responseReflect->getMethod('setStatusCode');
$method->setAccessible(true);

try {
$method->invokeArgs($this->response, [99]);
$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()
);
}
}

public function test_setStatusCode_greater_than_max_status_code()
{
try {
$method->invokeArgs($this->response, [600]);
$this->getMethodSetStatusCode()->invokeArgs($this->response, [600]);
} 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),
$exception->getMessage()
);
}
}

$method->invokeArgs($this->response, [201]);

public function test_setStatusCode()
{
$this->getMethodSetStatusCode()->invokeArgs($this->response, [201]);
$this->assertEquals(201, $this->response->getStatusCode());
}

private function getMethodSetStatusCode()
{
$responseReflect = new ReflectionClass(Response::class);
$method = $responseReflect->getMethod('setStatusCode');
$method->setAccessible(true);
return $method;
}


private function withError(Response $response, $code, $message = null)
{
$this->assertEquals($code, $response->getStatusCode());
Expand Down

0 comments on commit 6acaca6

Please sign in to comment.