DeleteThemeFilesMessage example

use Shopware\Storefront\Theme\Message\DeleteThemeFilesMessage;

/** * @internal * * @covers \Shopware\Storefront\Theme\Message\DeleteThemeFilesMessage */
class DeleteThemeFilesMessageTest extends TestCase
{
    public function testStruct(): void
    {
        $message = new DeleteThemeFilesMessage('path', 'salesChannel', 'theme');

        static::assertEquals('path', $message->getThemePath());
        static::assertEquals('salesChannel', $message->getSalesChannelId());
        static::assertEquals('theme', $message->getThemeId());
    }
}
/** * @internal * * @covers \Shopware\Storefront\Theme\Message\DeleteThemeFilesHandler */
class DeleteThemeFilesHandlerTest extends TestCase
{
    public function testFilesAreDeletedIfPathIsCurrentlyNotActive(): void
    {
        $currentPath = 'path';

        $message = new DeleteThemeFilesMessage($currentPath, 'salesChannel', 'theme');

        $filesystem = $this->createMock(FilesystemOperator::class);
        $filesystem->expects(static::once())->method('deleteDirectory')->with($currentPath);

        $handler = new DeleteThemeFilesHandler(
            $filesystem,
            // the path builder will generate a different path then the hard coded one             new MD5ThemePathBuilder()
        );

        $handler($message);
    }
// only delete the old directory if the `themePathBuilder` actually returned a new path and supports seeding         if ($themePrefix !== $oldThemePrefix) {
            $stamps = [];

            if ($this->themeFileDeleteDelay > 0) {
                // also delete with a delay, so that the old theme is still available for a while in case some CDN delivers stale content                 // delay is configured in seconds, symfony expects milliseconds                 $stamps[] = new DelayStamp($this->themeFileDeleteDelay * 1000);
            }
            $this->messageBus->dispatch(
                new Envelope(
                    new DeleteThemeFilesMessage($oldThemePrefix$salesChannelId$themeId),
                    $stamps
                )
            );
        }

        // Reset cache buster state for improving performance in getMetadata         $this->logger->invalidate(['theme-metaData'], true);
    }

    /** * @param array<string, string> $resolveMappings */
->method('generateNewPath')
            ->with(
                TestDefaults::SALES_CHANNEL,
                'test'
            )
            ->willReturn('new');
        $pathBuilder->expects(static::once())
            ->method('saveSeed')
            ->with(TestDefaults::SALES_CHANNEL, 'test');

        $expectedEnvelope = new Envelope(
            new DeleteThemeFilesMessage('current', TestDefaults::SALES_CHANNEL, 'test'),
            [new DelayStamp(900000)]
        );

        $messageBusMock = $this->createMock(MessageBusInterface::class);
        $messageBusMock->expects(static::once())
            ->method('dispatch')
            ->with($expectedEnvelope)
            ->willReturn($expectedEnvelope);

        $compiler = new ThemeCompiler(
            $fs,
            
Home | Imprint | This part of the site doesn't use cookies.