When one test creates a mock object, sets staticExpectation and throws an unexpected exception afterwards, the state of the mock object class, which is saved in a static member variable, is not cleaned up before invoking the next test. This can cause the next test which sets another staticExpectation on the same class to fail.

See https://github.com/sebastianbergmann/phpunit/issues/1143 for more details and an example test that demonstrates this issue.

The fix is to clean up the mock objects' state after each test is run or an exception is caught.