Should something this be a unit test or something else? Using Laravel 8
Solution 1:
if you need to check response code during unit test you can use assertStatus in your test. for the example:
$response = $this->getJson($program_url);
$response->assertStatus(404);
Or use Http::get and check status like this. (you can use this anywhere in the code, not only in the test):
$response = Http::get($program_url);
if($response->status()==404) {
........
}
Or you can use php function: get_headers. You can also use this anywhere in your code and it's a bit faster than the previous one:
private function pageExists($url) {
$headers=@get_headers($url);
return $headers && $headers[0] != 'HTTP/1.1 404 Not Found';
}
you can use this method like this:
if($this->pageExists($program_url)) {
.........
}