public function getAccountByAuthenticationProviderNameReturnsTheAuthenticatedAccountWithGivenProviderName()
{
$mockAuthenticationManager = $this->createMock(AuthenticationManagerInterface::class);
$mockAccount1 = $this->createMock(Account::class);
$mockAccount2 = $this->createMock(Account::class);
$token1 = $this->createMock(TokenInterface::class, [], [], 'token1' . md5(uniqid(mt_rand(), true)));
$token1->expects($this->any())->method('isAuthenticated')->will($this->returnValue(false));
$token1->expects($this->never())->method('getAccount');
$token2 = $this->createMock(TokenInterface::class, [], [], 'token2' . md5(uniqid(mt_rand(), true)));
$token2->expects($this->any())->method('isAuthenticated')->will($this->returnValue(true));
$token2->expects($this->any())->method('getAccount')->will($this->returnValue($mockAccount1));
$token3 = $this->createMock(TokenInterface::class, [], [], 'token3' . md5(uniqid(mt_rand(), true)));
$token3->expects($this->any())->method('isAuthenticated')->will($this->returnValue(true));
$token3->expects($this->any())->method('getAccount')->will($this->returnValue($mockAccount2));
$securityContext = $this->getAccessibleMock(Context::class, ['getAuthenticationTokens']);
$securityContext->setRequest($this->mockActionRequest);
$securityContext->_set('authenticationManager', $mockAuthenticationManager);
$securityContext->_set('activeTokens', ['SomeOhterProvider' => $token1, 'SecondProvider' => $token2, 'MatchingProvider' => $token3]);
$this->assertSame($mockAccount2, $securityContext->getAccountByAuthenticationProviderName('MatchingProvider'));
}