3 namespace Tests\Wallabag\UserBundle\EventListener
;
5 use Monolog\Handler\TestHandler
;
7 use Symfony\Component\EventDispatcher\EventDispatcher
;
8 use Symfony\Component\HttpFoundation\Request
;
9 use Symfony\Component\HttpFoundation\RequestStack
;
10 use Symfony\Component\Security\Core\AuthenticationEvents
;
11 use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent
;
12 use Wallabag\UserBundle\EventListener\AuthenticationFailureListener
;
14 class AuthenticationFailureListenerTest
extends \PHPUnit_Framework_TestCase
16 private $requestStack;
21 protected function setUp()
23 $request = Request
::create('/');
24 $request->request
->set('_username', 'admin');
26 $this->requestStack
= new RequestStack();
27 $this->requestStack
->push($request);
29 $this->logHandler
= new TestHandler();
30 $logger = new Logger('test', [$this->logHandler
]);
32 $this->listener
= new AuthenticationFailureListener(
37 $this->dispatcher
= new EventDispatcher();
38 $this->dispatcher
->addSubscriber($this->listener
);
41 public function testOnAuthenticationFailure()
43 $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
44 ->disableOriginalConstructor()
47 $exception = $this->getMockBuilder('Symfony\Component\Security\Core\Exception\AuthenticationException')
48 ->disableOriginalConstructor()
51 $event = new AuthenticationFailureEvent(
56 $this->dispatcher
->dispatch(
57 AuthenticationEvents
::AUTHENTICATION_FAILURE
,
61 $records = $this->logHandler
->getRecords();
63 $this->assertCount(1, $records);
64 $this->assertSame('Authentication failure for user "admin", from IP "127.0.0.1", with UA: "Symfony/3.X".', $records[0]['message']);