summaryrefslogtreecommitdiff
path: root/tests/Unit/Middleware/ExceptionHandlerTest.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2018-09-04 18:24:11 +0200
committermsquare <msquare@notrademark.de>2018-09-04 18:24:11 +0200
commitb320fc779063ee80b8f0ba505cb323287ccccbf5 (patch)
tree1e420597ae72c979361bf29b66ae7e27c73cf431 /tests/Unit/Middleware/ExceptionHandlerTest.php
parent9f1ee0c6c6497d43fb275491ec53fda420f64b81 (diff)
parent36dafdb68acbde2fe42ce36ef50f497c8c06411f (diff)
Merge branch 'MyIgel-rebuild-psr7'
Diffstat (limited to 'tests/Unit/Middleware/ExceptionHandlerTest.php')
-rw-r--r--tests/Unit/Middleware/ExceptionHandlerTest.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/Unit/Middleware/ExceptionHandlerTest.php b/tests/Unit/Middleware/ExceptionHandlerTest.php
new file mode 100644
index 00000000..6d2a20e6
--- /dev/null
+++ b/tests/Unit/Middleware/ExceptionHandlerTest.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Middleware;
+
+use Engelsystem\Application;
+use Engelsystem\Exceptions\Handler;
+use Engelsystem\Http\Response;
+use Engelsystem\Middleware\ExceptionHandler;
+use Engelsystem\Test\Unit\Middleware\Stub\ExceptionMiddlewareHandler;
+use Engelsystem\Test\Unit\Middleware\Stub\ReturnResponseMiddlewareHandler;
+use Illuminate\Contracts\Container\Container as ContainerInterface;
+use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+
+class ExceptionHandlerTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Middleware\ExceptionHandler::__construct
+ * @covers \Engelsystem\Middleware\ExceptionHandler::process
+ */
+ public function testRegister()
+ {
+ /** @var MockObject|ContainerInterface $container */
+ $container = $this->getMockForAbstractClass(ContainerInterface::class);
+ /** @var MockObject|ServerRequestInterface $request */
+ $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
+ /** @var MockObject|ResponseInterface $response */
+ $response = $this->getMockBuilder(Response::class)->getMock();
+ /** @var MockObject|Handler $errorHandler */
+ $errorHandler = $this->getMockBuilder(Handler::class)->getMock();
+ $returnResponseHandler = new ReturnResponseMiddlewareHandler($response);
+ $throwExceptionHandler = new ExceptionMiddlewareHandler();
+
+ Application::setInstance($container);
+
+ $container->expects($this->exactly(2))
+ ->method('get')
+ ->withConsecutive(['error.handler'], ['psr7.response'])
+ ->willReturnOnConsecutiveCalls($errorHandler, $response);
+
+ $response->expects($this->once())
+ ->method('withContent')
+ ->willReturn($response);
+ $response->expects($this->once())
+ ->method('withStatus')
+ ->with(500)
+ ->willReturn($response);
+
+ $handler = new ExceptionHandler($container);
+ $return = $handler->process($request, $returnResponseHandler);
+ $this->assertEquals($response, $return);
+
+ $return = $handler->process($request, $throwExceptionHandler);
+ $this->assertEquals($response, $return);
+ }
+}