- 🇫🇷France gidel
Here's a patch made for the 9.5.3 release (From 2023-01-31 - 11:33pm 0e78230972c599be926cbb7baa5a77a2afa362a2).
According to the change record Updated to PHPUnit 9 → :
Drupal 9.1.x has updated to PHPUnit 9. Installs on PHP 7.3 will continue to use PHPUnit 8.4 for compatibility reasons.
As of PHPUnit 8, \PHPUnit\Framework\TestCase
added a void
return type hint to the following methods:
protected function setUp(): void
protected function tearDown(): void
public static function setUpBeforeClass(): void
protected function assertPostConditions(): void
protected function assertPreConditions(): void
(not currently used by core Drupal)public static function tearDownAfterClass(): void
(not currently used by core Drupal)protected function onNotSuccessfulTest(): void
(not currently used by core Drupal)See https://phpunit.de/announcements/phpunit-8.html
This issue is to correct the signature used for these methods in core, for all classes that extend \PHPUnit\Framework\TestCase
, which includes classes that extend \Drupal\Tests\UnitTestCase
, \Drupal\KernelTests\KernelTestBase
, and \Drupal\Tests\BrowserTestBase
.
Specifically, this issue is to ensure that the void return type hint is used and that the protected
visibility is declared properly. The protected
visibility mainly affects core's setUp()
and tearDown()
methods because there are still a large number of cases where public
has been improperly used.
None.
The void
return type hint technically constitutes an API change, but the protected
visibility does not - setUp()
and tearDown()
have been declared as protected in core Drupal since early in Drupal 7. Fixing visibility for these methods is just adhering to our existing API.
None.
On Drupal 9.0.7, I tried to run Upgrade Rector, and got the following fatal error:
PHP Fatal error: Declaration of Drupal\Tests\BrowserTestBase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /Users/dan/coding/drupal-ch/web/core/tests/Drupal/Tests/BrowserTestBase.php on line 388
I see that we applied fixes in #3114640: Declaration of Drupal\Tests\UnitTestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void → and 🐛 PhpUnit 8 tests breaking because of compatibility issue with setUp() Fixed but it looks like we missed this file and many others.
When I do a search for setUp() { I get 86 results in 86 files, do we want to patch all of them in this one issue?
The fix is to simply add the return type of void:
- protected function setUp() {
+ protected function setUp(): void {
Fixed
10.1 ✨
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Here's a patch made for the 9.5.3 release (From 2023-01-31 - 11:33pm 0e78230972c599be926cbb7baa5a77a2afa362a2).