Version 12 of the PHP testing framework PHPUnit is scheduled to be released in early February 2025. iX talks to Sebastian Bergmann, the initiator, lead developer and maintainer of the project, about the current development status, upcoming changes and individual features of the upcoming release.
Advertisement
Sebastian Bergmann has been an open source guy from the beginning. He shares his experiences in publications and conferences. He is also the co-founder and principal consultant of The PHP Consulting Company (thePHP.cc).
iX: PHPUnit 12 expected to be released in February 2025: What is the current development status?
Sebastian Bergmann: A new major version like PHPUnit 12 is released on the first Friday of February every year. Therefore the release of PHPUnit 12.0 is scheduled for February 7, 2025.
Releases like PHPUnit 12.0 are primarily for cleanup and provide an annual opportunity to make changes that are not backwards compatible. For example, features marked as “deprecated” in the previous version have been removed.
All planned changes that are not backward compatible have already been applied to the main branch of the PHPUnit repository on GitHub. The current development status in this regard is what can be expected when PHPUnit 12 is released.
personal highlights
iX: Which features of the new version are your personal highlights?
Sebastian Bergmann: A new version like PHPUnit 12.0 usually doesn’t bring many new features, because it forms the basis of the feature release of the year in February. There are some small new features in PHPUnit 12.0 to be able to control code coverage even better through attributes.
My personal highlight of PHPUnit 12 is not a new feature, but the result of cleanup, conversion, and improvement work over the past few years: test stubs are finally clearly separated from mock objects.
Sebastian Bergmann, author of the PHP framework PHPUnit and co-founder of thePHP.cc.
Brief digression: Object-oriented programming has different types of objects: services, entities, and value objects, for example. Services encapsulate processes, these could be business processes or more technical things like loading and saving data. Ideally, services implement an interface.
While testing, we use the actual implementation of that interface if we want to test that implementation. When we want to test a component that depends on an interface we use the test stub of this interface. When we want to test communication between cooperating objects we use a mock object of the interface.
When test doubles were introduced into the test frameworks of that time about 20 years ago and later became popular, the terms test stub and mock object were still interchangeable. For this reason, PHPUnit initially offered only one API, the method getMock()
To make test doubles. This was confusing and that’s why we’ve been working a lot on the API for test doubles over the last few years.
When reading test code, it is important to understand what it does and why it does it. For example, if a dependency is replaced by a test double for testing purposes, it is important to know why this is happening. If the component under test is to be isolated from only one dependency, a test stub should be used. If communication between objects is to be specified and/or verified, a mock object is needed. If an API is used always and everywhere in the test code to create mock objects, it is only at a second or third glance that you can see what is being tested. This is now clear due to the strict separation of APIs for creating test stubs and mock objects.
iX: How can developers prepare for PHPUnit 12?
Sebastian Bergmann: Since the changes that are not backwards compatible with PHPUnit 11 have already been implemented (see above), those who are brave can test their own tests with what becomes PHPUnit 12.
Of course, this is easier and less risky with the current stable version: if I can run my tests with PHPUnit 11.5 without the test runner complaining that I’m using obsolete functionality, then I know I’m Can run my tests with PHPUnit 12.
Madeleine Domogala asked questions.
(MDO)
