EntityWrittenContainerEvent example


                'name' => 'hook1',
                'eventName' => ProductEvents::PRODUCT_WRITTEN_EVENT,
                'url' => 'https://test.com',
            ],
        ]$context);

        $this->appendNewResponse(new Response(200));

        $id = Uuid::randomHex();

        $event = new EntityWrittenContainerEvent(
            $context,
            new NestedEventCollection([
                new EntityWrittenEvent(
                    ProductDefinition::ENTITY_NAME,
                    [
                        new EntityWriteResult(
                            $id,
                            [
                                'id' => $id,
                                'name' => 'testProduct',
                                'productNumber' => 'SWC-1000',
                                
$address->setId(Uuid::randomHex());
        $result->method('first')->willReturn($address);

        $addressRepository = $this->createMock(EntityRepository::class);
        $addressRepository->method('search')->willReturn($result);
        $addressRepository
            ->expects(static::once())
            ->method('upsert')
            ->willReturnCallback(function Darray $data) {
                static::assertSame(['mapped' => 1]$data[0]['customFields']);

                return new EntityWrittenContainerEvent(Context::createDefaultContext()new NestedEventCollection([])[]);
            });

        $customFieldMapper = $this->createMock(StoreApiCustomFieldMapper::class);
        $customFieldMapper
            ->expects(static::once())
            ->method('map')
            ->with(CustomerAddressDefinition::ENTITY_NAME, new RequestDataBag([
                'test' => 1,
                'mapped' => 1,
            ]))
            ->willReturn(['mapped' => 1]);

        
/** * @experimental */
    public function create(array $data, Context $context): EntityWrittenContainerEvent
    {
        $writeResults = $this->getDummyWriteResults($data, EntityWriteResult::OPERATION_INSERT, $context);
        /** @var EntityWrittenEvent $entityWrittenEvent */
        $entityWrittenEvent = $writeResults->first();

        $this->creates[] = $entityWrittenEvent->getPayloads();

        return new EntityWrittenContainerEvent($context$writeResults[]);
    }

    /** * @experimental */
    public function update(array $data, Context $context): EntityWrittenContainerEvent
    {
        $this->updates[] = $data;

        return new EntityWrittenContainerEvent(
            $context,
            
public function testGetSubscribedEvents(): void
    {
        static::assertArrayHasKey(EntityWrittenContainerEvent::class, EntityIndexingSubscriber::getSubscribedEvents());
    }

    public function testRefresh(): void
    {
        $registry = $this->createMock(EntityIndexerRegistry::class);
        $registry->expects(static::once())->method('refresh');

        $subscriber = new EntityIndexingSubscriber($registry);
        $subscriber->refreshIndex(new EntityWrittenContainerEvent(Context::createDefaultContext()new NestedEventCollection()[]));
    }
}
 $queueTaskPayload$scheduledTaskPayload ] = $data;

            static::assertArrayHasKey('status', $queueTaskPayload);
            static::assertArrayHasKey('status', $scheduledTaskPayload);
            static::assertArrayHasKey('id', $queueTaskPayload);
            static::assertArrayHasKey('id', $scheduledTaskPayload);
            static::assertEquals(ScheduledTaskDefinition::STATUS_SKIPPED, $queueTaskPayload['status']);
            static::assertEquals('queuedTask', $queueTaskPayload['id']);
            static::assertEquals(ScheduledTaskDefinition::STATUS_SKIPPED, $scheduledTaskPayload['status']);
            static::assertEquals('scheduledTask', $scheduledTaskPayload['id']);

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

        $this->scheduleTaskRepository->expects(static::never())->method('delete');
        $this->scheduleTaskRepository->expects(static::never())->method('create');

        $registry->registerTasks();
    }

    public function testQueuedOrSkippedTasksShouldBecomeScheduled(): void
    {
        $tasks = [new InvalidateCacheTask()new CreateAliasTask()];

        
$flowEventMock->method('getCustomEvents')->willReturn($customEventsMock);

        $this->flowEventsRepositoryMock->expects(static::once())->method('upsert')->willReturnCallback(function D$upserts$context) use ($appId): EntityWrittenContainerEvent {
            static::assertSame([
                [
                    'appId' => $appId,
                    'name' => 'value',
                    'aware' => [],
                ],
            ]$upserts);

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

        $this->flowEventsRepositoryMock->expects(static::once())->method('delete')->willReturnCallback(function D$ids$context) use ($appId): EntityWrittenContainerEvent {
            static::assertSame([['id' => Uuid::fromHexToBytes($appId)]]$ids);

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

        $context = Context::createDefaultContext();
        $this->flowEventPersister->updateEvents($flowEventMock$appId$context, 'en-GB');
    }

    


    public function testOnEntityWritten(): void
    {
        $context = Context::createDefaultContext();

        $idA = Uuid::randomHex();
        $idB = Uuid::randomBytes();
        $idC = Uuid::randomBytes();
        $idD = Uuid::randomBytes();

        $event = new EntityWrittenContainerEvent($contextnew NestedEventCollection([
            new EntityWrittenEvent('many_to_one', [
                new EntityWriteResult($idA[], 'many_to_one', EntityWriteResult::OPERATION_INSERT),
            ]$context[]),
            new EntityWrittenEvent('one_to_many', [
                new EntityWriteResult($idA['ruleId' => $idA], 'one_to_many', EntityWriteResult::OPERATION_INSERT),
                new EntityWriteResult($idA[], 'one_to_many', EntityWriteResult::OPERATION_UPDATE, null, new ChangeSet(
                    ['rule_id' => $idB],
                    ['rule_id' => $idC],
                    false
                )),
                new EntityWriteResult($idA[], 'one_to_many', EntityWriteResult::OPERATION_DELETE, null, new ChangeSet(
                    [

                false
            );

        $subscriber = new CacheInvalidationSubscriber(
            $cacheInvalidator,
            $this->createMock(Connection::class),
            false,
            false
        );

        $subscriber->invalidateContext(new EntityWrittenContainerEvent(
            Context::createDefaultContext(),
            new NestedEventCollection([
                new EntityWrittenEvent(
                    SalesChannelDefinition::ENTITY_NAME,
                    [
                        new EntityWriteResult(
                            $salesChannelId,
                            [],
                            SalesChannelDefinition::ENTITY_NAME,
                            EntityWriteResult::OPERATION_UPDATE,
                        ),
                    ],
$result->method('getEntities')->willReturn(new ScheduledTaskCollection([$scheduledTask]));
        $scheduledTaskRepository->expects(static::once())->method('search')->willReturn($result);
        $scheduledTaskRepository->expects(static::once())->method('update')->willReturnCallback(function Darray $data, Context $context) {
            static::assertCount(1, $data);
            $data = $data[0];
            static::assertArrayHasKey('id', $data);
            static::assertArrayHasKey('nextExecutionTime', $data);
            static::assertArrayHasKey('status', $data);
            static::assertEquals('1', $data['id']);
            static::assertEquals(ScheduledTaskDefinition::STATUS_SKIPPED, $data['status']);

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

        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(static::never())->method('dispatch');
        $scheduler = new TaskScheduler(
            $scheduledTaskRepository,
            $bus,
            new ParameterBag([
                'shopware.cache.invalidation.delay' => 0,
            ])
        );

        
'textBoosted' => ['type' => 'text'],
        ];

        static::assertEquals($expectedProperties$properties);
    }

    public function testRefresh(): void
    {
        $c = $this->getContainer()->get(Connection::class);
        static::assertEmpty($c->fetchAllAssociative('SELECT `index` FROM `admin_elasticsearch_index_task`'));

        $this->registry->refresh(new EntityWrittenContainerEvent(Context::createDefaultContext()new NestedEventCollection([
            new EntityWrittenEvent('promotion', [
                new EntityWriteResult(
                    'c1a28776116d4431a2208eb2960ec340',
                    [],
                    'promotion',
                    EntityWriteResult::OPERATION_INSERT
                ),
            ], Context::createDefaultContext()),
        ])[]));

        $index = $c->fetchOne('SELECT `index` FROM `admin_elasticsearch_index_task`');

        
$index = new AdminSearchRegistry(
            ['promotion' => $this->indexer],
            $connection,
            $this->createMock(MessageBusInterface::class),
            $this->createMock(EventDispatcherInterface::class),
            $client,
            $searchHelper,
            [],
            []
        );

        $index->refresh(new EntityWrittenContainerEvent(Context::createDefaultContext()new NestedEventCollection([
            new EntityWrittenEvent('promotion', [
                new EntityWriteResult(
                    'c1a28776116d4431a2208eb2960ec340',
                    [],
                    'promotion',
                    EntityWriteResult::OPERATION_INSERT
                ),
            ], Context::createDefaultContext()),
        ])[]));
    }

    
->method('allowIndexing');

        $connection = $this->createMock(Connection::class);

        $customFieldUpdater = new CustomFieldUpdater(
            $this->createMock(ElasticsearchOutdatedIndexDetector::class),
            $this->createMock(Client::class),
            $elasticsearchHelper,
            $connection
        );

        $containerEvent = new EntityWrittenContainerEvent(
            Context::createDefaultContext(),
            new NestedEventCollection(),
            []
        );

        $customFieldUpdater->onNewCustomFieldCreated($containerEvent);
    }

    public function testElasticsearchDisabled(): void
    {
        $elasticsearchHelper = $this->createMock(ElasticsearchHelper::class);
        
$customerRepository = $this->createMock(EntityRepository::class);
        $customerRepository->method('search')->willReturn($result);
        $customerRepository
            ->expects(static::once())
            ->method('create')
            ->willReturnCallback(function Darray $create) {
                static::assertCount(1, $create);
                static::assertArrayHasKey('accountType', $create[0]);
                static::assertSame(CustomerEntity::ACCOUNT_TYPE_PRIVATE, $create[0]['accountType']);

                return new EntityWrittenContainerEvent(Context::createDefaultContext()new NestedEventCollection([])[]);
            });

        $register = new RegisterRoute(
            new EventDispatcher(),
            $this->createMock(NumberRangeValueGeneratorInterface::class),
            $this->createMock(DataValidator::class),
            $this->createMock(DataValidationFactoryInterface::class),
            $this->createMock(DataValidationFactoryInterface::class),
            $systemConfigService,
            $customerRepository,
            $this->createMock(SalesChannelContextPersister::class),
            
static::assertNotNull($data[0]['deliveries']);
                static::assertNotNull($data[0]['deliveries'][0]);
                static::assertSame($data[0]['deliveries'][0]['stateId']$orderEntity->getDeliveries()?->first()?->getStateId());

                static::assertSame($context->getTaxState(), CartPrice::TAX_STATE_FREE);

                /** @var CartPrice $price */
                $price = $data[0]['price'];

                static::assertSame($price->getTaxStatus(), CartPrice::TAX_STATE_FREE);

                return new EntityWrittenContainerEvent(Context::createDefaultContext()new NestedEventCollection([
                    new EntityWrittenEvent('order', [new EntityWriteResult('created-id', [], 'order', EntityWriteResult::OPERATION_INSERT)], Context::createDefaultContext()),
                ])[]);
            });

        $this->orderConverter
            ->expects(static::once())
            ->method('assembleSalesChannelContext')
            ->willReturnCallback(function DOrderEntity $order, Context $context) {
                $context->setTaxState($order->getTaxStatus());

                $salesChannel = new SalesChannelEntity();
                


    public function search(Criteria $criteria, Context $context): EntitySearchResult
    {
        throw new \Error('MockRepository->search: Not implemented');
    }

    public function update(array $data, Context $context): EntityWrittenContainerEvent
    {
        ++$this->updateCalls;

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

    public function upsert(array $data, Context $context): EntityWrittenContainerEvent
    {
        ++$this->upsertCalls;

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

    public function create(array $data, Context $context): EntityWrittenContainerEvent
    {
        
Home | Imprint | This part of the site doesn't use cookies.