CollectingMessageBus example

Feature::skipTestIfActive('ES_MULTILINGUAL_INDEX', $this);

        $this->connection = $this->createMock(Connection::class);
        $this->helper = $this->createMock(ElasticsearchHelper::class);
        $this->registry = new ElasticsearchRegistry([$this->createDefinition('product')]);
        $this->indexCreator = $this->createMock(IndexCreator::class);
        $this->iteratorFactory = $this->createMock(IteratorFactory::class);
        $this->client = $this->createMock(Client::class);
        $this->currencyRepository = $this->createMock(EntityRepository::class);
        $this->languageRepository = $this->createMock(EntityRepository::class);
        $this->newEsIndexer = $this->createMock(MultilingualEsIndexer::class);
        $this->bus = new CollectingMessageBus();

        $this->helper->method('allowIndexing')->willReturn(true);

        $this->language1 = new LanguageEntity();
        $this->language1->setId(Defaults::LANGUAGE_SYSTEM);
        $this->language1->setUniqueIdentifier(Defaults::LANGUAGE_SYSTEM);

        $language2 = new LanguageEntity();
        $language2->setId('2');
        $language2->setUniqueIdentifier('2');

        
private CollectingMessageBus $messageBus;

    private FileSaver $fileSaver;

    protected function setUp(): void
    {
        $this->mediaRepository = $this->createMock(EntityRepository::class);
        $filesystemPublic = $this->createMock(FilesystemOperator::class);
        $urlGenerator = $this->createMock(UrlGeneratorInterface::class);
        $thumbnailService = $this->createMock(ThumbnailService::class);
        $this->messageBus = new CollectingMessageBus();
        $metadataLoader = $this->createMock(MetadataLoader::class);
        $typeDetector = $this->createMock(TypeDetector::class);
        $filesystemPrivate = $this->createMock(FilesystemOperator::class);
        $eventDispatcher = $this->createMock(EventDispatcherInterface::class);

        $this->fileSaver = new FileSaver(
            $this->mediaRepository,
            $filesystemPublic,
            $filesystemPrivate,
            $urlGenerator,
            $thumbnailService,
            
use Shopware\Elasticsearch\Framework\SystemUpdateListener;

/** * @internal * * @covers \Shopware\Elasticsearch\Framework\SystemUpdateListener */
class SystemUpdateListenerTest extends TestCase
{
    public function testShouldDoNothingWhenNotSet(): void
    {
        $messageBus = new CollectingMessageBus();

        $listener = new SystemUpdateListener(
            $this->createMock(AbstractKeyValueStorage::class),
            $this->createMock(ElasticsearchIndexer::class),
            $messageBus
        );

        $listener($this->createMock(UpdatePostFinishEvent::class));

        static::assertCount(0, $messageBus->getMessages());
    }

    
class ProductExportGenerateTaskHandlerTest extends TestCase
{
    /** * @dataProvider shouldBeRunDataProvider */
    public function testShouldBeRun(ProductExportEntity $productExportEntity, bool $expectedResult): void
    {
        $salesChannelRepositoryMock = $this->getSalesChannelRepositoryMock();
        $salesChannelContextFactoryMock = $this->getSalesChannelContextFactoryMock();
        $productExportRepositoryMock = $this->getProductExportRepositoryMock($productExportEntity);

        $messageBusMock = new CollectingMessageBus();

        $productExportGenerateTaskHandler = new ProductExportGenerateTaskHandler(
            $this->createMock(EntityRepository::class),
            $salesChannelContextFactoryMock,
            $salesChannelRepositoryMock,
            $productExportRepositoryMock,
            $messageBusMock
        );

        $productExportGenerateTaskHandler->run();

        
private CollectingMessageBus $bus;

    protected function setUp(): void
    {
        $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
        $this->connection = $this->createMock(Connection::class);
        $this->clientMock = new MockHandler([new Response(200)]);
        $this->client = new Client(['handler' => HandlerStack::create($this->clientMock)]);
        $this->container = new Container();
        $this->eventFactory = $this->createMock(HookableEventFactory::class);
        $this->bus = new CollectingMessageBus();
    }

    public function testDispatchWithWebhooksSync(): void
    {
        $event = new AppFlowActionEvent('foobar', ['foo' => 'bar']['foo' => 'bar']);

        $webhookEntity = $this->getWebhookEntity($event->getName());
        $this->prepareContainer($webhookEntity);

        $this->dispatcher->expects(static::once())->method('dispatch')->with($event$event->getName())->willReturn($event);

        

#[Package('system-settings')] class ImportExportHandlerTest extends TestCase
{
    /** * @dataProvider dataProviderForTestImportExport */
    public function testImportExportHandlerDispatchesMessage(string $activity): void
    {
        $messageBus = new CollectingMessageBus();

        $factory = $this->createMock(ImportExportFactory::class);

        $adminSource = new AdminApiSource('userId');
        $adminSource->setIsAdmin(true);
        $context = Context::createDefaultContext($adminSource);

        $importExportHandler = new ImportExportHandler($messageBus$factory);

        $logEntity = new ImportExportLogEntity();
        $logEntity->setActivity($activity);
        
$expectedMessageNonStrict = new UpdateThumbnailsMessage();

        if (Feature::isActive('v6.6.0.0')) {
            $expectedMessageNonStrict->setContext($this->context);
        } else {
            $expectedMessageNonStrict->withContext($this->context);
        }

        $expectedMessageNonStrict->setIsStrict(false);
        $expectedMessageNonStrict->setMediaIds($affectedMediaIds);

        $messageBusMock = new CollectingMessageBus();

        $command = new GenerateThumbnailsCommand(
            $this->getContainer()->get(ThumbnailService::class),
            $this->mediaRepository,
            $this->mediaFolderRepository,
            $messageBusMock,
        );

        $this->runCommand($commandnew StringInput('--strict --async')$output);
        $this->runCommand($commandnew StringInput('--async')$output);
        $this->runCommand($commandnew StringInput('--async')$output);
        
$event
            ->expects(static::never())
            ->method('getWriteResults');

        $subscriber->onSalesChannelWritten($event);
    }

    public function testOnNewLanguageIndexGetsCreated(): void
    {
        Feature::skipTestIfActive('ES_MULTILINGUAL_INDEX', $this);

        $bus = new CollectingMessageBus();

        $elasticsearchHelper = $this->createMock(ElasticsearchHelper::class);
        $elasticsearchHelper->expects(static::once())->method('allowIndexing')->willReturn(true);

        $subscriber = new LanguageSubscriber(
            $elasticsearchHelper,
            $this->createMock(ElasticsearchRegistry::class),
            $this->createMock(Client::class),
            $this->createMock(ProductDefinition::class),
            $bus
        );

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