From 491ee376517cded3c9c8d2389e3f9f21daa1a407 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 28 Dec 2018 03:28:33 +0100 Subject: Don't save sessions permanently on api and metrics paths closes #530 (Session on API calls) --- tests/Unit/Middleware/SessionHandlerTest.php | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/Unit/Middleware/SessionHandlerTest.php (limited to 'tests/Unit/Middleware/SessionHandlerTest.php') diff --git a/tests/Unit/Middleware/SessionHandlerTest.php b/tests/Unit/Middleware/SessionHandlerTest.php new file mode 100644 index 00000000..4abd71a6 --- /dev/null +++ b/tests/Unit/Middleware/SessionHandlerTest.php @@ -0,0 +1,61 @@ +createMock(NativeSessionStorage::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); + + $handler->expects($this->exactly(2)) + ->method('handle') + ->with($request) + ->willReturn($response); + + $request->expects($this->exactly(2)) + ->method('getCookieParams') + ->willReturnOnConsecutiveCalls([], ['SESSION' => 'BlaFoo']); + + $request->expects($this->exactly(2)) + ->method('getAttribute') + ->with('route-request-path') + ->willReturn('/foo'); + + $sessionStorage->expects($this->exactly(2)) + ->method('getName') + ->willReturn('SESSION'); + + /** @var SessionHandler|MockObject $middleware */ + $middleware = $this->getMockBuilder(SessionHandler::class) + ->setConstructorArgs([$sessionStorage, ['/foo']]) + ->setMethods(['destroyNative']) + ->getMock(); + + $middleware->expects($this->once()) + ->method('destroyNative') + ->willReturn(true); + + $middleware->process($request, $handler); + $middleware->process($request, $handler); + } +} -- cgit v1.2.3-54-g00ecf