Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Exotelis's avatar

Testing methods with abort() as last statement

Hey, I'm writing tests and stumpled over a weird behaiviour. Well maybe it's not weird, because I know why it happens but I don't know how to handle this. Lets say we have the following method/function:

protected function getUnknownUserResponse()
{
	abort(400, 'Unknown user');
} // <- is marked red in the coverage report

As mentioned in the comment, PHPUnit's coverage report marks the last curly bracket of the method red. I know the reason is, that this line can never be reached because af the abort() statement, but since abort() is the last line of the method shouldn't it be marked as tested?

I could prepend throw to the abort() call and it would work, but that feels a little bit hacky... Is der a best practise?

0 likes
3 replies
Wobbie's avatar

I'm currently experiencing the same issue. Did you find a solution @exotelis ?

Please or to participate in this conversation.