public function setUp() { $this->listener = new Listener(); $this->user = $this->getMockBuilder(User::class)->setMethods(['isActive'])->getMock(); $this->auth = $this->getMockBuilder(AuthenticationService::class)->setMethods(['authenticate', 'hasIdentity', 'getIdentity', 'clearIdentity', 'getUser'])->getMock(); $this->auth->expects($this->any())->method('getUser')->willReturn($this->user); $this->serviceManager = $this->getMockBuilder(ServiceManager::class)->setMethods(['get', 'has'])->getMock(); $this->serviceManager->expects($this->any())->method('get')->will($this->returnCallback(function ($name) { switch ($name) { case 'AuthenticationService': return $this->auth; break; default: throw new \InvalidArgumentException(); break; } })); $this->application = $this->getMockBuilder(Application::class)->setMethods(['getServiceManager', 'getRequest', 'getResponse', 'run', 'getEventManager'])->getMock(); $this->application->expects($this->any())->method('getServiceManager')->willReturn($this->serviceManager); $this->routeMatch = new RouteMatch([]); $this->event = $this->getMockBuilder(MvcEvent::class)->getMock(); $this->event->expects($this->any())->method('getApplication')->willReturn($this->application); $this->event->expects($this->any())->method('getRouteMatch')->willReturn($this->routeMatch); }