getExceptions example

foreach ($writeCommands as $command) {
            if ($command->getDefinition()->getClass() === ImportExportProfileDefinition::class
                && $command instanceof DeleteCommand
            ) {
                $ids[] = $command->getPrimaryKey()['id'];
            }
        }

        $filteredIds = $this->filterSystemDefaults($ids);
        if (!empty($filteredIds)) {
            $event->getExceptions()->add(new DeleteDefaultProfileException($filteredIds));
        }
    }

    private function filterSystemDefaults(array $ids): array
    {
        if (empty($ids)) {
            return [];
        }

        $result = $this->connection->executeQuery(
            'SELECT id FROM import_export_profile WHERE id IN (:idList) AND system_default = 1',
            [
$parameters = new WriteParameterBag(
            $registry->get(WebhookDefinition::class),
            WriteContext::createFromContext($context),
            '',
            new WriteCommandQueue(),
            new PrimaryKeyBag()
        );

        $extractor->extract($data$parameters);

        if ($valid) {
            static::assertCount(0, $parameters->getContext()->getExceptions()->getExceptions());

            return;
        }

        static::assertCount(1, $parameters->getContext()->getExceptions()->getExceptions());
        $exception = $parameters->getContext()->getExceptions()->getExceptions();
        $exception = \array_shift($exception);

        static::assertInstanceOf(WriteConstraintViolationException::class$exception);

        $violations = $exception->getViolations();
        
foreach ($payload as $index => $row) {
                    $parameters->setPath('/' . $key . '/' . $index);
                    $context->resetPaths();
                    $this->commandExtractor->extract($row$parameters);
                }

                $writes[] = $this->factory->resolveWrite($definition$payload);
            }
        }

        $context->getExceptions()->tryToThrow();

        $this->gateway->execute($commandQueue->getCommandsInOrder()$context);

        $result = $this->factory->build($commandQueue);

        $notFound = array_merge_recursive(...$notFound);

        $writes = array_merge_recursive(...$writes);

        $deletes = array_merge_recursive(...$deletes);

        


        $fakeConnection = new FakeConnection([]);

        $event = new PreWriteValidationEvent($this->context, $commands);
        $validator = new ShippingMethodValidator($fakeConnection);
        $validator->preValidate($event);

        $exception = null;

        try {
            $event->getExceptions()->tryToThrow();
        } catch (WriteException $e) {
            $exception = $e;
        }

        if (!$success) {
            static::assertNotNull($exception);
            static::assertEquals(WriteConstraintViolationException::class$exception->getExceptions()[0]::class);
        } else {
            static::assertNull($exception);
        }
    }

    
