handler = $this->prophesize(RequestHandlerInterface::class); $this->em = $this->prophesize(EntityManagerInterface::class); $this->middleware = new CloseDbConnectionMiddleware($this->em->reveal()); } /** * @test */ public function connectionIsClosedWhenMiddlewareIsProcessed() { $req = new ServerRequest(); $resp = new Response(); $conn = $this->prophesize(Connection::class); $closeConn = $conn->close()->will(function () { }); $getConn = $this->em->getConnection()->willReturn($conn->reveal()); $clear = $this->em->clear()->will(function () { }); $handle = $this->handler->handle($req)->willReturn($resp); $result = $this->middleware->process($req, $this->handler->reveal()); $this->assertSame($result, $resp); $getConn->shouldHaveBeenCalledOnce(); $closeConn->shouldHaveBeenCalledOnce(); $clear->shouldHaveBeenCalledOnce(); $handle->shouldHaveBeenCalledOnce(); } }