getDispatchedMessages example

public function collect(Request $request, Response $response, \Throwable $exception = null): void
    {
        // Noop. Everything is collected live by the traceable buses & cloned as late as possible.     }

    public function lateCollect(): void
    {
        $this->data = ['messages' => [], 'buses' => array_keys($this->traceableBuses)];

        $messages = [];
        foreach ($this->traceableBuses as $busName => $bus) {
            foreach ($bus->getDispatchedMessages() as $message) {
                $debugRepresentation = $this->cloneVar($this->collectMessage($busName$message));
                $messages[] = [$debugRepresentation$message['callTime']];
            }
        }

        // Order by call time         usort($messagesfn ($a$b) => $a[1] <=> $b[1]);

        // Keep the messages clones only         $this->data['messages'] = array_column($messages, 0);
    }

    
$logEntity = $importExportService->prepareImport(
            $context,
            $profileId,
            $expireDate,
            $file
        );

        $importExportMessage = new ImportExportMessage($context$logEntity->getId(), ImportExportLogEntity::ACTIVITY_IMPORT);

        $importExportHandler->__invoke($importExportMessage);

        $messages = $messageBus->getDispatchedMessages();

        $importExportMessage = null;
        foreach ($messages as $message) {
            if (isset($message['message']) && $message['message'] instanceof ImportExportMessage) {
                $importExportMessage = $message['message'];
            }
        }

        static::assertNotNull($importExportMessage);
        static::assertEquals($logEntity->getId()$importExportMessage->getLogId());
        static::assertEquals($logEntity->getActivity()$importExportMessage->getActivity());

        
$newsletterRecipient = [
            'id' => $id,
        ];

        $this->getContainer()
            ->get('newsletter_recipient.repository')
            ->delete([$newsletterRecipient]$context);

        $messageBus = $this->getContainer()->get('messenger.bus.shopware');
        static::assertInstanceOf(TraceableMessageBus::class$messageBus);

        foreach ($messageBus->getDispatchedMessages() as $message) {
            if (isset($message['message']) && $message['message'] instanceof NewsletterRecipientIndexingMessage) {
                $this->getContainer()->get(NewsletterRecipientIndexer::class)->handle($message['message']);
            }
        }
    }
}
        $this->createTestEntity($now->sub(new \DateInterval('P30M')), 3600, 'Testexport.csv');

        // Create a second ProductExport, last exported 30 minutes ago, to be exported every hour         $this->createTestEntity($now->sub(new \DateInterval('PT30M')), 3600, 'Testexport1.csv');

        /** @var TraceableMessageBus $bus */
        $bus = $this->getContainer()->get('messenger.bus.shopware');
        static::assertInstanceOf(TraceableMessageBus::class$bus);

        $this->clearQueue();
        // Since clearing the queue doesn't seem to really work, check difference in message number         $messagesBefore = $this->getDispatchedMessages();
        $this->getTaskHandler()->run();
        $messagesAfter = $this->getDispatchedMessages();

        static::assertCount(\count($messagesBefore) + 1, $messagesAfter);
    }

    /** * @group quarantined */
    public function testGeneratedAtIsNullWorks(): void
    {
        
$handler->run();

        // Expired log and file entities should've been deleted, not yet expired should still exist         static::assertTrue($this->logEntityExists($logIdA));
        static::assertTrue($this->fileEntityExists($fileIdA));
        static::assertFalse($this->logEntityExists($logIdB));
        static::assertFalse($this->fileEntityExists($fileIdB));

        // Actual file should get deleted from filesystem         static::assertTrue($this->filesystem->fileExists($expiredFilePath));

        $messages = $this->messageBus->getDispatchedMessages();
        $deleteFileMessage = null;
        foreach ($messages as $message) {
            if (isset($message['message']) && $message['message'] instanceof DeleteFileMessage) {
                $deleteFileMessage = $message['message'];
            }
        }
        static::assertNotNull($deleteFileMessage);

        $this->deleteFileHandler->__invoke($deleteFileMessage);
        static::assertFalse($this->filesystem->fileExists($expiredFilePath));
    }

    
public function testItTracesDispatch()
    {
        $message = new DummyMessage('Hello');

        $stamp = new DelayStamp(5);
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects($this->once())->method('dispatch')->with($message[$stamp])->willReturn(new Envelope($message[$stamp]));

        $traceableBus = new TraceableMessageBus($bus);
        $line = __LINE__ + 1;
        $traceableBus->dispatch($message[$stamp]);
        $this->assertCount(1, $tracedMessages = $traceableBus->getDispatchedMessages());
        $actualTracedMessage = $tracedMessages[0];
        unset($actualTracedMessage['callTime']); // don't check, too variable         $this->assertEquals([
            'message' => $message,
            'stamps' => [$stamp],
            'stamps_after_dispatch' => [$stamp],
            'caller' => [
                'name' => 'TraceableMessageBusTest.php',
                'file' => __FILE__,
                'line' => $line,
            ],
        ],

                'HTTP_CONTENT_TYPE' => 'application/json',
            ],
            json_encode(['skip' => ['category.indexer']], \JSON_THROW_ON_ERROR)
        );

        /** @var JsonResponse $response */
        $response = $this->getBrowser()->getResponse();

        static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()print_r($response->getContent(), true));

        $messages = $bus->getDispatchedMessages();

        $hasSalesChannelIndexerMessage = false;
        $hasCategoryIndexerMessage = false;
        foreach ($messages as $message) {
            if (isset($message['message']) && $message['message'] instanceof IterateEntityIndexerMessage) {
                $hasSalesChannelIndexerMessage = $hasSalesChannelIndexerMessage ?: $message['message']->getIndexer() === 'sales_channel.indexer';
                $hasCategoryIndexerMessage = $hasCategoryIndexerMessage ?: $message['message']->getIndexer() === 'category.indexer';
            }
        }

        static::assertTrue($hasSalesChannelIndexerMessage);
        
Home | Imprint | This part of the site doesn't use cookies.