Fixes failing to recognize mock methods when using getMockForTrait()#29
Fixes failing to recognize mock methods when using getMockForTrait()#29BluePsyduck wants to merge 2 commits intophpstan:1.1.xfrom
Conversation
|
I noticed that it is currently not possible to have all tests passing on Travis because of a BC break in phpstan from 0.10.2 to 0.10.3. Should I change the dependency in composer.json to |
|
Hi, this isn’t that easy to fix, trait is not a standalone type, your
solution probably doesn’t work or it would break in some situation. Correct
solution is to generate an intersection type of ObjectWithoutClassType and
HasMethodType + HasPropertyType of all the traits methods and properties.
On Tue, 25 Sep 2018 at 18:05, BluePsyduck ***@***.***> wrote:
This pull request fixes that PHPStan failed to recognize the mock methods
when calling getMockForTrait() on the mock builder.
I also repaired the two failing tests of the current master.
Example:
// Context: Test method in a TestCase class.$trait = $this->getMockBuilder(MyFancyTrait::class) ->setMethods(['myFancyMethod']) ->getMockForTrait();$trait->expects($this->once()) ->method('myFancyMethod') ->with($myFancyParameter);
This would always trigger Call to an undefined method
PHPUnit\Framework\MockObject\MockBuilder<MyFancyTrait>::expects()..
------------------------------
You can view, comment on, or merge this pull request online at:
#29
Commit Summary
- Fixes failing tests in current master.
- Fixes failing to recognize mock methods when using getMockForTrait().
File Changes
- *M* src/Type/PHPUnit/MockBuilderDynamicReturnTypeExtension.php
<https://github.com/phpstan/phpstan-phpunit/pull/29/files#diff-0> (1)
- *M* tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php
<https://github.com/phpstan/phpstan-phpunit/pull/29/files#diff-1> (2)
- *M*
tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php
<https://github.com/phpstan/phpstan-phpunit/pull/29/files#diff-2> (2)
Patch Links:
- https://github.com/phpstan/phpstan-phpunit/pull/29.patch
- https://github.com/phpstan/phpstan-phpunit/pull/29.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#29>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGZuLY-0kYpcJw9GTl3foe0g70Jf31Tks5uelRUgaJpZM4W49LI>
.
--
Ondřej Mirtes
|
|
What’s the BC break?
On Tue, 25 Sep 2018 at 18:20, BluePsyduck ***@***.***> wrote:
I noticed that it is currently not possible to have all tests passing on
Travis because of a BC break in phpstan from 0.10.2 to 0.10.3.
Should I change the dependency in composer.json to "phpstan/phpstan":
"^0.10.3"?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#29 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGZuCWv8bclkzcDOaKshjtvnkT0X6Poks5ueleugaJpZM4W49LI>
.
--
Ondřej Mirtes
|
Okay, this surpasses my knowledge about how phpstan works internally so I won't be able to fix it that way myself. (I did a quick test, and for my case phpstan recognized both the mock methods and the trait methods.)
The constructor of |
This pull request fixes that PHPStan failed to recognize the mock methods when calling getMockForTrait() on the mock builder.
I also repaired the two failing tests of the current master.
Example:
This would always trigger
Call to an undefined method PHPUnit\Framework\MockObject\MockBuilder<MyFancyTrait>::expects()..