Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$defaultTheme being set via a Trait is not discovered. #773

Open
dpagini opened this issue Jun 12, 2024 · 1 comment
Open

$defaultTheme being set via a Trait is not discovered. #773

dpagini opened this issue Jun 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dpagini
Copy link

dpagini commented Jun 12, 2024

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);
@dpagini dpagini added the bug Something isn't working label Jun 12, 2024
@dpagini
Copy link
Author

dpagini commented Dec 3, 2024

Hmm... so I've revisited this problem recently, and granted setting this property via a method I view as an edge case, I think that simply setting the property via a trait would be less of an edge case, and that does not appear to work, either...

so if I have...

trait ThemeTestTrait {

  protected string $defaultTheme = 'stark';

}

If I include this trait in my test files, then PHPStan will still throw this error that the property is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant