Category: PHP

Our choices to respect as much as possible the best practices, the SOLID principles, the Composition Over Inheritance approach and so on should never be affected by any issue with our test framework(s). As a developer, I should not remove a “final” statement just because “I don’t know how I will test a specific thing if I keep it”.

In this fictiv e application, we have a class User which takes as mandatory parameters an ID and a Currency.

We also decided to declare it as “final” because we don’t want to allow the rest of our application to extends it.

So if you have a lot of tests, you can also not use a PHPUnit Hook but, instead, calling the BypassFinals::enable() method in the specific tests where you need it, for instance in the setUp() method of the test class.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners