summaryrefslogtreecommitdiff
path: root/tests/Unit/Middleware
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-23 19:13:19 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-23 20:11:37 +0200
commit66038eda14d5d4e624b6636a6156570e3e940e49 (patch)
tree6e4b7557b7d91786ef47f22f7ddef85eed1dfb42 /tests/Unit/Middleware
parent590adffa9316b98544cb8d67b03b80e44ba9c8b7 (diff)
parent9d34f371cb9c5ab0d60bd3158678b9cc9da6cc80 (diff)
Merge branch 'twig-templates'
Diffstat (limited to 'tests/Unit/Middleware')
-rw-r--r--tests/Unit/Middleware/RequestHandlerTest.php77
1 files changed, 70 insertions, 7 deletions
diff --git a/tests/Unit/Middleware/RequestHandlerTest.php b/tests/Unit/Middleware/RequestHandlerTest.php
index 896b55c3..cb5fc4a6 100644
--- a/tests/Unit/Middleware/RequestHandlerTest.php
+++ b/tests/Unit/Middleware/RequestHandlerTest.php
@@ -38,15 +38,12 @@ class RequestHandlerTest extends TestCase
public function testProcess()
{
/** @var Application|MockObject $container */
- $container = $this->createMock(Application::class);
/** @var ServerRequestInterface|MockObject $request */
- $request = $this->getMockForAbstractClass(ServerRequestInterface::class);
/** @var RequestHandlerInterface|MockObject $handler */
- $handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
/** @var ResponseInterface|MockObject $response */
- $response = $this->getMockForAbstractClass(ResponseInterface::class);
+ /** @var MiddlewareInterface|MockObject $middlewareInterface */
+ list($container, $request, $handler, $response, $middlewareInterface) = $this->getMocks();
- $middlewareInterface = $this->getMockForAbstractClass(MiddlewareInterface::class);
$requestHandlerInterface = $this->getMockForAbstractClass(RequestHandlerInterface::class);
$request->expects($this->exactly(3))
@@ -57,10 +54,10 @@ class RequestHandlerTest extends TestCase
/** @var RequestHandler|MockObject $middleware */
$middleware = $this->getMockBuilder(RequestHandler::class)
->setConstructorArgs([$container])
- ->setMethods(['resolveMiddleware'])
+ ->setMethods(['resolveRequestHandler'])
->getMock();
$middleware->expects($this->exactly(3))
- ->method('resolveMiddleware')
+ ->method('resolveRequestHandler')
->with('FooBarClass')
->willReturnOnConsecutiveCalls(
$middlewareInterface,
@@ -86,4 +83,70 @@ class RequestHandlerTest extends TestCase
$this->expectException(InvalidArgumentException::class);
$middleware->process($request, $handler);
}
+
+ /**
+ * @covers \Engelsystem\Middleware\RequestHandler::resolveRequestHandler
+ */
+ public function testResolveRequestHandler()
+ {
+ /** @var Application|MockObject $container */
+ /** @var ServerRequestInterface|MockObject $request */
+ /** @var RequestHandlerInterface|MockObject $handler */
+ /** @var ResponseInterface|MockObject $response */
+ /** @var MiddlewareInterface|MockObject $middlewareInterface */
+ list($container, $request, $handler, $response, $middlewareInterface) = $this->getMocks();
+
+ $className = 'Engelsystem\\Controllers\\FooBarTestController';
+
+ $request->expects($this->exactly(1))
+ ->method('getAttribute')
+ ->with('route-request-handler')
+ ->willReturn('FooBarTestController@showStuff');
+
+ /** @var RequestHandler|MockObject $middleware */
+ $middleware = $this->getMockBuilder(RequestHandler::class)
+ ->setConstructorArgs([$container])
+ ->setMethods(['resolveMiddleware'])
+ ->getMock();
+ $middleware->expects($this->once())
+ ->method('resolveMiddleware')
+ ->with([$middlewareInterface, 'showStuff'])
+ ->willReturn($middlewareInterface);
+
+ $middlewareInterface->expects($this->once())
+ ->method('process')
+ ->with($request, $handler)
+ ->willReturn($response);
+
+ $container->expects($this->exactly(2))
+ ->method('has')
+ ->withConsecutive(['FooBarTestController'], [$className])
+ ->willReturnOnConsecutiveCalls(false, true);
+ $container->expects($this->once())
+ ->method('make')
+ ->with($className)
+ ->willReturn($middlewareInterface);
+
+ $return = $middleware->process($request, $handler);
+ $this->assertEquals($return, $response);
+ }
+
+ /**
+ * @return array
+ */
+ protected function getMocks(): array
+ {
+ /** @var Application|MockObject $container */
+ $container = $this->createMock(Application::class);
+ /** @var ServerRequestInterface|MockObject $request */
+ $request = $this->getMockForAbstractClass(ServerRequestInterface::class);
+ /** @var RequestHandlerInterface|MockObject $handler */
+ $handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
+ /** @var ResponseInterface|MockObject $response */
+ $response = $this->getMockForAbstractClass(ResponseInterface::class);
+ /** @var MiddlewareInterface $middlewareInterface */
+ $middlewareInterface = $this->getMockForAbstractClass(MiddlewareInterface::class);
+
+ return [$container, $request, $handler, $response, $middlewareInterface];
+ }
}