phpstan-magento: Failure with `phpstan/phpstan-phpunit` and PHPStan cache usage

Hi, I’m using this extension together with phpstan/phpstan-phpunit.

bitexpert/phpstan-magento         v0.29.0 PHPStan Magento Extension
phpstan/phpstan                   1.10.7  PHPStan - PHP Static Analysis Tool
phpstan/phpstan-phpunit           1.3.10  PHPUnit extensions and rules for PHPStan

Without PHPStan cache, everything works fine. If I enable PHPStan cache, I receive get the following error on the second run, where that cache is used:

In ExtensionInterfaceAutoloader.php line 93:
                                                                                                            
  [InvalidArgumentException]                                                                                
  PHPStan\PhpDoc\PHPUnit\MockObjectTypeNodeResolverInterface does not exist and has no extension interface  
                                                                                                            

Exception trace:
  at /opt/composer/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionInterfaceAutoloader.php:93
 bitExpert\PHPStan\Magento\Autoload\ExtensionInterfaceAutoloader->getFileContents() at /opt/composer/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionInterfaceAutoloader.php:69
 bitExpert\PHPStan\Magento\Autoload\ExtensionInterfaceAutoloader->autoload() at n/a:n/a
 ReflectionClass->__construct() at /opt/composer/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionAutoloader.php:87
 bitExpert\PHPStan\Magento\Autoload\ExtensionAutoloader->getFileContents() at /opt/composer/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionAutoloader.php:70
 bitExpert\PHPStan\Magento\Autoload\ExtensionAutoloader->autoload() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadFunctionsSourceLocator.php:41
 PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadFunctionsSourceLocator->locateIdentifier() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php:26
 PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php:33
 PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/DefaultReflector.php:32
 PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingReflector.php:45
 PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php:149
 PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php:35
 PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php:552
 PHPStan\Analyser\ResultCache\ResultCacheManager->getProjectExtensionFiles() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php:528
 PHPStan\Analyser\ResultCache\ResultCacheManager->save() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php:363
 PHPStan\Analyser\ResultCache\ResultCacheManager->PHPStan\Analyser\ResultCache\{closure}() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php:386
 PHPStan\Analyser\ResultCache\ResultCacheManager->process() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php:108
 PHPStan\Command\AnalyseApplication->analyse() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php:173
 PHPStan\Command\AnalyseCommand->execute() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php:259
 _PHPStan_e0e4f009c\Symfony\Component\Console\Command\Command->run() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php:870
 _PHPStan_e0e4f009c\Symfony\Component\Console\Application->doRunCommand() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php:261
 _PHPStan_e0e4f009c\Symfony\Component\Console\Application->doRun() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php:157
 _PHPStan_e0e4f009c\Symfony\Component\Console\Application->run() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan:124
 _PHPStan_e0e4f009c\{closure}() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan:125
 require() at /opt/composer/vendor/phpstan/phpstan/phpstan:8
 include() at /usr/local/bin/phpstan:120

analyse [-c|--configuration CONFIGURATION] [-l|--level LEVEL] [--no-progress] [--debug] [-a|--autoload-file AUTOLOAD-FILE] [--error-format ERROR-FORMAT] [-b|--generate-baseline [GENERATE-BASELINE]] [--allow-empty-baseline] [--memory-limit MEMORY-LIMIT] [--xdebug] [--fix] [--watch] [--pro] [--] [<paths>...]

My configuration is the following:

includes:
    - /opt/composer/vendor/bitexpert/phpstan-magento/extension.neon
    - /opt/composer/vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
    level: 7
    checkMissingIterableValueType: false
    tmpDir: ./volumes/phpstan
    bootstrapFiles:
        - ./src/vendor/autoload.php
    magento:
        magentoRoot: ./src

Any thoughts?

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 19 (7 by maintainers)

Most upvoted comments

Hi @shochdoerfer, thanks for your hint about ./volumes/phpstan and caching behavior about PHPStan. But the default caching behavior of PHPStan will not take into account, because it will run in docker. So I need to change the cache path. But I can try, what’s happened, if I use a volume on PHPStan default cache folder. I will also check the behavior without docker.

Thanks for opening your first issue here!

Weird problem, not exactly sure what is going on. Somehow the Extension Attribute Autoloaders get triggered even though the classname PHPStan\PhpDoc\PHPUnit\MockObjectTypeNodeResolverInterface does not match the regex in both autoloaders.

Let me try to run a few tests to see if I can reproduce the problem somehow.