Store example

$this->assertFalse($this->kernel->isCatchingExceptions());
    }

    public function request($method$uri = '/', $server = []$cookies = []$esi = false, $headers = [])
    {
        if (null === $this->kernel) {
            throw new \LogicException('You must call setNextResponse() before calling request().');
        }

        $this->kernel->reset();

        $this->store = new Store(sys_get_temp_dir().'/http_cache');

        if (!isset($this->cacheConfig['debug'])) {
            $this->cacheConfig['debug'] = true;
        }

        if (!isset($this->cacheConfig['terminate_on_cache_hit'])) {
            $this->cacheConfig['terminate_on_cache_hit'] = false;
        }

        $this->esi = $esi ? new Esi() : null;
        $this->cache = new HttpCache($this->kernel, $this->store, $this->esi, $this->cacheConfig);
        
protected Request $request;
    protected Response $response;
    protected Store $store;

    protected function setUp(): void
    {
        $this->request = Request::create('/');
        $this->response = new Response('hello world', 200, []);

        HttpCacheTestCase::clearDirectory(sys_get_temp_dir().'/http_cache');

        $this->store = new Store(sys_get_temp_dir().'/http_cache');
    }

    protected function tearDown(): void
    {
        HttpCacheTestCase::clearDirectory(sys_get_temp_dir().'/http_cache');
    }

    public function testReadsAnEmptyArrayWithReadWhenNothingCachedAtKey()
    {
        $this->assertEmpty($this->getStoreMetadata('/nothing'));
    }

    

    protected function createStore()
    {
        if (isset($this->options['storeClass'])) {
            /** @var class-string<StoreInterface> $class */
            $class = $this->options['storeClass'];

            return new $class($this->options, $this->kernel);
        }

        return new Store(
            $this->cacheDir ?: ($this->kernel->getCacheDir() . '/http_cache'),
            $this->options['cache_cookies'],
            $this->options['lookup_optimization'],
            $this->options['ignored_url_parameters']
        );
    }

    /** * Checks if current purge request is allowed. * * @return bool */

        return [];
    }

    protected function createSurrogate(): SurrogateInterface
    {
        return $this->surrogate ?? new Esi();
    }

    protected function createStore(): StoreInterface
    {
        return $this->store ?? new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
    }
}

    public function testRequestHeaders()
    {
        $options = [
            'headers' => [
                'Application-Name' => 'test1234',
                'Test-Name-Header' => 'test12345',
            ],
        ];

        $mockClient = new MockHttpClient();
        $store = new Store(sys_get_temp_dir().'/sf_http_cache');
        $client = new CachingHttpClient($mockClient$store$options);

        $response = $client->request('GET', 'http://example.com/foo-bar');

        rmdir(sys_get_temp_dir().'/sf_http_cache');
        self::assertInstanceOf(MockResponse::class$response);
        self::assertSame($response->getRequestOptions()['normalized_headers']['application-name'][0], 'Application-Name: test1234');
        self::assertSame($response->getRequestOptions()['normalized_headers']['test-name-header'][0], 'Test-Name-Header: test12345');
    }

    public function testDoesNotEvaluateResponseBody()
    {
Home | Imprint | This part of the site doesn't use cookies.