Skip to content

Commit

Permalink
Merge pull request #22 from villfa/fix/16
Browse files Browse the repository at this point in the history
Add support for spies
  • Loading branch information
weirdan authored Jun 27, 2021
2 parents 992e041 + f641af0 commit fcaf0d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Hooks/MockReturnTypeUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
$return_type_candidate = $event->getReturnTypeCandidate();
$expr = $event->getExpr();
$method_id = $event->getMethodId();
if ($return_type_candidate && $method_id === 'Mockery::mock' && isset($expr->args[0])) {
if ($return_type_candidate && self::isMockMethod($method_id) && isset($expr->args[0])) {
$first_arg = $expr->args[0]->value;

$fq_class_name = null;
Expand Down Expand Up @@ -65,4 +65,9 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
}
}
}

private static function isMockMethod(string $method_id): bool
{
return $method_id === 'Mockery::mock' || $method_id === 'Mockery::spy';
}
}
16 changes: 16 additions & 0 deletions tests/acceptance/MockReturn.feature
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@ Feature: MockReturn
"""
When I run Psalm
Then I see no errors

Scenario: Class spying is recognized
Given I have the following code
"""
class User
{
}
function foo(User $user): User
{
return $user;
}
$_user = foo(Mockery::spy(User::class));
"""
When I run Psalm
Then I see no errors

0 comments on commit fcaf0d9

Please sign in to comment.