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

PHPUnit\Framework\TestCase is not an interface #202

Closed
nicrodgers opened this issue Jan 29, 2021 · 9 comments
Closed

PHPUnit\Framework\TestCase is not an interface #202

nicrodgers opened this issue Jan 29, 2021 · 9 comments

Comments

@nicrodgers
Copy link

How is drupal-check installed?

drupal-check is installed as a dependency to my project

Environment:

  • OS: lando (macOSx)
  • PHP Version: 7.3
  • Drupal core: 8.9.13

Describe the bug
I recently ran composer update, and phpstan was updated to 0.12.70 and drupal-check 1.1.6

Before the update, I could run:
vendor/bin/drupal-check -d web/modules/custom

and not got any errors.
Now after the update, I get errors:


Line Block/ChildrenNavBlock.php


     Internal error: PHPUnit\Framework\TestCase is not an interface        
     Run PHPStan with --debug option and post the stack trace to:          
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md  

If I modify CheckCommand.php by adding --debug to the phpstan $command args and re-run, this is what I get:

/Volumes/www/cssiw/web/modules/custom/cssiw_utilities/src/Plugin/Block/ChildrenNavBlock.php
Fatal error: Uncaught ReflectionException: PHPUnit\Framework\TestCase is not an interface in /Volumes/www/cssiw/vendor/mglaman/phpstan-drupal/src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php:50
Stack trace:
#0 /Volumes/www/cssiw/vendor/mglaman/phpstan-drupal/src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php(50): ReflectionClass->implementsInterface('PHPUnit\\Framewo...')
#1 phar:https:///Volumes/www/cssiw/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(70): PHPStan\Rules\Drupal\GlobalDrupalDependencyInjectionRule->processNode(Object(PhpParser\Node\Expr\StaticCall), Object(PHPStan\Analyser\MutatingScope))
#2 phar:https:///Volumes/www/cssiw/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(91): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Expr\StaticCall), Object(PHPStan\Analyser\MutatingScope))
#3 phar:https:///Volumes/www/cssiw/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(389): PHPStan\Node\ClassStatementsGatherer->__invoke( in /Volumes/www/cssiw/vendor/mglaman/phpstan-drupal/src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php on line 50

Console output

Performing deprecation checks
Analyzing path: /Volumes/www/cssiw/web/modules/custom/cssiw_utilities/src/Plugin
Current working directory: /Volumes/www/cssiw
Using Drupal root: /Volumes/www/cssiw/web
Using vendor root: /Volumes/www/cssiw/vendor
PHPStan path: /Volumes/www/cssiw/vendor/phpstan/phpstan/phpstan.phar
PHPStan configuration path: /private/var/folders/0f/zwj32hqx79l1w28t2nnbh0gm0000gn/T/drupal_check_phpstan_1611930792.neon
PHPStan configuration:
parameters:
        tipsOfTheDay: false
        reportUnmatchedIgnoredErrors: false
        excludes_analyse:
                - */tests/Drupal/Tests/Listeners/Legacy/*
                - */tests/fixtures/*.php
                - */settings*.php
                - */node_modules/*

        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.#"

        drupal:
                drupal_root: /Volumes/www/cssiw/web

        customRulesetUsed: true
        bootstrapFiles:
                - /Volumes/www/cssiw/vendor/mglaman/drupal-check/error-bootstrap.php

includes:
        - /Volumes/www/cssiw/vendor/phpstan/phpstan-deprecation-rules/rules.neon
        - /Volumes/www/cssiw/vendor/mglaman/phpstan-drupal/extension.neon


Executing PHPStan
Result cache not used because of debug mode.
/Volumes/www/cssiw/web/modules/custom/cssiw_utilities/src/Plugin/Block/AddThisBlock.php
--- consumed 8 MB, total 78.5 MB
/Volumes/www/cssiw/web/modules/custom/cssiw_utilities/src/Plugin/Block/ChildrenNavBlock.php
Fatal error: Uncaught ReflectionException: PHPUnit\Framework\TestCase is not an interface in /Volumes/www/cssiw/vendor/mglaman/phpstan-drupal/src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php:50
Stack trace:
#0 /Volumes/www/cssiw/vendor/mglaman/phpstan-drupal/src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php(50): ReflectionClass->implementsInterface('PHPUnit\\Framewo...')
#1 phar:https:///Volumes/www/cssiw/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(70): PHPStan\Rules\Drupal\GlobalDrupalDependencyInjectionRule->processNode(Object(PhpParser\Node\Expr\StaticCall), Object(PHPStan\Analyser\MutatingScope))
#2 phar:https:///Volumes/www/cssiw/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(91): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Expr\StaticCall), Object(PHPStan\Analyser\MutatingScope))
#3 phar:https:///Volumes/www/cssiw/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(389): PHPStan\Node\ClassStatementsGatherer->__invoke( in /Volumes/www/cssiw/vendor/mglaman/phpstan-drupal/src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php on line 50
Finished executing PHPStan
Unlinking PHPStan configuration
Return PHPStan exit code

@stevenspasbo
Copy link

Seeing this same error well, after reverting to phpstan to 0.12.42 (random version picked for testing), the issue disappeared.

@dmitrypro77
Copy link

I encountered with the same issue and after changing version of phpstan it works as expected.

@sheenasi
Copy link

likewise - changed version of phpstan to 0.12.42 in the drupal-check/composer.json and reinstalled composer, it worked like a charm.

@philwolstenholme
Copy link

See mglaman/phpstan-drupal#160

@mglaman
Copy link
Owner

mglaman commented Feb 5, 2021

We need to bump mglaman/phpstan-drupal to 0.12.8 to fix this.

@Dropa
Copy link

Dropa commented Mar 9, 2021

@mglaman consider locking up the phpstan version in phpstan-drupal. This has been appearing already few times.

This re-appears with phpstan 0.12.70 and newers (currently 0.12.81), and with the current composer requirement in phpstan-drupal is ^0.12.64, which means that if you have installed/updated Jan 27th, drupal-check is most likely broken for you.

Simple fix until phpstan version is locked by default is to manually require lower phpstan version.

@mglaman
Copy link
Owner

mglaman commented Mar 11, 2021

Locking phpstan can lead to other problems. That is one reason I shipped a phar for drupal-check, because it provides locked dependencies.

I've received funding, so drupal-check will get some love once I get phpstan-drupal stabilized more.

@mglaman
Copy link
Owner

mglaman commented Feb 2, 2022

This should be all fixed after the latest phpstan-drupal work.

@mglaman mglaman closed this as completed Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants