On Tue, Aug 27, 2019 at 6:55 PM Aryeh Gregor ayg@aryeh.name wrote:
I see that in some classes, like WANObjectCache, most methods are declared final. Why is this? [..]
The problem is that PHPUnit mocks can't touch final methods. [..]
What did you want to assert in this test?
I find there is sometimes a tendency for a test to needlessly duplicate the source code by being too strict on expecting exactly which method is called to the point that it becomes nothing but a more verbose version of the source code; always requiring a change to both.
Personally, I prefer a style of testing where it providers a simpler view of the code. More like a manual of how it should be used, and what observable outcome it should produce.
I think PHPUnit's assertion helpers for things like method()->once() are quite useful. But, personally, I almost never need them. And in the few occasions where I did use them, it's never a private, static or final method (which can't be mocked). In some cases, I accidentally tried to mock such method and found every time it was either because of pre-existing technical debt, or because I misunderstood the code, or because I was testing arbitrary implementation details.
As such, to perhaps help with the conversation, I'd like to have a practical example we can look at and compare potential solutions. Perhaps from WANObjectCache, or perhaps with something else.
-- Timo