cache = new ArrayCache(); $this->middleware = new QrCodeCacheMiddleware($this->cache); } /** * @test */ public function noCachedPathFallsBackToNextMiddleware() { $delegate = $this->prophesize(RequestHandlerInterface::class); $delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledOnce(); $this->middleware->process(ServerRequestFactory::fromGlobals()->withUri( new Uri('/foo/bar') ), $delegate->reveal()); $this->assertTrue($this->cache->contains('/foo/bar')); } /** * @test */ public function cachedPathReturnsCacheContent() { $isCalled = false; $uri = (new Uri())->withPath('/foo'); $this->cache->save('/foo', ['body' => 'the body', 'content-type' => 'image/png']); $delegate = $this->prophesize(RequestHandlerInterface::class); $resp = $this->middleware->process( ServerRequestFactory::fromGlobals()->withUri($uri), $delegate->reveal() ); $this->assertFalse($isCalled); $resp->getBody()->rewind(); $this->assertEquals('the body', $resp->getBody()->getContents()); $this->assertEquals('image/png', $resp->getHeaderLine('Content-Type')); $delegate->handle(Argument::any())->shouldHaveBeenCalledTimes(0); } }