From f3b3b6683ca90b70ec4d4daae002dc0caac9ebdd Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 11 Aug 2018 23:46:28 +0200 Subject: Added middleware tests --- tests/Unit/Middleware/LegacyMiddlewareTest.php | 85 ++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/Unit/Middleware/LegacyMiddlewareTest.php (limited to 'tests/Unit/Middleware/LegacyMiddlewareTest.php') 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 @@ +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); + } +} -- cgit v1.2.3-70-g09d2