* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Http\Tests\Firewall; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; use Symfony\Component\Security\Http\Firewall\AnonymousAuthenticationListener; class AnonymousAuthenticationListenerTest extends TestCase { public function testHandleWithTokenStorageHavingAToken() { $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $tokenStorage ->expects($this->any()) ->method('getToken') ->will($this->returnValue($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())) ; $tokenStorage ->expects($this->never()) ->method('setToken') ; $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $authenticationManager ->expects($this->never()) ->method('authenticate') ; $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', null, $authenticationManager); $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); } public function testHandleWithTokenStorageHavingNoToken() { $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $tokenStorage ->expects($this->any()) ->method('getToken') ->will($this->returnValue(null)) ; $anonymousToken = new AnonymousToken('TheSecret', 'anon.', array()); $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $authenticationManager ->expects($this->once()) ->method('authenticate') ->with($this->callback(function ($token) { return 'TheSecret' === $token->getSecret(); })) ->will($this->returnValue($anonymousToken)) ; $tokenStorage ->expects($this->once()) ->method('setToken') ->with($anonymousToken) ; $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', null, $authenticationManager); $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); } public function testHandledEventIsLogged() { $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $logger->expects($this->once()) ->method('info') ->with('Populated the TokenStorage with an anonymous Token.') ; $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', $logger, $authenticationManager); $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); } } __halt_compiler();----SIGNATURE:----aimNKR9xVzAeYxU9gRxkJGmEOLjg+umGbu66vgTVq32VfiuCHJEVEAqsU+0Z3ilIFrZqCnIWDsebMzHVCSAOgNMwrzHo+SMONjsclTBPQNXNvY2G/LfMoISN0A0mxCTNAYvARE1ubEsqHZokLn9Hp0O3I9Bkf0F9DR6J++tpm8miH0PbqtVzMUl1LqyGpjfjI9qY0mrt1sbUbSIpPFLzpXmlQuS/TdxRin8X+W4kxXmwqpFZEVD7v2v9HtyN4fpGxJ6b0FM4vtjpo6esaDmhWe4+LjnYYt4vwhZpoMQRUrDxsPDD5zu4XmGySeJ9lMoIAGoYE0M2mwLQGMEc05rIXSqGnfgWAKl7cdpkXG8cTaS3SZQcIq9UEFzdM2RIoEgrc6m3x0Ei8eECRhn8A14xzcUrpccz6e4B3otDcwLTF/6fM1whi8S7oZCOrE5lcvoGFFwFadkPPwp68ZnEwZe0F8p/f5G2J6V8LmX6tmteqOZZ0WpCQZsXe+39lWSbSA7Xc1qFrv5XSN/6zVEaBqfJeK/lpGLaC+GLLYUNX7/kuugoqNxyzu3++xhpEHX3Wajfd17JpZLSzK3meixXV8EXG1cfEUUZ/77NziNRDT+rr2TGH2KtU/CbSBv+y/KubSfSf/n36rkRbtYSI8V8tk5+tgCrb5pSGvRc1FsQRz0sybQ=----ATTACHMENT:----NjI0MTQ3MDg1OTc0NTYxOSAzMTE2ODY5MDEzMzI5NzMgNDc4OTA2MDY2OTgzNjg4OQ==