$this->buildViolation(
                        'The defined tax rate is required when fixed tax present',
                        ['{{ taxId }}' => null],
                        '/taxId',
                        $taxType,
                        self::VIOLATION_TAX_ID_REQUIRED
                    )
                );
            }

            if ($violations->count() > 0) {
                $event->getExceptions()->add(new WriteConstraintViolationException($violations$command->getPath()));
            }
        }
    }

    /** * @return array<string, mixed> */
    private function findShippingMethod(string $shippingMethodId): array
    {
        $shippingMethod = $this->connection->executeQuery(
            'SELECT `tax_type`, `tax_id` FROM `shipping_method` WHERE `id` = :id',
            [
null,
                null,
                null,
                $this->getSalesChannelConfiguration($input$output)
            );

            $io->success('Sales channel has been created successfully.');
        } catch (WriteException $exception) {
            $io->error('Something went wrong.');

            $messages = [];
            foreach ($exception->getExceptions() as $err) {
                if ($err instanceof WriteConstraintViolationException) {
                    foreach ($err->getViolations() as $violation) {
                        $messages[] = $violation->getPropertyPath() . ': ' . $violation->getMessage();
                    }
                }
            }

            $io->listing($messages);

            return self::SUCCESS;
        }

        
$stack = new DataStack($data);
        $existence = EntityExistence::createEmpty();
        $fieldPath = $parameters->getPath() . '/' . $field->getPropertyName();

        $propertyKeys = array_map(fn (Field $field) => $field->getPropertyName()$field->getPropertyMapping());

        // If a mapping is defined, you should not send properties that are undefined.         // Sending undefined fields will throw an UnexpectedFieldException         $keyDiff = array_diff(array_keys($data)$propertyKeys);
        if (\count($keyDiff)) {
            foreach ($keyDiff as $fieldName) {
                $parameters->getContext()->getExceptions()->add(
                    new UnexpectedFieldException($fieldPath . '/' . $fieldName(string) $fieldName)
                );
            }
        }

        foreach ($field->getPropertyMapping() as $nestedField) {
            $kvPair = $stack->pop($nestedField->getPropertyName());

            if ($kvPair === null) {
                // The writer updates the whole field, so there is no possibility to update                 // "some" fields. To enable a merge, we have to respect the $existence state
/** @var WriteException|null $e */
        $e = null;

        try {
            $this->repository->upsert($data, Context::createDefaultContext());
        } catch (\Exception $e) {
        }

        static::assertInstanceOf(WriteException::class$e);

        /** @var WriteConstraintViolationException $constraintViolation */
        $constraintViolation = $e->getExceptions()[0];
        static::assertInstanceOf(WriteConstraintViolationException::class$constraintViolation);

        static::assertSame('/taxId', $constraintViolation->getViolations()->get(0)->getPropertyPath());

        $data = [
            [
                'id' => $child,
                'productNumber' => Uuid::randomHex(),
                'stock' => 10,
                'parentId' => null,
                'name' => 'Child transformed to parent',
                
$discount,
                        $command->getPayload(),
                        $violationList,
                        $index
                    );

                    break;
            }
        }

        if ($violationList->count() > 0) {
            $event->getExceptions()->add(new WriteConstraintViolationException($violationList));
        }
    }

    /** * This function collects all database data that might be * required for any of the received entities and values. * * @param array<WriteCommand> $writeCommands * * @throws PromotionException * @throws Exception */
sprintf($message$entity),
                sprintf($message, '{{ entity }}'),
                ['{{ entity }}' => $entity],
                null,
                '/',
                null,
                null,
                self::VIOLATION_LOCKED
            ));
        }

        $event->getExceptions()->add(new WriteConstraintViolationException($violations));
    }

    /** * @param WriteCommand[] $writeCommands * * @return array<string, bool> */
    private function containsLockedEntities(array $writeCommands): array
    {
        $ids = [];
        $locked = [];

        
$context = Context::createDefaultContext();

        $e = null;

        try {
            $this->categoryRepository->upsert([$category]$context);
        } catch (WriteException $e) {
        }

        static::assertInstanceOf(WriteException::class$e);

        static::assertCount(1, $e->getExceptions());
        $first = $e->getExceptions()[0];

        static::assertInstanceOf(ExpectedArrayException::class$first);
        static::assertEquals('/0/children', $first->getPath());
    }

    public function testICanWriteChildren(): void
    {
        $parent = Uuid::randomHex();
        $child1 = Uuid::randomHex();
        $child2 = Uuid::randomHex();

        
$defaultContext = Context::createDefaultContext();
        $paymentMethod = $this->createPaymentMethodDummyArray();

        unset($paymentMethod[0]['name']);

        try {
            $this->paymentRepository->create($paymentMethod$defaultContext);

            static::fail('The name should always be required!');
        } catch (WriteException $e) {
            /** @var WriteConstraintViolationException $constraintViolation */
            $constraintViolation = $e->getExceptions()[0];
            static::assertInstanceOf(WriteConstraintViolationException::class$constraintViolation);
            static::assertEquals('/name', $constraintViolation->getViolations()->get(0)->getPropertyPath());
        }
    }

    /** * @return array<int, array<string, mixed>> */
    private function createPaymentMethodDummyArray(): array
    {
        return [
            [
foreach ($states as $record) {
            $id = (string) $record['sales_channel_id'];
            $mapping[$id]['current_default'] = $record['current_default'];
            $mapping[$id]['state'][] = $record['language_id'];
        }

        return $mapping;
    }

    private function writeViolationException(ConstraintViolationList $violations, PreWriteValidationEvent $event): void
    {
        $event->getExceptions()->add(new WriteConstraintViolationException($violations));
    }
}
null,
                '/' . $id,
                $id,
                null,
                self::VIOLATION_DELETE_DEFAULT_CURRENCY
            );

            $violations->add($violation);
        }

        if ($violations->count() > 0) {
            $event->getExceptions()->add(new WriteConstraintViolationException($violations));
        }
    }
}


        $e = null;

        try {
            $this->service->sync([$operation], Context::createDefaultContext()new SyncBehavior());
        } catch (WriteException $e) {
        }

        static::assertInstanceOf(WriteException::class$e);

        static::assertCount(4, $e->getExceptions());
        $first = $e->getExceptions()[0];

        /** @var WriteConstraintViolationException $first */
        static::assertInstanceOf(WriteConstraintViolationException::class$first);
        static::assertStringStartsWith('/manufacturers/1/translations', $first->getPath());
    }

    public function testDeleteWithWildCards(): void
    {
        $ids = new IdsCollection();

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