MockSnippetFile example


class SnippetFileCollectionFactoryTest extends TestCase
{
    public function testCreateSnippetFileCollection(): void
    {
        $snippetFileLoaderMock = $this->createMock(SnippetFileLoaderInterface::class);
        $snippetFileLoaderMock->expects(static::once())
            ->method('loadSnippetFilesIntoCollection')
            ->willReturnCallback(function DSnippetFileCollection $fileCollection): void {
                $fileCollection->add(new MockSnippetFile('storefront.de-DE', 'de-DE', '{}', true));
            });

        $factory = new SnippetFileCollectionFactory($snippetFileLoaderMock);

        $collection = $factory->createSnippetFileCollection();

        static::assertCount(1, $collection);
    }
}
public function testGetStorefrontSnippetsForNotExistingSnippetSet(): void
    {
        $this->expectException(\InvalidArgumentException::class);

        $service = $this->getSnippetService();

        $service->getStorefrontSnippets($this->getCatalog([], 'en-GB'), Uuid::randomHex());
    }

    public function testGetRegionFilterItems(): void
    {
        $snippetFile = new MockSnippetFile(
            'foo',
            'foo',
            <<<json { "foo": { "baz": "foo_baz", "bas": "foo_bas" }, "bar": { "zz": "bar_zz" } }
$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;
    }
}
'salesChannelId' => Uuid::randomHex(),
            'withThemeRegistry' => true,
            'usedTheme' => 'SwagTheme',
            'databaseSnippets' => [
                'title' => 'Database title',
            ],
        ];
    }

    private function addThemes(): void
    {
        $this->snippetCollection->add(new MockSnippetFile('storefront.de-DE', 'de-DE', '{}', true, 'Storefront'));
        $this->snippetCollection->add(new MockSnippetFile('storefront.en-GB', 'en-GB', '{}', true, 'Storefront'));
        $this->snippetCollection->add(new MockSnippetFile('swagtheme.de-DE', 'de-DE', '{}', true, 'SwagTheme'));
        $this->snippetCollection->add(new MockSnippetFile('swagtheme.en-GB', 'en-GB', '{}', true, 'SwagTheme'));
    }
}
Home | Imprint | This part of the site doesn't use cookies.