public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $whip = $container->get('Recurly\\Whip'); $listener = new IpListener($whip); $logger = $container->get('Recurly\\Logger'); $listener->setLogger($logger); return $listener; }
public function testProperlySetUnauthorizedAndTriggerEventOnUnauthorization() { $whip = $this->createMock(Whip::class); $whip->expects($this->once())->method('getValidIpAddress')->will($this->returnValue(false)); $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); $listener = new IpListener($whip); $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_403, $response->getStatusCode()); }