InvalidIdentifierException example

$serializer = new EntitySerializer();
        $serializerRegistry = $this->getContainer()->get(SerializerRegistry::class);
        $serializer->setRegistry($serializerRegistry);
        $return = $serializer->deserialize(new Config([][][])$productDefinition$importData);
        $return = \is_array($return) ? $return : iterator_to_array($return);

        static::assertSame($expectedData$return);
    }

    public function testEnsureIdFieldsWithInvalidCharacter(): void
    {
        static::expectExceptionObject(new InvalidIdentifierException('invalid|string_with_pipe'));

        /** @var EntityDefinition $productDefinition */
        $productDefinition = $this->getContainer()->get(ProductDefinition::class);

        [$expectedData$importData] = require __DIR__ . '/../../../fixtures/ensure_ids_for_products.php';
        $importData['id'] = 'invalid|string_with_pipe';

        $serializer = new EntitySerializer();
        $serializerRegistry = $this->getContainer()->get(SerializerRegistry::class);
        $serializer->setRegistry($serializerRegistry);
        $return = $serializer->deserialize(new Config([][][])$productDefinition$importData);
        


    private function normalizeId(?string $id): string
    {
        $id = mb_strtolower(trim((string) $id));

        if ($id === '' || Uuid::isValid($id)) {
            return $id;
        }

        if (str_contains($id, '|')) {
            throw new InvalidIdentifierException($id);
        }

        return Uuid::fromStringToHex($id);
    }
}
Home | Imprint | This part of the site doesn't use cookies.