Skip to content
Advertisement

How to use expectException in PHPUnit?

I’m trying to test my Exception, or any other exception in PHP Unit.

JavaScript

Still fails:

JavaScript

What could be the problem?

Advertisement

Answer

The problem is that the exception is never thrown because you are catching it in the catch block. The correct code to test your exception would be this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement