cache = new ArrayCache(); $this->middleware = new QrCodeCacheMiddleware($this->cache); } /** * @test */ public function noCachedPathFallbacksToNextMiddleware() { $isCalled = false; $this->middleware->__invoke( ServerRequestFactory::fromGlobals(), new Response(), function ($req, $resp) use (&$isCalled) { $isCalled = true; return $resp; } ); $this->assertTrue($isCalled); } /** * @test */ public function cachedPathReturnsCacheContent() { $isCalled = false; $uri = (new Uri())->withPath('/foo'); $this->cache->save('/foo', ['body' => 'the body', 'content-type' => 'image/png']); $resp = $this->middleware->__invoke( ServerRequestFactory::fromGlobals()->withUri($uri), new Response(), function ($req, $resp) use (&$isCalled) { $isCalled = true; return $resp; } ); $this->assertFalse($isCalled); $resp->getBody()->rewind(); $this->assertEquals('the body', $resp->getBody()->getContents()); $this->assertEquals('image/png', $resp->getHeaderLine('Content-Type')); } }