diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-11-13 17:48:07 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2018-12-02 12:53:31 +0100 |
commit | 9788c5095a67a45fe3545ae0fc747b8e629ea4fd (patch) | |
tree | ac6edc92fcf08c40d4b517529a76ab9f230829f0 /tests/Unit/Middleware | |
parent | 2588bbf7bc5374830662af7c01df688c42d30dc6 (diff) |
Implemented HttpException
Diffstat (limited to 'tests/Unit/Middleware')
-rw-r--r-- | tests/Unit/Middleware/ErrorHandlerTest.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/Unit/Middleware/ErrorHandlerTest.php b/tests/Unit/Middleware/ErrorHandlerTest.php index abf9c52f..c0834591 100644 --- a/tests/Unit/Middleware/ErrorHandlerTest.php +++ b/tests/Unit/Middleware/ErrorHandlerTest.php @@ -2,6 +2,7 @@ namespace Engelsystem\Test\Unit\Middleware; +use Engelsystem\Http\Exceptions\HttpException; use Engelsystem\Http\Response; use Engelsystem\Middleware\ErrorHandler; use Engelsystem\Test\Unit\Middleware\Stub\ReturnResponseMiddlewareHandler; @@ -85,4 +86,43 @@ class ErrorHandlerTest extends TestCase $errorHandler->process($request, $returnResponseHandler); $errorHandler->process($request, $returnResponseHandler); } + + /** + * @covers \Engelsystem\Middleware\ErrorHandler::process + */ + public function testProcessException() + { + /** @var ServerRequestInterface|MockObject $request */ + $request = $this->createMock(ServerRequestInterface::class); + /** @var ResponseInterface|MockObject $psrResponse */ + $psrResponse = $this->getMockForAbstractClass(ResponseInterface::class); + /** @var ReturnResponseMiddlewareHandler|MockObject $returnResponseHandler */ + $returnResponseHandler = $this->getMockBuilder(ReturnResponseMiddlewareHandler::class) + ->disableOriginalConstructor() + ->getMock(); + + $psrResponse->expects($this->once()) + ->method('getStatusCode') + ->willReturn(300); + + $returnResponseHandler->expects($this->once()) + ->method('handle') + ->willReturnCallback(function () { + throw new HttpException(300, 'Some response', ['lor' => 'em']); + }); + + /** @var ErrorHandler|MockObject $errorHandler */ + $errorHandler = $this->getMockBuilder(ErrorHandler::class) + ->disableOriginalConstructor() + ->setMethods(['createResponse']) + ->getMock(); + + $errorHandler->expects($this->once()) + ->method('createResponse') + ->with('Some response', 300, ['lor' => 'em']) + ->willReturn($psrResponse); + + $return = $errorHandler->process($request, $returnResponseHandler); + $this->assertEquals($psrResponse, $return); + } } |