Envelope example

$pathBuilder->expects(static::once())
            ->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(
            
new EntitySearchResult(
                    SalesChannelDomainDefinition::ENTITY_NAME,
                    1,
                    new SalesChannelDomainCollection([$salesChannelDomain]),
                    null,
                    $criteria,
                    $context
                )
            );

        $this->busMock->expects(static::once())->method('dispatch')->with($warmUpMessageExpected)
            ->willReturn(new Envelope($this->createMock(\stdClass::class)));

        $this->cacheWarmer->warmUp();
    }

    public function testWarmUpWithId(): void
    {
        $salesChannelDomain = new SalesChannelDomainEntity();
        $salesChannelDomain->setId(Uuid::randomHex());
        $salesChannelDomain->setUniqueIdentifier(Uuid::randomHex());
        $salesChannelDomain->setUrl('https://localhost');
        $context = Context::createDefaultContext();
        
'nextExecutionTime' => (new \DateTime())->modify('-1 second'),
            ],
        ], Context::createDefaultContext());

        $this->messageBus->expects(static::once())
            ->method('dispatch')
            ->with(static::callback(function DTestTask $task) use ($taskId) {
                static::assertEquals($taskId$task->getTaskId());

                return true;
            }))
            ->willReturn(new Envelope(new TestTask()));

        $this->scheduler->queueScheduledTasks();

        /** @var ScheduledTaskEntity $task */
        $task = $this->scheduledTaskRepo->search(new Criteria([$taskId]), Context::createDefaultContext())->get($taskId);
        static::assertEquals(ScheduledTaskDefinition::STATUS_QUEUED, $task->getStatus());
    }

    public function testScheduleTasksDoesntScheduleFutureTask(): void
    {
        $this->connection->executeStatement('DELETE FROM scheduled_task');

        


/** * @internal */
#[Package('command')] class TestNestedCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $testCause = new TestCause();
        $testCause->throw(new HandlerFailedException(new Envelope(new \stdClass())[new TestException('test')]));

        return Command::SUCCESS;
    }
}

/** * @internal */
#[Package('cause')] class TestCause extends Command
{
    

class CollectingMessageBus implements MessageBusInterface
{
    /** * @var array<Envelope> */
    private array $messages = [];

    public function dispatch(object $message, array $stamps = []): Envelope
    {
        $envelope = new Envelope($message);

        $this->messages[] = $envelope;

        return $envelope;
    }

    /** * @return array<Envelope> */
    public function getMessages(): array
    {
        
$status = $data['status'];
                static::assertEquals($expected ? ScheduledTaskDefinition::STATUS_QUEUED : ScheduledTaskDefinition::STATUS_SKIPPED, $status);
                static::assertEquals('1', $data['id']);

                return new EntityWrittenContainerEvent($contextnew NestedEventCollection()[]);
            });

        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects($expected ? static::once() : static::never())->method('dispatch')->willReturnCallback(function D$message) {
            static::assertInstanceOf(InvalidateCacheTask::class$message);

            return new Envelope($message);
        });

        $scheduler = new TaskScheduler(
            $scheduledTaskRepository,
            $bus,
            new ParameterBag(['shopware.cache.invalidation.delay' => $delay])
        );

        $scheduler->queueScheduledTasks();
    }

    
'id' => $webhookEventId,
            'appName' => 'SwagApp',
            'deliveryStatus' => WebhookEventLogDefinition::STATUS_QUEUED,
            'webhookName' => 'hook1',
            'eventName' => 'order',
            'appVersion' => '0.0.1',
            'url' => 'https://test.com',
            'serializedWebhookMessage' => serialize($webhookEventMessage),
        ]]$this->context);

        $event = new WorkerMessageFailedEvent(
            new Envelope($webhookEventMessage),
            'async',
            new ClientException('test', new Request('GET', 'https://test.com')new Response(500))
        );

        $this->getContainer()->get(RetryWebhookMessageFailedSubscriber::class)
            ->failed($event);

        $webhookEventLog = $webhookEventLogRepository->search(new Criteria([$webhookEventId])$this->context)->first();
        static::assertEquals($webhookEventLog->getDeliveryStatus(), WebhookEventLogDefinition::STATUS_FAILED);
    }
}
unset($actualPayload['source']['eventId']);
                static::assertEquals($payload$actualPayload);
                static::assertEquals($appId$message->getAppId());
                static::assertEquals($webhookId$message->getWebhookId());
                static::assertEquals($shopwareVersion$message->getShopwareVersion());
                static::assertEquals('s3cr3t', $message->getSecret());
                static::assertEquals(Defaults::LANGUAGE_SYSTEM, $message->getLanguageId());
                static::assertEquals('en-GB', $message->getUserLocale());

                return true;
            }))
            ->willReturn(new Envelope(new WebhookEventMessage($webhookEventId$payload$appId$webhookId, '6.4', 'http://test.com', 's3cr3t', Defaults::LANGUAGE_SYSTEM, 'en-GB')));

        $webhookDispatcher = new WebhookDispatcher(
            $this->getContainer()->get('event_dispatcher'),
            $this->getContainer()->get(Connection::class),
            $client,
            $this->shopUrl,
            $this->getContainer(),
            $this->getContainer()->get(HookableEventFactory::class),
            Kernel::SHOPWARE_FALLBACK_VERSION,
            $bus,
            false
        );

class CollectingMessageBus implements MessageBusInterface
{
    /** * @var array<Envelope> */
    private array $messages = [];

    public function dispatch(object $message, array $stamps = []): Envelope
    {
        $envelope = new Envelope($message);

        $this->messages[] = $envelope;

        return $envelope;
    }

    /** * @return array<Envelope> */
    public function getMessages(): array
    {
        
// 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 */
$message = new SitemapMessage(
            TestDefaults::SALES_CHANNEL,
            Defaults::LANGUAGE_SYSTEM,
            null,
            null,
            true
        );

        $this->messageBusMock->expects(static::once())
            ->method('dispatch')
            ->willReturn(new Envelope($message));

        $this->sitemapHandler->run();
    }

    public function testItGeneratesCorrectMessagesIfLastLanguageIsFirstOfNextSalesChannel(): void
    {
        /** @var list<string> $salesChannelIds */
        $salesChannelIds = $this->salesChannelRepository->searchIds(new Criteria(), Context::createDefaultContext())->getIds();

        $nonDefaults = array_values(array_filter(array_map(function Dstring $id): ?array {
            if ($id === TestDefaults::SALES_CHANNEL) {
                
Home | Imprint | This part of the site doesn't use cookies.