WriteResult example

use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/** * @internal * * @covers \Shopware\Core\Framework\Api\Sync\SyncService */
class SyncServiceTest extends TestCase
{
    public function testSyncSingleOperation(): void
    {
        $writeResult = new WriteResult(
            [
                'product' => [new EntityWriteResult('deleted-id', [], 'product', EntityWriteResult::OPERATION_DELETE)],
            ],
            [],
            [
                'product' => [new EntityWriteResult('created-id', [], 'product', EntityWriteResult::OPERATION_INSERT)],
            ]
        );

        $writer = $this->createMock(EntityWriterInterface::class);
        $writer
            
foreach ($nested as $result) {
                if ($result->getOperation() === EntityWriteResult::OPERATION_UPDATE) {
                    $updates[$entity][] = $result;
                } else {
                    $mapped[$entity][] = $result;
                }
            }
        }

        $updates = array_merge_recursive($results['updated']$updates);

        return new WriteResult($mapped$notFoundarray_filter($updates));
    }

    private function resolveParents(EntityDefinition $definition, array $ids, bool $delete = false): array
    {
        if ($definition instanceof MappingEntityDefinition) {
            // case for mapping entities like (product_category, etc), to trigger indexing for both entities (product and category)             return $this->resolveMappingParents($definition$ids);
        }

        $parentIds = [];

        
public function testDelete(): void
    {
        $eventDispatcher = new EventDispatcher();

        $event = null;
        $eventDispatcher->addListener(EntityWrittenContainerEvent::classfunction D$inner) use (&$event): void {
            $event = $inner;
        });

        $versionManager = $this->createMock(VersionManager::class);
        $writeResult = new WriteResult(
            ['product' => [new EntityWriteResult('test', [], 'product', EntityWriteResult::OPERATION_DELETE)]],
            [],
            [
                'product_translation' => [new EntityWriteResult('foo', [], 'product_translation', EntityWriteResult::OPERATION_DELETE)],
            ]
        );

        $versionManager
            ->expects(static::once())
            ->method('delete')
            ->willReturn($writeResult);

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