2016-09-12 19:37
浏览 46


These are my mocks:


And this is the code of the class I am testing:

$token = $securityContext->getToken();
$isFullyAuthenticated = $securityContext->isGranted('IS_AUTHENTICATED_FULLY');

It throws the error:

Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException: The security context contains no authentication token. One possible reason may be that there is no firewall configured for this URL.

I have no idea what to do at this point, I though mocks intercepted the call to methods and returned whatever I wanted. But in this case is seems the isGranted methods is not being mock

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doushaiyu5065 2016-10-16 03:22

    I figured out that the problem is that the isGranted method is final, so it's imposible to mock, the workaround the problem was to mock all the attributes of SecurityContext so that when the method is call it returns my desired output, instead of intercepting the call with a mock method.

    打赏 评论
  • drkj41932 2016-09-12 19:59

    Try using willReturn instead of will and add the with

    So try this:


    Instead of this:


    Hope this help

    打赏 评论

相关推荐 更多相似问题