php - Mocking SecurityContext in Symfony2 using PHPUnit -


these mocks:

$this->user->method('getcustomerid')            ->willreturn($this->customerid); $this->usertoken->method('getuser')                 ->willreturn($this->user); $this->securitycontext->method('gettoken')                       ->willreturn($this->usertoken); $this->securitycontext->expects($this->once())                       ->method('isgranted')                       ->will($this->returnvalue(true)); 

and code of class testing:

$token = $securitycontext->gettoken(); $isfullyauthenticated = $securitycontext->isgranted('is_authenticated_fully'); 

it throws error:

symfony\component\security\core\exception\authenticationcredentialsnotfoundexception: security context contains no authentication token. 1 possible reason may there no firewall configured url. 

i have no idea @ point, though mocks intercepted call methods , returned whatever wanted. in case seems isgranted methods not being mock

try using willreturn instead of will , add with

so try this:

$this->securitycontext->expects($this->once())                       ->method('isgranted')                       ->with('is_authenticated_fully')                       ->willreturn(true); 

instead of this:

$this->securitycontext->expects($this->once())                       ->method('isgranted')                       ->will($this->returnvalue(true)); 

hope help


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -