summaryrefslogtreecommitdiff
path: root/tests/Unit/Middleware/LegacyMiddlewareTest.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/LegacyMiddlewareTest.php
parent9f1ee0c6c6497d43fb275491ec53fda420f64b81 (diff)
parent36dafdb68acbde2fe42ce36ef50f497c8c06411f (diff)
Merge branch 'MyIgel-rebuild-psr7'
Diffstat (limited to 'tests/Unit/Middleware/LegacyMiddlewareTest.php')
-rw-r--r--tests/Unit/Middleware/LegacyMiddlewareTest.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/Unit/Middleware/LegacyMiddlewareTest.php b/tests/Unit/Middleware/LegacyMiddlewareTest.php
new file mode 100644
index 00000000..34e60b60
--- /dev/null
+++ b/tests/Unit/Middleware/LegacyMiddlewareTest.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Middleware;
+
+use Engelsystem\Http\Request;
+use Engelsystem\Middleware\LegacyMiddleware;
+use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
+use Psr\Container\ContainerInterface;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use Symfony\Component\HttpFoundation\ParameterBag;
+
+class LegacyMiddlewareTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Middleware\LegacyMiddleware::__construct
+ * @covers \Engelsystem\Middleware\LegacyMiddleware::process
+ */
+ public function testRegister()
+ {
+ /** @var ContainerInterface|MockObject $container */
+ $container = $this->getMockForAbstractClass(ContainerInterface::class);
+ /** @var LegacyMiddleware|MockObject $middleware */
+ $middleware = $this->getMockBuilder(LegacyMiddleware::class)
+ ->setConstructorArgs([$container])
+ ->setMethods(['loadPage', 'renderPage'])
+ ->getMock();
+ /** @var Request|MockObject $defaultRequest */
+ $defaultRequest = $this->createMock(Request::class);
+ /** @var ParameterBag|MockObject $parameters */
+ $parameters = $this->createMock(ParameterBag::class);
+ /** @var ResponseInterface|MockObject $response */
+ $response = $this->getMockForAbstractClass(ResponseInterface::class);
+ /** @var RequestHandlerInterface|MockObject $handler */
+ $handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
+ /** @var ServerRequestInterface|MockObject $request */
+ $request = $this->getMockForAbstractClass(ServerRequestInterface::class);
+
+ $middleware->expects($this->exactly(2))
+ ->method('loadPage')
+ ->withConsecutive(['user_worklog'], ['login'])
+ ->willReturnOnConsecutiveCalls(
+ ['title', 'content'],
+ ['title2', 'content2']
+ );
+
+ $middleware->expects($this->exactly(2))
+ ->method('renderPage')
+ ->withConsecutive(
+ ['user_worklog', 'title', 'content'],
+ ['login', 'title2', 'content2']
+ )
+ ->willReturn($response);
+
+ $container->expects($this->atLeastOnce())
+ ->method('get')
+ ->with('request')
+ ->willReturn($defaultRequest);
+
+ $defaultRequest->query = $parameters;
+ $defaultRequest->expects($this->once())
+ ->method('path')
+ ->willReturn('user-worklog');
+
+ $parameters->expects($this->exactly(3))
+ ->method('get')
+ ->with('p')
+ ->willReturnOnConsecutiveCalls(
+ null,
+ 'foo',
+ '/'
+ );
+
+ $handler->expects($this->once())
+ ->method('handle')
+ ->with($request)
+ ->willReturn($response);
+
+ $middleware->process($request, $handler);
+ $middleware->process($request, $handler);
+ $middleware->process($request, $handler);
+ }
+}