Using anonymous classes to write simpler tests

Matthieu Napoli, author of PHP-DI and externals.io, wrote a post on how you can use anonymous classes to quickly create mocks, spies and fixtures.

Anonymous classes were added to PHP 7. This article intends to show how useful they can be for writing tests.

http://mnapoli.fr/anonymous-classes-in-tests/

Join 9,500+ smart developers

Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

Found something interesting to share? Submit a link to the community section.