phpstan-drupal
phpstan-drupal copied to clipboard
$defaultTheme being set via a Trait is not discovered.
Bug report
First, let me say that I think this is an edge case, so I really don't know if there's value in trying to solve this... would be totally OK if this gets closed as "wontfix".
In my particular issue, when Drupal announced that $defaultTheme
must be set for all tests, in my project we started setting this via a trait, but the trait sets the property at runtime. Given this is a very unique use case, I would be happy to just ignore this rule, so I opened #772 which would help me ignore it.
I'm not totally sure if this is a useful bug report for other reasons.. just to consider that the property may be set outside the test itself...?
Code snippet that reproduces the problem
Here is how I set $defaultTheme
via trait...
trait ThemeTestTrait {
/**
* {@inheritdoc}
*
* Set all custom tests to use stark by default.
*
* This was introduced in Drupal core v9 where all tests switched from the
* classy theme to an undefined theme.
*
* @see https://www.drupal.org/node/3083055
*/
protected function installDefaultThemeFromClassProperty(ContainerInterface $container): void {
if (!isset($this->defaultTheme)) {
$this->defaultTheme = 'stark';
}
parent::installDefaultThemeFromClassProperty($container);