* * 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:----J3v8Y7luztP8seQIDFkKIf/IGdfAzRV1xGW9iDBZLIEoq9L2zlMy2uZqEHTAaLWOBZ6s81dCu297GSZXydJLgFeE4EaChsg0jcQXHjIEcmDRSscJs08uISRWZ40D6GrCGGNXIWfJ1nOi+bLfZKHi8XPgGtzImcaeypq3+oqdnFt+mduIDQwXEQoMkQDBtCKqZ978rougxKmNaUCX20o3mIyjR3imHdqkK43lEqgr08ESyIehhGi4tR9znQGvnRQnvalbJF5V/E4dU3fU8yZYeu9FK9jnMXCbR6w8WaMt9F0GBUaugaPsYRp2bHxUxQTllkaAE5W4Nwmaw+Zk74ESrqxWwHvj4E/0yNW88xkzFp1ZoNHiBC2WWFk8NndSGtFIVYTKhOT6fFP6bp7NAJUd4PQlaMCyLI8kszwiLKwuOVV8rB0kJTenrKV1IeMSSFCRvua+w1pxp8yV90Xw0LM/h5rAmZNf9VR8EJQxr8VoDu3IbyGNTk9UCYvklztITFik3z1tfO2HIbvQYKD2DcrcXYYUFH/SW7q917vHJto9gqXho0xLYGx9Tg6QwANChLN8WltwF5BK0ilh6RVmxMgRdx5VmYhtiI3h/2Ej6/eUrK21dWmNeJInncKd2AHfGrD1Uz+M9FyKFeEhcSkhG7YLuT/f+oXgCb+ENwVnWUKmsak=----ATTACHMENT:----NjU2Nzk0NjgxMjc2NDE0MSA3NzkxMjkwMjU4MjIwNDg0IDc2NDg5MzQzMjE2NTU3MjY=