Yesterday, we've finally upgraded to PHPUnit 8 (T192167). However, PHPUnit 9 is scheduled for release on Feb 7th, which means that we can start thinking about it. IMHO, we shouldn't rush the upgrade (given that various repos are probably still incompatible with PHPUnit 8). However, I find it wise to start preparing now, instead of letting tech debt accumulate.
This is especially true because PHPUnit 9 will have several compat breaks ([[https://github.com/sebastianbergmann/phpunit/milestone/34|source]]). Most notably:
[] MockBuilder::setMethods will be hard-deprecated (T278010);
[x] The TestListener interface will be removed in favour of hooks.
[x] Migrate MediaWikiLoggerPHPUnitTestListener ([[https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/566829/|gerrit patch]])
[x] Migrate MediaWikiPHPUnitTestListener ([[https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/673704/|gerrit patch]])
[] ResultPrinter will become an interface. We subclass the current ResultPrinter to augment logs (the "logs generated by test case" lines); That should extend DefaultResultPrinter (introduced in PHPUnit 9.0.0) instead.
[x] The methods that were hard-deprecated in PHPUnit 8 (assertInternalType, assertAttribute*, assertArraySubset, ...) will be removed; shouldn't be a problem, related PHPCS sniffs have been in place for many months
[] It will **not** support PHP 7.2. As such, we cannot upgrade until T261872 is done.
[] Additional minor fixes:
[] Several traits declare createMock as abstract but the signature will change in PHPUnit 9 (`string` typehint added); the traits should probably not declare the method at all, and use `@method` or an if+throw. List: MockTitleTrait, MockAuthorityTrait, MockServiceDependenciesTrait (also `fail()`, but the signature is the same), HandlerTestTrait
[] MockHttpTrait redeclares getMockBuilder(). Same as above.
[] Our XML schema is outdated (`--migrate-configuration` to update it)
[] `@coversNothing` should be added to MediaWikiCoversValidator::testValidCovers
[] ApiTestCase uses `$this->contains()` which should become `$this->containsIdentical`
---
Optional things which might (or will) help with future upgrades, e.g. PHPUnit 10:
- Possibly avoid a custom printer
- Removing MediaWikiPHPUnitCommand and our custom entry point (T90875)
- Removing our PHPUnit extensions: MediaWikiHooksPHPUnitExtension (blocked on T278011), MediaWikiLoggerPHPUnitExtension (used in conjunction with the ResultPrinter)