-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
InvocationMocker annotated as internal, but docs suggest using functions it provides #3742
Comments
@sebastianbergmann Do you have a view on whether this is a PHPUnit bug, and if so what the best way to fix it would be? I'm happy to make a PR if so. Thanks. |
Workaround for me currently is to add a block (see below) to my psalm.xml but this is annoying - what is the fix? If it's internal are we supposed to use it? If not what are the alternatives?
|
This is an interesting problem related to fluent interfaces, I think. When you write $foo = $this->createMock(Foo::class);
$foo->method('bar')->willReturn('baz'); then you rely on the fact that The good news is that @Ocramius extracted the
|
Depends on how stable the interface is: if it's good enough, we can drop |
Thank you @sebastianbergmann and @Ocramius ! Excited to halve my ignores ;) |
Forgive me for dredging this up, but this still occurs on 8.4.3. Using |
bump @sebastianbergmann - what about InvocationMocker? Every time I use mocks, I have to put up with calling internal methods, as @lord2800 mentioned above |
8fdb4a6 is in every release since PHPUnit 8.4.0. |
When using PHPUnit's built-in mocking capabilities, and type-checking my code with Psalm, I get
InternalMethod
issues raised for PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturn, PHPUnit\Framework\MockObject\Builder\InvocationMocker::method, and PHPUnit\Framework\MockObject\Builder\InvocationMocker::with.This is due to the annotation on the class:
phpunit/src/Framework/MockObject/Builder/InvocationMocker.php
Line 22 in f67ca36
For example with the following code:
But as far as I can tell I'm following the instructions in the docs at https://phpunit.readthedocs.io/en/8.2/test-doubles.html#mock-objects .
If I'm not using PHPUnit wrong, I think that probably either the
@internal
annotation should be removed fromInvocationMocker
, and perhaps added to some of its functions that are not mentioned in the documentation, such as the constructor, or the return type declared atphpunit/src/Framework/MockObject/MockObject.php
Line 16 in f67ca36
BuilderInvocationMocker
, which is an alias ofInvocationMocker
, to an interface containing just the functions we should be relying on.The text was updated successfully, but these errors were encountered: