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

Could not get class storage for Mockery\Adapter\Phpunit\MockeryPHPUnitIntegrationAssertPostConditions #1537

Closed
jaydiablo opened this issue Apr 9, 2019 · 4 comments

Comments

@jaydiablo
Copy link
Contributor

I'm not certain if this belongs here or in https://github.com/psalm/mockery-psalm-plugin but it might be general enough of an issue that it's a Psalm issue, not a plugin issue.

I get this error when trying to analyze a class that uses the Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration trait (which is required for Mockery to perform its assertions on if a mocked method was called the expected number of times or not).

Fatal error: Uncaught InvalidArgumentException: Could not get class storage for Mockery\Adapter\Phpunit\MockeryPHPUnitIntegrationAssertPostConditions

Digging a bit, that particular trait has this bit of code at the beginning of the file before the class is defined:

if (class_exists('PHPUnit_Framework_TestCase') || version_compare(\PHPUnit\Runner\Version::id(), '8.0.0', '<')) {
    class_alias(MockeryPHPUnitIntegrationAssertPostConditionsForV7AndPrevious::class, MockeryPHPUnitIntegrationAssertPostConditions::class);
} else {
    class_alias(MockeryPHPUnitIntegrationAssertPostConditionsForV8::class, MockeryPHPUnitIntegrationAssertPostConditions::class);
}

https://github.com/mockery/mockery/blob/master/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php#L25

Seems that this is done to change which trait ends up loading in based on the PHPUnit version being used. However, the class_alias seems to be throwing off Psalm when analyzing that trait.

If this is too much of an edge case to resolve in Psalm, is it possible to tell Psalm that \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegrationAssertPostConditions is actualy an alias for \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegrationAssertPostConditionsForV7AndPrevious (in my case)?

@jaydiablo
Copy link
Contributor Author

This is with Psalm 3.2.5 btw, and the fatal error happens here:

vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php:44

Stack trace if this helps:

#0 vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1099): Psalm\Internal\Provider\ClassLikeStorageProvider->get('Mockery\\Adapter...')
#1 vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1151): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeTraitUse(Object(Psalm\Aliases), Object(PhpParser\Node\Stmt\TraitUse), Object(Psalm\Internal\Analyzer\ProjectAnalyzer), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Context), Object(Psalm\Context), NULL)
#2 vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(663): Psalm\Internal\Ana in vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php on line 44

FWIW, Psalm 2.x would still parse and analyze the code, but spit out an UndefinedTrait error.

@muglug
Copy link
Collaborator

muglug commented Apr 9, 2019

If this is too much of an edge case to resolve in Psalm, is it possible to tell Psalm that \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegrationAssertPostConditions is actualy an alias for \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegrationAssertPostConditionsForV7AndPrevious (in my case)?

Yeah, you should be able to create a stub file with that class_alias inside.

@jaydiablo
Copy link
Contributor Author

Yeah, you should be able to create a stub file with that class_alias inside.

I was able to get that to work, maybe something that should be added to the Mockery plugin? I can try to put together a PR for that if you think that's where something like this belongs...

@muglug
Copy link
Collaborator

muglug commented Apr 10, 2019

I can try to put together a PR for that if you think that's where something like this belongs

Yes please!

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

2 participants