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
Reflection error: Drupal\Tests\PhpunitCompatibilityTrait not found #143
Comments
@MPParsley Can you follow this guide to make sure PHPStan has a way to discover those symbols? https://phpstan.org/user-guide/discovering-symbols Maybe you need to add some directories as |
Since we updated phpstan/phpstan to 0.12.43 we're seeing a lot of these Reflection errors when running drupal-check, here's another one:
Looks like something changed in ondrejmirtes/better-reflection that's triggering this. |
So can you follow the advice from my previous comment? https://github.com/mglaman/drupal-check/issues/186#issuecomment-691712665 Where are these classes/traits located and is discovering symbols configured correctly to find them? |
I've encountered same report as https://github.com/mglaman/drupal-check/issues/186#issuecomment-696295272. The This is noticeable after installing drupal core using composer |
@ondrejmirtes, the advice in mglaman/drupal-check#186 (comment) is too cumbersome to implement; Drupal/Symfony contain a large amount of classes that are using the same pattern:
Afaik, from a php perspective |
I'm just telling you that the right directories need to be put into |
Thanks @ondrejmirtes for the tip but the purpose of scanDirectories is to exclude files from being scanned but it should be fine to also scan the Symfony (and other) dependencies. Also, it would be really hard to define "the right directories" in a generic fashion up front. Note that the phpstan config for this project lives in https://github.com/mglaman/phpstan-drupal/blob/master/phpstan.neon |
You misunderstand how it works :) You don't want to analyze |
Well, now I'm confused ;-)
|
This exact case is tested here so it should work... https://github.com/phpstan/phpstan/tree/master/e2e/symfony-event |
Since phpstan 0.12.43 I'm seeing lots of these:
As a workaround I'm now downgrading phpstan/phpstan to 0.12.42 Seems like |
|
Drupal tests are autoloaded, see https://www.drupal.org/docs/develop/standards/psr-4-namespaces-and-autoloading-in-drupal-8 In 0.12.43 it's broken and in one patch version lower 0.12.42 it works, of course I could be wrong but there seems to be a bug in play.
There are no complaints about
PhpunitCompatibilityTrait lives in the same namespace as UnitTestCase but somehow it's not found. |
Please create a small reproducing repository that shows your problem, thank you. |
I've provided a repo that produces the https://github.com/pookmish/drupal-check-issue My steps to produce this repo:
You can also see that |
I looked into this: I've grabbed and modified the generated PHPStan config by drupal-check: parameters:
tipsOfTheDay: false
reportUnmatchedIgnoredErrors: false
excludes_analyse:
- */tests/Drupal/Tests/Listeners/Legacy/*
- */tests/fixtures/*.php
- */settings*.php
- */node_modules/*
drupal:
drupal_root: /Users/ondrej/Downloads/drupal-check-issue/web
customRulesetUsed: true
ignoreErrors:
- "#\\Drupal calls should be avoided in classes, use dependency injection instead#"
- "#Plugin definitions cannot be altered.#"
- "#Missing cache backend declaration for performance.#"
- "#Plugin manager has cache backend specified but does not declare cache tags.#"
bootstrapFiles:
- /Users/ondrej/Downloads/drupal-check-issue/vendor/mglaman/drupal-check/src/Command/../../error-bootstrap.php
includes:
- /Users/ondrej/Downloads/drupal-check-issue/vendor/mglaman/drupal-check/src/Command/../../../../phpstan/phpstan-deprecation-rules/rules.neon
- /Users/ondrej/Downloads/drupal-check-issue/vendor/mglaman/drupal-check/src/Command/../../../../mglaman/phpstan-drupal/extension.neon And simply added (following the Discovering symbols guide): scanFiles:
- /Users/ondrej/Downloads/drupal-check-issue/web/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php And it fixed the issue. So this is something that should be tackled in phpstan-drupal or drupal-check... I can't speak for why it worked before but this is clearly a misconfigured situation... |
Adding items to the This is not a maintainable approach, the phpstan-drupal & drupal-check are generic packages meant to support deprecation checking. If possible we should avoid coupling them to the internals (such as specific traits) of Drupal. We should first identify why phpstan |
Using I don't think that investigating why the trait in 0.12.43 cannot be found would be productive, the example project setup is such that it was never meant to work. |
… positivies and errors with upgrade_status deprecation discovery. More info: https://www.drupal.org/project/upgrade_status/issues/3172382 / Running "drush upgrade_status:analyze" leads to reflection errors "Experiencing similar errors. Found out the issue started happening after the latest release of phpstan/phpstan 0.12.43. Issue has been reported on the mglaman/drupal-check project: https://github.com/mglaman/drupal-check/issues/186 Quick fix for a project using this would be to manually require the previous version for the time being: composer require phpstan/phpstan:"0.12.42" https://github.com/mglaman/drupal-check/issues/186 https://phpstan.org/user-guide/discovering-symbols -> Downgrade seems like the best option now, although PHPStan dev points to fixing it by changing config based on this page
After the latest release of phpstan/phpstan 0.12.43 we run into reflection errors. Issue has been reported on the mglaman/drupal-check project: mglaman/drupal-check#186 Quick fix for a project using this would be to manually require the previous version for the time being: composer require phpstan/phpstan:"0.12.42"
* [#246] Add CI testing matrix against D8 and D9. * [#246] Remove wikimedia/composer-merge-plugin from CI as it's causing double updates and timing out. * [#246] Set core_version_requirement: ^8.7.7 || ^9, the same minimum as apigee_edge. * [#246] Use phpstan/phpstan 0.12.42 due to bug https://github.com/mglaman/drupal-check/issues/186 * [#246] Add $defaultTheme to functional/functionalJS tests. * [#246] Remove apigee_mock_client and replace with apigee_mock_api_client from apigee_edge. * [#246] Fix deprecations in kernel tests. * [#246] Fix deprecations in kernel tests. * [#246] Fix deprecations in functional tests. * [#246] Fix deprecations in functional JS tests. * [#246] Fix deprecations in apigee_m10n_add_credit_kernel. * [#246] Fix deprecations in apigee_m10n_add_credit and apigee_m10n_teams. * [#246] Require the latest D9 compatible version of apigee_edge.
Moving this to PHPStan Drupal |
#144 fixes the tests here and uncovers this bug |
So this path is covered in the autoloader provided by PHPStan Drupal.
\PHPStan\Drupal\DrupalAutoloader::addCoreNamespaces
For some reason the modifications done to the autoloader cause this to break. I wonder if its due to the trait having this line of code?
Going down the debug train to see why the autoloader hacks provided here broke things |
A similar issue existed with interface_exists in phpstan/phpstan#3521 |
@ondrejmirtes I'm trying to track down what's happening. Because the BetterReflection picks up the file.. kind of. (Made some screenshots in #145 ) But what I thought was interesting is this:
The trait error still occurs with a directory scan, but not with file scan. |
Weird, try to reproduce the issue with a vanilla PHPStan install, or in OptimizedDirectorySourceLocatorTest in phpstan-src... |
@ondrejmirtes 👍 will do. I'm trying to do some investigative work to see where/what/how. If it is in PHPStan's reflection code or the BetterReflection library. |
Merging the PR to get a conflict in so phpstan-drupal "works." The conflict is on Notes:
I can't easily tell why. But I want to just get a green release out and then continue debugging. |
I think the conflicted release isn't necessary. Does this problem apply to all phpstan-drupal users? If not then you're blocking them from getting other useful stuff and bugfixes... |
@ondrejmirtes it unfortunately is, right now. Across the board, all users are hitting reflection errors for It could be fixed if I could have the |
Going to try the latest PHPStan. This fix stuck out at me DependencyResolver - get current function reflection instead of obtaining it through ReflectionProvider (phpstan/phpstan-src@0e42941), #3909 |
I found the error! It's due to an alias defined for PHPUnit compatibility between PHPUnit 6 and 7. I also double checked, it's not due to it being defined dynamically.
When I comment out that line of code and target the trait directly, non-aliased, everything works fine: ie When I modify the statement to be hardcoded and not rely on |
From the PHPStan issue, the fix is to include the file in |
How is drupal-check installed?
drupal-check is installed as a dependency to my project
Environment:
Describe the bug
Reflection error occurs when using multiple arguments to test different files.
$ vendor/bin/drupal-check --deprecations --no-progress --drupal-root=../drupal --exclude-dir=vendor cookiebot_consent.module src/Event/LibrariesEvent.php
This issue was partially fixed in phpstan/phpstan#3522 but still occurs when using different files as arguments.
cookiebot_consent.module
src/Event/LibrariesEvent.php
Symfony\Contracts\EventDispatcher\Event
Console output
The text was updated successfully, but these errors were encountered: