I see lots of answers about how to use PHPUnit to test whether or not an exception is thrown for a method - that's great and fine.
For this code, I understand that @expectsException will allow me to test the try{} block and thing1(). How do I test the thing2()
and thing3()
bits?
try {
thing1();
}
catch (Exception $e) {
thing2();
thing3();
}
Here's what I have now that fails:
function myTest() {
$prophecy = $this->prophesize(Exception::CLASS);
$my_exception = $prophecy->reveal();
// more testing stuff
...
}
PHPUnit sees the reveal()
call as an unexpected exception, and quits before "more testing stuff".