> I don't like these limitations either, but testing is an integral part > of development, and we need to code in a way that facilitates testing.
This is especially true for e.g. static methods, but here we'd be renouncing to a possibly useful feature. > Why do methods ever "have" to be final? If you want to make sure that any subclass won't ever change the implementation of a method, and thus all callers know what to expect from calling a final method. I see finals as a sort of safeguard to help write better code, like e.g. typehints. > That would be a nice solution if it works well. If someone wants to > volunteer to try to get it working, then we won't need to have this > discussion. But until someone does, the question remains. IMHO this would be a perfect compromise. I've filed T231419 for that, and I also think that before discussing any further, we should try to see if we can install that tool. Il giorno mer 28 ago 2019 alle ore 09:30 Aryeh Gregor <a...@aryeh.name> ha scritto: > On Tue, Aug 27, 2019 at 11:53 PM Daimona <daimona.w...@gmail.com> wrote: > > Personally, I don't like these limitations in PHPUnit and the like. IMHO, > > they should never be a reason for changing good code. > > I don't like these limitations either, but testing is an integral part > of development, and we need to code in a way that facilitates testing. > In each case we need to make a cost-benefit analysis about what's best > for the project. The question is whether there's any benefit to using > final that outweighs the cost to testability. > > > And sometimes, methods have to be final. > > Why do methods ever "have" to be final? Someone who installs an > extension accepts that they get whatever behavior changes the > extension makes. If the extension does something we don't want it to, > it will either work or not, but that's the extension's problem. > > This is exactly the question: why do we ever want methods to be final? > Is there actually any benefit that outweighs the problems for testing? > > > Anyway, some time ago I came across [1], which allows mocking final > methods > > and classes. IIRC, it does that by removing the `final` keywords from the > > tokenized PHP code. I don't know how well it works, nor if it could > degrade > > performance, but if it doesn't we could bring it in via composer. > > That would be a nice solution if it works well. If someone wants to > volunteer to try to get it working, then we won't need to have this > discussion. But until someone does, the question remains. > > _______________________________________________ > Wikitech-l mailing list > Wikitech-l@lists.wikimedia.org > https://lists.wikimedia.org/mailman/listinfo/wikitech-l -- https://meta.wikimedia.org/wiki/User:Daimona_Eaytoy "Daimona" is not my real name -- he/him _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l