Closed t-heuser closed 3 years ago
Hi, can you show your composer.json and the output of running fresh composer install?
Otherwise I'll have to ask your to create a small reproducing repository since this use-case definitely works and is tested.
BTW the correct way to annotate a mock is MockObject&TestConstr. MockObject|TestConstr also works to construct an intersection type but that's thanks to a special exception in this extension. See more: https://phpstan.org/blog/union-types-vs-intersection-types
Hi, I know about the way to annotate it with "&". But If I do that I get another error: PHPDoc tag @var for property Tests\Unit\Model\Session\SessionTest::$soapHelperMock contains unresolvable type.
This is the property with it's PHPDoc tag to which throws the error:
/** @var MockObject&SoapHelper */
protected $soapHelperMock;
So this isn't working either. The SoapHelper class is definitly existing and also discovered by phpstan as the file is within the analysed path.
Here is my composer.json:
Here is the output of a fresh composer install:
I also tried to it without any other package, that means I uninstalled all packages listed in the dev section of the composer.json with the exception of phpunit, phpstan, phpstan-phpunit and extension-installer. I still got the same errors.
I'm absolutely clueless what could trigger these errors.
Hi, this can mean only one thing - SoapHelper is a final class :) And they can't be mocked.
Ah okay. Yeah it's final and I bypass this with "dg/bypass-finals" to be able to mock the classes. This is the result of me also using ergebnis/phpstan-rules which has the rule that every non-anonymous has to be final (ergebnis/phpstan-rules). Do you have an idea how to bypass this without removing ergebnis/phpstan.rules? Should I just add an regex which excludes these errors?
bypass-finals used to work without a problem but right now there's an incompatibility that's hard to solve: https://github.com/phpstan/phpstan/issues/3854 feel free to subscribe to that issue, thanks.
Okay, thanks a lot for your help.
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.
Hi, I just tried to setup phpstan with phpunit but it's not working for me. I have installed phpstan/phpstan@0.12.50, phpstan/phpstan-phpunit@0.12.16 and phpstan/phpstan/extension-loader@1.0.5. Here I have a minimum (not) working example:
The TestConstr class is just an empty final class. When I execute phpstan now at level 7 I get the following error:
26 Call to an undefined method PHPUnit\Framework\MockObject\MockObject|Tests\TestConstr::expects().
This should not be the case with this package or am I missing something?