Skip to content

Commit cd45d71

Browse files
committed
fix bug test set status code duplication
1 parent 6acaca6 commit cd45d71

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

tests/unit/ResponseTest.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,34 +271,32 @@ public function test_withStatus()
271271

272272
public function test_setStatusCode_less_than_min_status_code()
273273
{
274-
try {
275-
$this->getMethodSetStatusCode()->invokeArgs($this->response, [99]);
276-
} catch (InvalidArgumentException $exception) {
277-
$this->assertEquals(
278-
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),
279-
$exception->getMessage()
280-
);
281-
}
274+
$this->run_setStatusCode($this->getMethodSetStatusCode(), 99);
282275
}
283276

284277
public function test_setStatusCode_greater_than_max_status_code()
278+
{
279+
$this->run_setStatusCode($this->getMethodSetStatusCode(), 600);
280+
}
281+
282+
public function test_setStatusCode()
283+
{
284+
$this->run_setStatusCode($this->getMethodSetStatusCode(), 200);
285+
}
286+
287+
private function run_setStatusCode(\ReflectionMethod $method, $code)
285288
{
286289
try {
287-
$this->getMethodSetStatusCode()->invokeArgs($this->response, [600]);
290+
$method->invokeArgs($this->response, [$code]);
291+
$this->assertEquals($code, $this->response->getStatusCode());
288292
} catch (InvalidArgumentException $exception) {
289293
$this->assertEquals(
290-
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),
294+
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),
291295
$exception->getMessage()
292296
);
293297
}
294298
}
295299

296-
public function test_setStatusCode()
297-
{
298-
$this->getMethodSetStatusCode()->invokeArgs($this->response, [201]);
299-
$this->assertEquals(201, $this->response->getStatusCode());
300-
}
301-
302300
private function getMethodSetStatusCode()
303301
{
304302
$responseReflect = new ReflectionClass(Response::class);

0 commit comments

Comments
 (0)