SnippetFileCollection example

->willReturn([$secondPath]);

        $snippetFileHandler->method('openJsonFile')
            ->willReturnCallback(function D$path) use ($firstPath) {
                if ($path === $firstPath) {
                    return ['german' => 'exampleGerman'];
                }

                return ['english' => 'exampleEnglish'];
            });

        $snippetValidator = new SnippetValidator(new SnippetFileCollection()$snippetFileHandler, '');
        $missingSnippets = $snippetValidator->validate();

        static::assertCount(2, $missingSnippets);
        static::assertArrayHasKey('german', $missingSnippets['en-GB']);
        static::assertSame('german', $missingSnippets['en-GB']['german']['keyPath']);
        static::assertSame('exampleGerman', $missingSnippets['en-GB']['german']['availableValue']);

        static::assertArrayHasKey('english', $missingSnippets['de-DE']);
        static::assertSame('english', $missingSnippets['de-DE']['english']['keyPath']);
        static::assertSame('exampleEnglish', $missingSnippets['de-DE']['english']['availableValue']);
    }

    
class SnippetFileCollectionFactory
{
    /** * @internal */
    public function __construct(private readonly SnippetFileLoaderInterface $snippetFileLoader)
    {
    }

    public function createSnippetFileCollection(): SnippetFileCollection
    {
        $collection = new SnippetFileCollection();
        $this->snippetFileLoader->loadSnippetFilesIntoCollection($collection);

        return $collection;
    }
}

class SnippetFileLoaderTest extends TestCase
{
    public function testLoadSnippetsFromShopwareBundle(): void
    {
        $kernel = new MockedKernel(
            [
                'ShopwareBundleWithSnippets' => new ShopwareBundleWithSnippets(),
            ]
        );

        $collection = new SnippetFileCollection();

        $snippetFileLoader = new SnippetFileLoader(
            $kernel,
            $this->createMock(Connection::class),
            $this->createMock(AppSnippetFileLoader::class),
            new ActiveAppsLoader(
                $this->createMock(Connection::class),
                $this->createMock(AppLoader::class),
                '/'
            )
        );

        
static::assertEmpty($snippetSetData['value']);
            } else {
                static::assertSame($value$snippetSetData['value']);
                static::assertSame($originValue$snippetSetData['origin']);
                static::assertSame($resetValue$snippetSetData['resetTo']);
            }
        }
    }

    private function getSnippetService(AbstractSnippetFile ...$snippetFiles): SnippetService
    {
        $collection = new SnippetFileCollection();
        foreach ($snippetFiles as $file) {
            $collection->add($file);
        }

        return new SnippetService(
            $this->getContainer()->get(Connection::class),
            $collection,
            $this->getContainer()->get('snippet.repository'),
            $this->getContainer()->get('snippet_set.repository'),
            $this->getContainer()->get('sales_channel_domain.repository'),
            $this->getContainer()->get(SnippetFilterFactory::class),
            
$resultEn = array_filter(/** * @param array<string, bool|string> $item */ $resultfn (array $item) => $item['iso'] === 'en-GB');

        static::assertCount(2, $resultDe);
        static::assertCount(1, $resultEn);
    }

    private function getCollection(): SnippetFileCollection
    {
        $collection = new SnippetFileCollection();
        $collection->add(new MockSnippetFile('storefront.de-DE', 'de-DE', '{}', true, 'SwagPlugin'));
        $collection->add(new MockSnippetFile('storefront.de-DE_extension', 'de-DE', '{}', false, 'SwagPlugin'));
        $collection->add(new MockSnippetFile('storefront.en-GB', 'en-GB', '{}', true));

        return $collection;
    }
}

class SnippetServiceTest extends TestCase
{
    private SnippetFileCollection $snippetCollection;

    private Connection&MockObject $connection;

    protected function setUp(): void
    {
        $this->connection = $this->createMock(Connection::class);
        $this->snippetCollection = new SnippetFileCollection();
        $this->addThemes();
    }

    /** * @dataProvider getStorefrontSnippetsDataProvider * * @param list<string> $catalogMessages * @param \Throwable|list<string> $expected * @param list<string> $databaseSnippets */
    public function testGetStorefrontSnippets(
        
$administrationFiles = $this->snippetFileHandler->findAdministrationSnippetFiles();
        $storefrontSnippetFiles = $this->snippetFileHandler->findStorefrontSnippetFiles();

        return $this->hydrateFiles(array_merge($deprecatedFiles$administrationFiles$storefrontSnippetFiles));
    }

    /** * @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,
                ''
            ));
        }
new MockedKernel([]),
            $this->getContainer()->get(Connection::class),
            $this->getContainer()->get(AppSnippetFileLoader::class),
            $this->getContainer()->get(ActiveAppsLoader::class)
        );
    }

    public function testLoadSnippetFilesIntoCollectionWithoutSnippetFiles(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/Apps/AppWithoutSnippets');

        $collection = new SnippetFileCollection();

        $this->snippetFileLoader->loadSnippetFilesIntoCollection($collection);

        static::assertCount(0, $collection);
    }

    public function testLoadSnippetFilesIntoCollection(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures/Apps/AppWithSnippets');

        $collection = new SnippetFileCollection();

        
Home | Imprint | This part of the site doesn't use cookies.