PHPUnit 9.5 migration when upgrading to Silverstripe CMS Recipe 4.10

Hey everyone, we’re in the final stage of wrapping the Silverstripe CMS 4.10 release which should be landing some time next week. As we’ve already mentioned, the SIlverstripe CMS 4.10 release will require you to migrate your test coverage to PHPUnit 9.5 if you want to run your tests with PHP 8.

We thought it could be useful to have an entry on the forum to track PHPUnit 9.5 conversations.

If you get stuck while migrating your Silverstripe CMS project to PHPUnit 9.5, start by:

If you can’t find what you are looking for and your question is simple, then try posting it on this thread. If you think your question is a bit more complex, then start a new thread and tag it with phpunit95.

Also, if you migrated your test coverage to PHPUnit 9.5 already, please share any lessons learned so others can benefit from your experience.

1 Like

Our experience migrating Silverstripe CMS Open Source modules to PHPUnit 9.5

As an indication, once we sorted the core architectural problem related to running Silverstripe CMS tests with PHPUnit 9.5, the migration itself took about 2 weeks worth of dev time. Our codebase is quite big and our test coverage is quite extensive. I would not expect most projects to need anywhere near that amount of time.

Most of the work was just a glorified global search and replace. The most common problems we came across have already been documented in the migration guide.

Tools and libraries that could be useful

yoast/phpunit-polyfills is a library that restores some APIs that have been removed from PHPUnit 9. We decided not to use it to avoid adding more dependencies to Silverstripe CMS. However, there’s nothing stopping you from adding it to your project.

Rector is another tool you might want to look at. It can instantly upgrade old PHP code and handle automated refactorings. Rector has a PHPUnit rule set to upgrade your test cases. We only realise it could be useful after we were done migrating all our tests, but that shouldn’t stop you from giving it a go.