phpstan/phpdoc-parser

Custom Phpstan rule tests broken after update to 1.20.0 (still happens on 1.20.4)

gnutix opened this issue · 6 comments

Hello there,

Sorry if I should not be opening this new issue, but I can't comment on the original one (#188).

I too had to disable my custom PHPStan tests extending PHPStan\Testing\TypeInferenceTestCase since migrating to 1.20.0, and today I tried again to enable them on 1.20.4 and here's the errors I get :

1) Error
The data provider specified for App\Test\Unit\Infrastructure\Shared\PhpStan\Extensions\TypeInferenceTest::testAsserts is invalid.
Error: Undefined constant PHPStan\PhpDocParser\Lexer\Lexer::TOKEN_DOCTRINE_TAG
phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:118
phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:84
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/PhpDoc/PhpDocStringResolver.php:28
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:156
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:265
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:292
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:185
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:164
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:113
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php:258
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php:235
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1475
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:558
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:1519
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:574
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:338
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:49
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:78
/app/tests/unit/Infrastructure/Shared/PhpStan/Extensions/TypeInferenceTest.php:24

Let me know if there's anything more I can do.
gnutix

Hi, this looks like the autoloader got mixed up. You have multiple copies of phpdoc-parser in your project, in different versions. Some of them might be inside PHARs.

The latest version is 1.22.0. Try to upgrade everything relevant in your project so that everything uses this version.

I just did a composer update of all our dependencies before testing this again.. So I can't get more up-to-date than this.

You should figure out where those two different versions are coming from, then we can do something about it.

There's indeed 2 paths for this Lexer class that I can find in our project :

  • vendor/phpstan/phpdoc-parser/src/Lexer/Lexer.php (expected)
  • vendor/rector/rector/vendor/phpstan/phpdoc-parser/src/Lexer/Lexer.php (hello Rector my old friend.. 🎶)

Rector was defined in composer.json like so : "rector/rector": "^0.15", making it stuck to 0.15.25 when the latest version is 0.17. So I've updated it to 0.17, and now the error changed to :

1) Error
The data provider specified for App\Test\Unit\Infrastructure\Shared\PhpStan\Extensions\TypeInferenceTest::testAsserts is invalid.
Error: Undefined constant PHPStan\PhpDocParser\Lexer\Lexer::TOKEN_DOCTRINE_TAG
phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:118
phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php:84
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/PhpDoc/PhpDocStringResolver.php:28
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:156
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:265
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:292
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:185
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:164
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/FileTypeMapper.php:113
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php:258
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php:235
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:1475
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php:558
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:1519
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:574
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:338
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:49
phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:78
/app/tests/unit/Infrastructure/Shared/PhpStan/Extensions/TypeInferenceTest.php:24

Thing is, I even tried to uninstall Rector (composer remove rector/rector); and the tests still fail with the same error. I can find only one usage of namespace PHPStan\PhpDocParser\Lexer in the whole project now.

Could another version of php-parser be hidden somewhere ? How could I find it ? (you mentionned PHARS, but I don't know what to do with that :s)

Please create a small reproducing repository that shows the problem, otherwise I can't help you.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.