Kevinrob\GuzzleCache\ValidationTest::setUp PHP Метод

setUp() публичный Метод

public setUp ( )
    public function setUp()
    {
        // Create default HandlerStack
        $stack = HandlerStack::create(function (RequestInterface $request, array $options) {
            switch ($request->getUri()->getPath()) {
                case '/etag':
                    if ($request->getHeaderLine('If-None-Match') == 'MyBeautifulHash') {
                        return new FulfilledPromise((new Response(304))->withHeader('X-Replaced', '2'));
                    }
                    return new FulfilledPromise((new Response())->withHeader('Etag', 'MyBeautifulHash')->withHeader('X-Base-Info', '1')->withHeader('X-Replaced', '1'));
                case '/etag-changed':
                    if ($request->getHeaderLine('If-None-Match') == 'MyBeautifulHash') {
                        return new FulfilledPromise((new Response())->withHeader('Etag', 'MyBeautifulHash2'));
                    }
                    return new FulfilledPromise((new Response())->withHeader('Etag', 'MyBeautifulHash'));
                case '/stale-while-revalidate':
                    if ($request->getHeaderLine('If-None-Match') == 'MyBeautifulHash') {
                        return new FulfilledPromise((new Response(304))->withHeader('Cache-Control', 'max-age=10'));
                    }
                    return new FulfilledPromise((new Response())->withHeader('Etag', 'MyBeautifulHash')->withHeader('Cache-Control', 'max-age=1')->withAddedHeader('Cache-Control', 'stale-while-revalidate=60'));
            }
            throw new \InvalidArgumentException();
        });
        $this->cache = new CacheMiddleware();
        // Add this middleware to the top with `push`
        $stack->push($this->cache, 'cache');
        // Initialize the client with the handler option
        $this->client = new Client(['handler' => $stack]);
        $this->cache->setClient($this->client);
    }