noEntityCloned example



        /** @var EntityWrittenContainerEvent $eventContainer */
        $eventContainer = $context->scope(Context::CRUD_API_SCOPE, function DContext $context) use ($definition$id$behavior): EntityWrittenContainerEvent {
            $entityRepo = $this->definitionRegistry->getRepository($definition->getEntityName());

            return $entityRepo->clone($id$context, null, $behavior);
        });

        $event = $eventContainer->getEventByEntityName($definition->getEntityName());
        if (!$event) {
            throw ApiException::noEntityCloned($entity$id);
        }

        $ids = $event->getIds();
        $newId = array_shift($ids);

        return new JsonResponse(['id' => $newId]);
    }

    #[Route(path: '/api/_action/version/{entity}/{id}', name: 'api.createVersion', methods: ['POST'], requirements: ['version' => '\d+', 'entity' => '[a-zA-Z-]+', 'id' => '[0-9a-f]{32}'])]     public function createVersion(Request $request, Context $context, string $entity, string $id): Response
    {
        
public function testUnauthorized(): void
    {
        $exception = ApiException::unauthorized('challenge', 'Message');

        static::assertInstanceOf(UnauthorizedHttpException::class$exception);
        static::assertEquals('Message', $exception->getMessage());
    }

    public function testNoEntityCloned(): void
    {
        $exception = ApiException::noEntityCloned('order', '1234');

        static::assertInstanceOf(NoEntityClonedException::class$exception);
        static::assertEquals('Could not clone entity order with id 1234.', $exception->getMessage());
    }

    public function testExpectationFailed(): void
    {
        $exception = ApiException::expectationFailed([]);

        static::assertInstanceOf(ExpectationFailedException::class$exception);
        static::assertEquals('API Expectations failed', $exception->getMessage());
    }
Home | Imprint | This part of the site doesn't use cookies.