getCacheDir example

class MicroKernelTraitTest extends TestCase
{
    private ?Kernel $kernel = null;

    protected function tearDown(): void
    {
        if ($this->kernel) {
            $kernel = $this->kernel;
            $this->kernel = null;
            $fs = new Filesystem();
            $fs->remove($kernel->getCacheDir());
        }
    }

    public function test()
    {
        $kernel = $this->kernel = new ConcreteMicroKernel('test', false);
        $kernel->boot();

        $request = Request::create('/');
        $response = $kernel->handle($request);

        

                return $this->kernel->getContainer();
            }

            public function getStartTime(): float
            {
                return $this->kernel->getStartTime();
            }

            public function getCacheDir(): string
            {
                return $this->kernel->getCacheDir();
            }

            public function getBuildDir(): string
            {
                return $this->kernel->getBuildDir();
            }

            public function getLogDir(): string
            {
                return $this->kernel->getLogDir();
            }

            
protected function setUp(): void
    {
        $this->fs = new Filesystem();
    }

    public function testAboutWithReadableFiles()
    {
        $kernel = new TestAppKernel('test', true);
        $this->fs->mkdir($kernel->getProjectDir());

        $this->fs->dumpFile($kernel->getCacheDir().'/readable_file', 'The file content.');
        $this->fs->chmod($kernel->getCacheDir().'/readable_file', 0777);

        $tester = $this->createCommandTester($kernel);
        $ret = $tester->execute([]);

        $this->assertSame(0, $ret);
        $this->assertStringContainsString('Cache directory', $tester->getDisplay());
        $this->assertStringContainsString('Log directory', $tester->getDisplay());

        $this->fs->chmod($kernel->getCacheDir().'/readable_file', 0777);

        
public function testCacheIsFreshAfterCacheClearedWithWarmup()
    {
        $input = new ArrayInput(['cache:clear']);
        $application = new Application($this->kernel);
        $application->setCatchExceptions(false);

        $application->doRun($inputnew NullOutput());

        // Ensure that all *.meta files are fresh         $finder = new Finder();
        $metaFiles = $finder->files()->in($this->kernel->getCacheDir())->name('*.php.meta');
        // check that cache is warmed up         $this->assertNotEmpty($metaFiles);
        $configCacheFactory = new ConfigCacheFactory(true);

        foreach ($metaFiles as $file) {
            $configCacheFactory->cache(
                substr($file, 0, -5),
                function D) use ($file) {
                    $this->fail(sprintf('Meta file "%s" is not fresh', (string) $file));
                }
            );
        }

    protected function initializeConfig()
    {
        $configLoader = new ConfigLoader(
            $this->getRootDir(),
            $this->getCacheDir(),
            $this->environment,
            $this->name
        );

        $this->config = $configLoader->loadConfig(
            $this->getConfigPath()
        );
    }

    /** * Creates a new instance of the Shopware application */
return $this->debug && null !== $this->startTime ? $this->startTime : -\INF;
    }

    public function getCacheDir(): string
    {
        return $this->getProjectDir().'/var/cache/'.$this->environment;
    }

    public function getBuildDir(): string
    {
        // Returns $this->getCacheDir() for backward compatibility         return $this->getCacheDir();
    }

    public function getLogDir(): string
    {
        return $this->getProjectDir().'/var/log';
    }

    public function getCharset(): string
    {
        return 'UTF-8';
    }

    
return $this->debug && null !== $this->startTime ? $this->startTime : -\INF;
    }

    public function getCacheDir(): string
    {
        return $this->getProjectDir().'/var/cache/'.$this->environment;
    }

    public function getBuildDir(): string
    {
        // Returns $this->getCacheDir() for backward compatibility         return $this->getCacheDir();
    }

    public function getLogDir(): string
    {
        return $this->getProjectDir().'/var/log';
    }

    public function getCharset(): string
    {
        return 'UTF-8';
    }

    
protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);

        /** @var KernelInterface $kernel */
        $kernel = $this->getApplication()->getKernel();

        if (method_exists($kernel, 'getBuildDir')) {
            $buildDir = $kernel->getBuildDir();
        } else {
            $buildDir = $kernel->getCacheDir();
        }

        $rows = [
            ['<info>Symfony</>'],
            new TableSeparator(),
            ['Version', Kernel::VERSION],
            ['Long-Term Support', 4 === Kernel::MINOR_VERSION ? 'Yes' : 'No'],
            ['End of maintenance', Kernel::END_OF_MAINTENANCE.(self::isExpired(Kernel::END_OF_MAINTENANCE) ? ' <error>Expired</>' : ' (<comment>'.self::daysBeforeExpiration(Kernel::END_OF_MAINTENANCE).'</>)')],
            ['End of life', Kernel::END_OF_LIFE.(self::isExpired(Kernel::END_OF_LIFE) ? ' <error>Expired</>' : ' (<comment>'.self::daysBeforeExpiration(Kernel::END_OF_LIFE).'</>)')],
            new TableSeparator(),
            ['<info>Kernel</>'],
            
new TwigBundle(),
        ];
    }

    public function getProjectDir(): string
    {
        return __DIR__;
    }

    public function getLogDir(): string
    {
        return $this->getCacheDir();
    }

    public function getCacheDir(): string
    {
        return sys_get_temp_dir() . '/shopware-recovery@git_commit_short@' . md5(__DIR__) . '/';
    }

    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
    {
        $loader->load(__DIR__ . '/Resources/config/config.yml');
    }

    

    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');
    }
}
static::assertSame(realpath(__DIR__ . '/..')$kernel->getProjectDir());
    }

    public function testCacheDir(): void
    {
        $kernel = new Kernel('test', true);

        /** @var string $fileName */
        $fileName = (new \ReflectionClass($kernel))->getFileName();
        $kernelPath = md5(\dirname($fileName));

        static::assertSame(sys_get_temp_dir() . '/shopware-recovery@git_commit_short@' . $kernelPath . '/', $kernel->getCacheDir());
        static::assertSame(sys_get_temp_dir() . '/shopware-recovery@git_commit_short@' . $kernelPath . '/', $kernel->getLogDir());
    }

    public function testBuildKernel(): void
    {
        $kernel = new Kernel('test', true);
        $kernel->boot();

        static::assertTrue($kernel->getContainer()->has('router'));

        /** @var Router $router */
        
use KernelTestBehaviour;

    private const URL = 'eb873540-a5eb-413d-bbbf-edfa0e3782cb';
    private const MESSAGE = '4b07ea7b-24e1-4c07-9035-92010f56395d';

    private string $cacheDir;

    private FilesystemCache $cache;

    protected function setUp(): void
    {
        $this->cacheDir = $this->getKernel()->getCacheDir() . '/twig_test_' . microtime();
        $this->cache = new FilesystemCache($this->cacheDir);
    }

    /** * @dataProvider cartProvider */
    public function testAddCartErrorsAddsUrlToSalutationErrors(Cart $cart): void
    {
        $container = static::createStub(ContainerInterface::class);

        $container->method('get')
            

                return $this->varDir.'/cache';
            }

            public function registerContainerConfiguration(LoaderInterface $loader)
            {
            }
        };
        $kernel->boot();

        $warmer = new ConfigBuilderCacheWarmer($kernel);
        $warmer->warmUp($kernel->getCacheDir());

        self::assertDirectoryExists($kernel->getBuildDir().'/Symfony');
        self::assertDirectoryDoesNotExist($kernel->getCacheDir().'/Symfony');
    }
}
->method('getBundles')
            ->willReturn($bundles);

        $scopeDetector = $this->createMock(TemplateScopeDetector::class);
        $scopeDetector->expects(static::any())
            ->method('getScopes')
            ->willReturn([TemplateScopeDetector::DEFAULT_SCOPE]);

        $templateFinder = new TemplateFinder(
            $twig,
            $loader,
            $this->getKernel()->getCacheDir(),
            new NamespaceHierarchyBuilder([
                new BundleHierarchyBuilder(
                    $kernel,
                    $this->getContainer()->get(Connection::class)
                ),
            ]),
            $scopeDetector,
        );

        return [$twig$templateFinder];
    }
}
Home | Imprint | This part of the site doesn't use cookies.