Skip to content

Commit

Permalink
MockMethodCallRule - do not report for empty $mockClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 2, 2023
1 parent 34ee324 commit 4cc5c6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Rules/PHPUnit/MockMethodCallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ public function processNode(Node $node, Scope $scope): array
continue;
}

$classNames = $mockedClassObject->getObjectClassNames();
if (count($classNames) === 0) {
continue;
}

$errors[] = sprintf(
'Trying to mock an undefined method %s() on class %s.',
$method,
implode('|', $mockedClassObject->getObjectClassNames())
implode('|', $classNames)
);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Rules/PHPUnit/data/mock-method-call.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,18 @@ public function method(string $string)
return $string;
}
};

final class FinalFoo
{

}

class FinalFooTest extends \PHPUnit\Framework\TestCase
{

public function testMockFinalClass()
{
$this->createMock(FinalFoo::class)->method('doFoo');
}

}

0 comments on commit 4cc5c6c

Please sign in to comment.