I have an issue returning correct behaviour when mocking specific object while writing tests in Symfony 5.
My method:
public function myTestFunction(TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
.....
}
I was trying in my tests like:
$this->token = $this->createMock(TokenInterface::class);
$this->token
->method('getUser')
->willReturn(UserInterface::class);
Result does not replicate the behaviour I want to accomplished based on the code I posted.
As I am defining $token as a stub, I am forced to describe every interaction with it, otherwise PHPUnit
, will return null for every method call.