GenericSnippetFile example



    /** * @param array<string> $files */
    private function hydrateFiles(array $files): SnippetFileCollection
    {
        $snippetFileCollection = new SnippetFileCollection();
        foreach ($files as $filePath) {
            $fileName = basename($filePath);

            $snippetFileCollection->add(new GenericSnippetFile(
                $fileName,
                $filePath,
                $this->getLocaleFromFileName($fileName),
                'Shopware',
                false,
                ''
            ));
        }

        return $snippetFileCollection;
    }

    

class GenericSnippetFileTest extends TestCase
{
    public function testInstantiate(): void
    {
        $ids = new IdsCollection();

        $isBase = Random::getBoolean();

        $exception = new GenericSnippetFile(
            $ids->get('name'),
            $ids->get('path'),
            $ids->get('iso'),
            $ids->get('author'),
            $isBase,
            $ids->get('technicalName'),
        );

        static::assertEquals($ids->get('name')$exception->getName());
        static::assertEquals($ids->get('author')$exception->getAuthor());
        static::assertEquals($ids->get('iso')$exception->getIso());
        


    public function testLoadSnippetFilesIntoCollectionDoesNotOverwriteFiles(): void
    {
        $kernel = new MockedKernel(
            [
                'ShopwareBundleWithSnippets' => new ShopwareBundleWithSnippets(),
            ]
        );

        $collection = new SnippetFileCollection([
            new GenericSnippetFile(
                'test',
                __DIR__ . '/_fixtures/ShopwareBundleWithSnippets/Resources/snippet/storefront.de-DE.json',
                'xx-XX',
                'test Author',
                true,
                'ShopwareBundleWithSnippets'
            ),
            new GenericSnippetFile(
                'test',
                __DIR__ . '/_fixtures/ShopwareBundleWithSnippets/Resources/snippet/storefront.en-GB.json',
                'yy-YY',
                
2 => $this->getSnippetFile($nameParts$fileInfo$author),
            3 => $this->getBaseSnippetFile($nameParts$fileInfo$author),
            default => null,
        };
    }

    /** * @param array<string> $nameParts */
    private function getSnippetFile(array $nameParts, SplFileInfo $fileInfo, string $author): GenericSnippetFile
    {
        return new GenericSnippetFile(
            implode('.', $nameParts),
            $fileInfo->getPathname(),
            $nameParts[1],
            $author,
            false,
            ''
        );
    }

    /** * @param array<string> $nameParts */
            $authors = [];
        }

        $snippetFiles = [];

        foreach ($finder->getIterator() as $fileInfo) {
            $nameParts = explode('.', $fileInfo->getFilenameWithoutExtension());

            $snippetFile = null;
            switch (\count($nameParts)) {
                case 2:
                    $snippetFile = new GenericSnippetFile(
                        implode('.', $nameParts),
                        $fileInfo->getPathname(),
                        $nameParts[1],
                        $this->getAuthorFromBundle($bundle$authors),
                        false,
                        $bundle->getName()
                    );

                    break;
                case 3:
                    $snippetFile = new GenericSnippetFile(
                        
Home | Imprint | This part of the site doesn't use cookies.