Like many stories these days, this story started with a tweet from Stefan Koopmanschap.
Dear library author,
No, marking your classes final if I want to mock them for my unit test is NOT ok.
— Stefan Koopmanschap (@skoop) July 20, 2017
In short: you can’t mock classes defined as final with PHPUnit.
But how can you test a class properly that depends on such a final class, if you can’t mock it?
The solution is simple but it requires you to write a mocking class that uses reflection to override the blockade introduced by the final visibility.
This doesn’t solve the issue that you cannot mock final classes in PHPUnit, but it does give you a non-intrusive solution to test without having a dependency on other classes.