I have the following pseudo code
public function testSomething() {
// assert something
// assert something else
$this->setExpectedException(...);
// trigger my exception here
// do one last thing
}
The issue I see, code after the exception being triggered is never made. Is this correct?
This is just a general wondering here – if this is normal I will refactor my test to perform the try/catch directly and fail() the test if nothing is caught.
The code after the exception should not be made. Think of the
setExpectedExceptionas making the test into atry -- catchSo the code after the exception is thrown will not be executed.If you need to do/check things after the exception, you should catch it. Though one warning with your catch, be specific about what exception is being thrown. PHPUnit throws exceptions for failed tests and you could accidentally catch this exception which may result in your test falsely passing.
Update:
If the code that you are executing is cleaning up, consider also moving it into the tearDown method of the test.