Skip to content

Commit 6acaca6

Browse files
committed
update test setStatusCode
1 parent e06013e commit 6acaca6

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/unit/ResponseTest.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,35 +269,45 @@ public function test_withStatus()
269269
$this->assertEquals(200, $this->response->getStatusCode());
270270
}
271271

272-
public function test_setStatusCode()
272+
public function test_setStatusCode_less_than_min_status_code()
273273
{
274-
$responseReflect = new ReflectionClass(Response::class);
275-
$method = $responseReflect->getMethod('setStatusCode');
276-
$method->setAccessible(true);
277-
278274
try {
279-
$method->invokeArgs($this->response, [99]);
275+
$this->getMethodSetStatusCode()->invokeArgs($this->response, [99]);
280276
} catch (InvalidArgumentException $exception) {
281277
$this->assertEquals(
282278
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),
283279
$exception->getMessage()
284280
);
285281
}
282+
}
286283

284+
public function test_setStatusCode_greater_than_max_status_code()
285+
{
287286
try {
288-
$method->invokeArgs($this->response, [600]);
287+
$this->getMethodSetStatusCode()->invokeArgs($this->response, [600]);
289288
} catch (InvalidArgumentException $exception) {
290289
$this->assertEquals(
291290
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),
292291
$exception->getMessage()
293292
);
294293
}
294+
}
295295

296-
$method->invokeArgs($this->response, [201]);
297-
296+
public function test_setStatusCode()
297+
{
298+
$this->getMethodSetStatusCode()->invokeArgs($this->response, [201]);
298299
$this->assertEquals(201, $this->response->getStatusCode());
299300
}
300301

302+
private function getMethodSetStatusCode()
303+
{
304+
$responseReflect = new ReflectionClass(Response::class);
305+
$method = $responseReflect->getMethod('setStatusCode');
306+
$method->setAccessible(true);
307+
return $method;
308+
}
309+
310+
301311
private function withError(Response $response, $code, $message = null)
302312
{
303313
$this->assertEquals($code, $response->getStatusCode());

0 commit comments

Comments
 (0)