The picture shows a light bulb lying on a wooden surface. The light bulb is lit and creates a warm atmosphere. Right next to the light bulb is a small pile of various old metal keys. The interplay between the glowing light bulb and the keys symbolically conveys the idea that ideas (light bulb) can be the key (bunch of keys) to new possibilities or solutions.

Most developers who work with PHPUnit on a daily basis know the basics inside out: assertSame(), #[Before], and perhaps a few data providers. But PHPUnit can do so much more. Under the hood, there are functions, options, and workflows that even experienced professionals have often never seen, let alone used.

In my presentation "So you think you know PHPUnit", I show how to discover and use these lesser-known features. These are not exotic gimmicks, but features that make your test code more robust, meaningful and maintainable. They help you get even more out of PHPUnit every day.

In this article, you will find the most important insights from the presentation: summarised concisely and ready to apply immediately.

  • Use the names of your tests to concisely and precisely describe the aspect of your software that they cover.

    Automated tests can do more than just verify whether your software works correctly. They can also serve as an executable specification and documentation of your software. The TestDox output should be understandable to your domain experts.

  • Use the --check-php-configuration CLI option to ensure that your PHP interpreter is properly configured for development and testing with PHPUnit.

  • Use the --generate-configuration CLI option to generate an XML configuration file for PHPUnit for your project that uses best practice defaults.

  • Use attributes such as #[CoversClass] to document the target a test case class intends to cover.

    PHPUnit uses this information, for example, to make reported code coverage information more precise and support test selection using the --covers CLI option.

  • Use the #[Small], #[Medium], and #[Large] attributes to document the scope of a test case class.

    PHPUnit uses this information, for example, to make reported code coverage information more precise and support test selection using the --group CLI option.

Finally, I would like to point out that despite its many features, PHPUnit is only one part of a successful testing strategy. You can find more interesting topics related to PHP development and modern testing methods in my other articles and presentations.

If you need assistance with implementing or optimising your tests, I also offer training and consulting services. Feel free to contact me so that we can work together to take your testing processes to the next level.