reflector = $this->getMockBuilder(ControllerMethodReflector::class) ->disableOriginalConstructor()->getMock(); $this->controller = $this->getMockBuilder(Controller::class) ->disableOriginalConstructor()->getMock(); $this->l10n = $this->createMock(IL10N::class); $this->subadminMiddlewareAsSubAdmin = new SubadminMiddleware($this->reflector, true, $this->l10n); $this->subadminMiddleware = new SubadminMiddleware($this->reflector, false, $this->l10n); } public function testBeforeControllerAsUserWithExemption(): void { $this->expectException(NotAdminException::class); $this->reflector ->expects($this->exactly(2)) ->method('hasAnnotation') ->withConsecutive( ['NoSubAdminRequired'], ['AuthorizedAdminSetting'], )->willReturn(false); $this->subadminMiddleware->beforeController($this->controller, 'foo'); } public function testBeforeControllerAsUserWithoutExemption(): void { $this->reflector ->expects($this->once()) ->method('hasAnnotation') ->with('NoSubAdminRequired') ->willReturn(true); $this->subadminMiddleware->beforeController($this->controller, 'foo'); } public function testBeforeControllerAsSubAdminWithoutExemption(): void { $this->reflector ->expects($this->exactly(2)) ->method('hasAnnotation') ->withConsecutive( ['NoSubAdminRequired'], ['AuthorizedAdminSetting'], )->willReturn(false); $this->subadminMiddlewareAsSubAdmin->beforeController($this->controller, 'foo'); } public function testBeforeControllerAsSubAdminWithExemption(): void { $this->reflector ->expects($this->once()) ->method('hasAnnotation') ->with('NoSubAdminRequired') ->willReturn(true); $this->subadminMiddlewareAsSubAdmin->beforeController($this->controller, 'foo'); } public function testAfterNotAdminException(): void { $expectedResponse = new TemplateResponse('core', '403', [], 'guest'); $expectedResponse->setStatus(403); $this->assertEquals($expectedResponse, $this->subadminMiddleware->afterException($this->controller, 'foo', new NotAdminException(''))); } public function testAfterRegularException(): void { $this->expectException(\Exception::class); $expectedResponse = new TemplateResponse('core', '403', [], 'guest'); $expectedResponse->setStatus(403); $this->subadminMiddleware->afterException($this->controller, 'foo', new \Exception()); } }