Trying to port a Drupal 7 module to 9 with accompanying test and getting this error immediately when running it:
PHP Fatal error: Type of Drupal\KernelTests\Core\Entity\EntityKernelTestBase::$modules must be array (as in class Drupal\KernelTests\KernelTestBase) in /var/www/html/docroot/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php on line 12
The test:
class MyModuleTest extends EntityKernelTestBase {
use NodeCreationTrait;
/**
* @var \Drupal\mymodule\Query\YearsQuery
*/
protected $query;
/**
* @var array $modules
*/
protected static $modules = [
'node',
'mymodule',
'mymodule_test',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
...
I checked around some of the core classes - the $modules declaration looks the same. Note that I am using PHPUnit 9.
public
rather thanprotected
MessageEntityTest
.array
type. Doespublic static $modules
work? The class you're inheriting from declares$modules
aspublic
, maybe the trouble is being caused by the change to the visibility and/or typepublic
- I definitely wasn't suggesting it should be public, they were just debug suggestions to see if the modifier was causing it :) But as you obviously feel strongly about it I'll take that on board, cheers for the tip!