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 (source). Most notably:
- MockBuilder::setMethods will be hard-deprecated (T278010);
- Assert::assertRegExp is hard-deprecated in favour of assertMatchesRegularExpression(), which however was also introduced in PHPUnit 9
- The TestListener interface will be removed in favour of hooks.
- 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.
- 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: