public function setUp()
{
// Create default HandlerStack
$stack = HandlerStack::create(function (RequestInterface $request, array $options) {
switch ($request->getUri()->getPath()) {
case '/private':
return new FulfilledPromise((new Response())->withAddedHeader('Cache-Control', 'private,max-age=2'));
case '/max-age':
return new FulfilledPromise((new Response())->withAddedHeader('Cache-Control', 'max-age=2'));
case '/s-maxage':
return new FulfilledPromise((new Response())->withAddedHeader('Cache-Control', 's-maxage=2,max-age=0'));
}
throw new \InvalidArgumentException();
});
// Add this middleware to the top with `push`
$stack->push(new CacheMiddleware(new PublicCacheStrategy()), 'cache');
// Initialize the client with the handler option
$this->client = new Client(['handler' => $stack]);
}