By longwave on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.0.x
Introduced in version:
9.0.0
Issue links:
Description:
PHPUnit 8 introduced void return types on the following methods:
setUpBeforeClass()setUp()assertPreConditions()assertPostConditions()tearDown()tearDownAfterClass()onNotSuccessfulTest()
For example,
protected function setUp() {
becomes
protected function setUp(): void {
In order for tests to be compatible with both PHPUnit 6 and 7 (used in Drupal 8) and PHPUnit 8 (used in Drupal 9), a backward compatibility shim was added so these typehints are not yet required, but this compatibility shim will be removed in Drupal 10, or earlier if a newer version of PHPUnit means it is no longer viable to support.
If a test class extends another test that already type hints void, the code will need to update to require at least PHP 7.1, then just add (): void { return type hint.
Impacts:
Module developers
Comments
The ::tearDown(): void is required in 9.5 core
Faced it porting to Drupal 10 Email registration module which has tests with Commerce codebase
Ref #3306470-6: [9.1] Declaring ::tearDown without a void return typehint is deprecated