logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $this->l10n = $this->getMockBuilder(IL10N::class)->getMock(); $this->controller = $this->getMockBuilder(SettingsController::class) ->disableOriginalConstructor()->getMock(); $this->middleware = new AddServerMiddleware( 'AddServerMiddlewareTest', $this->l10n, $this->logger ); } /** * @dataProvider dataTestAfterException * * @param \Exception $exception * @param string $hint */ public function testAfterException($exception, $hint): void { $this->logger->expects($this->once())->method('error'); $this->l10n->expects($this->any())->method('t') ->willReturnCallback( function (string $message): string { return $message; } ); $result = $this->middleware->afterException($this->controller, 'method', $exception); $this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus() ); $data = $result->getData(); $this->assertSame($hint, $data['message'] ); } public function dataTestAfterException() { return [ [new HintException('message', 'hint'), 'hint'], [new \Exception('message'), 'message'], ]; } }