stripProjectDir example

$this->configFactory = $this->getContainer()->get(StorefrontPluginConfigurationFactory::class);
    }

    public function testCreateThemeConfig(): void
    {
        /** @var string $basePath */
        $basePath = realpath(__DIR__ . '/../fixtures/ThemeConfig');

        $theme = $this->getBundle('TestTheme', $basePath, true);
        $config = $this->configFactory->createFromBundle($theme);

        $basePath = $this->stripProjectDir($basePath);

        static::assertEquals('TestTheme', $config->getTechnicalName());
        static::assertEquals($basePath . '/Resources', $config->getBasePath());
        static::assertTrue($config->getIsTheme());
        static::assertEquals(
            $basePath . '/Resources/app/storefront/src/main.js',
            $config->getStorefrontEntryFilepath()
        );
        $this->assertFileCollection([
            $basePath . '/Resources/app/storefront/src/scss/overrides.scss' => [],
            '@Storefront' => [],
            

    public function createFromThemeJson(string $name, array $data, string $path, bool $isFullpath = true): StorefrontPluginConfiguration
    {
        try {
            if (!$isFullpath) {
                $path = $this->projectDir . \DIRECTORY_SEPARATOR . str_replace(\DIRECTORY_SEPARATOR . 'Resources', '', $path);
            }
            $pathname = $path . \DIRECTORY_SEPARATOR . 'Resources/theme.json';

            $basePath = realpath(pathinfo($pathname, \PATHINFO_DIRNAME)) ?: $pathname;

            $basePath = $this->stripProjectDir($basePath);

            $config = new StorefrontPluginConfiguration($name);

            $config->setThemeJson($data);
            $config->setBasePath($this->stripProjectDir($basePath));
            $config->setStorefrontEntryFilepath($this->getEntryFile($path));
            $config->setIsTheme(true);
            $config->setName($data['name']);
            $config->setAuthor($data['author']);

            if (\array_key_exists('style', $data) && \is_array($data['style'])) {
                


    public function testFileRealPath(): void
    {
        $existingFile = realpath(__DIR__ . '/fixtures/SimpleTheme/Resources/theme.json');

        $projectDir = $this->getContainer()->getParameter('kernel.project_dir');

        $importer = new ThemeFileImporter($projectDir);
        static::assertSame('random-file.twig', $importer->getRealPath('random-file.twig'));
        static::assertSame($existingFile$importer->getRealPath($existingFile));
        static::assertSame($existingFile$importer->getRealPath($this->stripProjectDir($existingFile)));
    }

    private function stripProjectDir(string $path): string
    {
        $projectDir = $this->getContainer()->getParameter('kernel.project_dir');

        if (str_starts_with($path$projectDir)) {
            return substr($path, \strlen($projectDir) + 1);
        }

        return $path;
    }
Home | Imprint | This part of the site doesn't use cookies.