$this->accessDecisionManager->
expects($this->
once()) ->
method('decide'
)->
with($token,
['ROLE_ALLOWED_TO_SWITCH'
],
$targetsUser) ->
willReturn(true
);
$this->userChecker->
expects($this->
once()) ->
method('checkPostAuth'
)->
with($targetsUser);
$listener =
new SwitchUserListener($this->tokenStorage,
$this->userProvider,
$this->userChecker, 'provider123',
$this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', null, true
);
$listener($this->event
);
$this->
assertInstanceOf(UsernamePasswordToken::
class,
$this->tokenStorage->
getToken());
$this->
assertFalse($this->event->
hasResponse());
} public function testSwitchUserRefreshesOriginalToken() { $originalUser =
new InMemoryUser('username', null
);
$refreshedOriginalUser =
new InMemoryUser('username', null
);
$userProvider =
$this->
createMock(InMemoryUserProvider::
class);
$userProvider ->
expects($this->
any()) ->
method('refreshUser'
) ->
with($this->
identicalTo($originalUser))