public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $authAdapter = $container->get('Recurly\\AuthenticationAdapter');
     $listener = new AuthenticationListener($authAdapter);
     $logger = $container->get('Recurly\\Logger');
     $listener->setLogger($logger);
     return $listener;
 }
 public function testProperlySetUnauthorizedAndTriggerEventOnUnauthorization()
 {
     $event = new MvcEvent();
     $request = new HttpRequest();
     $response = new HttpResponse();
     $routeMatch = new RouteMatch([]);
     $application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
     $eventManager = $this->createMock(EventManagerInterface::class);
     $application->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
     $routeMatch->setMatchedRouteName(Module::RECURLY_NOTIFICATION_ROUTE);
     $event->setRequest($request)->setResponse($response)->setRouteMatch($routeMatch)->setApplication($application);
     $authenticationResult = $this->getAuthenticationResult();
     $authenticationResult->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $authAdapter = $this->getAuthenticationAdapter();
     $authAdapter->expects($this->once())->method('authenticate')->will($this->returnValue($authenticationResult));
     $listener = new AuthenticationListener($authAdapter);
     $logger = $this->createMock(LoggerInterface::class);
     $logger->expects($this->once())->method('info');
     $listener->setLogger($logger);
     $listener->onResult($event);
     $this->assertNotEmpty($event->getError());
     $this->assertNotNull($event->getParam('exception'));
     $this->assertEquals(HttpResponse::STATUS_CODE_401, $response->getStatusCode());
 }