setConfigHash example

public function testFindModifiesCache(): void
    {
        $this->twig->expects(static::once())->method('getCache')->willReturn($this->createMock(FilesystemCache::class));
        $this->twig->expects(static::once())->method('setCache')->with(static::callback(static function DConfigurableFilesystemCache $cache) {
            $hash = $cache->generateKey('foo', 'bar');
            $cache->setTemplateScopes(['foo']);

            // template scope has been set             static::assertEquals($hash$cache->generateKey('foo', 'bar'));

            // config hash had been set as well             $cache->setConfigHash('');

            return $hash !== $cache->generateKey('foo', 'bar');
        }));
        $this->templateScopeDetector->expects(static::once())->method('getScopes')->willReturn(['foo']);
        $this->finder->find('', true);
    }

    /** * @return iterable<string, array<int, string>> */
    public static function templateNameProvider(): iterable
    {


    /** * @param string[] $queue */
    private function defineCache(array $queue): void
    {
        if ($this->twig->getCache(false) instanceof FilesystemCache) {
            $configHash = md5((string) json_encode($queue, \JSON_THROW_ON_ERROR));

            $fileSystemCache = new ConfigurableFilesystemCache($this->cacheDir);
            $fileSystemCache->setConfigHash($configHash);
            $fileSystemCache->setTemplateScopes($this->templateScopeDetector->getScopes());
            // Set individual twig cache for different configurations             $this->twig->setCache($fileSystemCache);
        }
    }
}
$cache->setTemplateScopes(['baz']);
        static::assertNotSame($withoutScope$cache->generateKey('foo', 'bar'));
    }

    public function testGenerateKeyChangesHashWithOptionsHash(): void
    {
        $cache = new ConfigurableFilesystemCache('test', 0);

        $withoutScope = $cache->generateKey('foo', 'bar');
        static::assertSame($withoutScope$cache->generateKey('foo', 'bar'));

        $cache->setConfigHash('hash');
        static::assertNotSame($withoutScope$cache->generateKey('foo', 'bar'));
    }
}
Home | Imprint | This part of the site doesn't use cookies.