Summer Sale! All accounts are 50% off this week.

rephiscorth's avatar

Undefined method FatalError::getStatusCode(); using filp/whoops.

I recently updated my App\Exceptions\Handler::render() to use filp/whoops. It works perfectly on browser. Problem is when running phpunit and somethings goes wrong, I get undefined method ErrorException::getStatusCode() instead of the actual error.

I know the error emanates from this call, thing is every tutorial to use whoops says to do it this way.

// Inside Handler::render()
return new Response(
    $whoops->handleException($e),   // pretty page handler
    $e->getStatusCode(),
    $e->getHeaders()
);

How can I solve it?

0 likes
5 replies
mikebronner's avatar

You could dd($e) and see what is being passed in as an exception under PHPUnit. You could also check for the existence of $e->getStatusCode() using something like this:

if (method_exists('getStatisCode', $e) {
//throw whoops error here
}
rephiscorth's avatar
rephiscorth
OP
Best Answer
Level 2

Actually I just went for the default way, so I read into the parent's render method and just did as they did:

$fe = FlattenException::create($e);
return new Response(
    $whoops->handleException($e),
    $fe->getStatusCode(),
    $fe->getHeaders()
);
3 likes

Please or to participate in this conversation.