PHPUnit – how to check for exceptions

If you know your method will (or should) throw an exception under certain circumstances, you may want to write a test to assure it happens.

One way is to use PHPUnit annotations:

And the other, the plain old assertion-like statement: