get(PersonRepository::class); $person = $repo->findOneBy([]); if (!$person instanceof Person) { self::markTestSkipped('No person found in test database. Load fixtures to enable this test.'); } /** @var SerializerInterface $serializer */ $serializer = $container->get(SerializerInterface::class); // Should not throw $data = $serializer->normalize($person, 'json'); Assert::assertIsArray($data); // Spot check some expected keys exist foreach ([ 'type', 'id', 'text', 'textAge', 'firstName', 'lastName', 'birthdate', 'age', 'gender', 'civility', ] as $key) { Assert::assertArrayHasKey($key, $data, sprintf('Expected key %s in normalized payload', $key)); } // Minimal group should also work $minimal = $serializer->normalize($person, 'json', ['groups' => 'minimal']); Assert::assertIsArray($minimal); foreach ([ 'type', 'id', 'text', 'textAge', 'firstName', 'lastName', ] as $key) { Assert::assertArrayHasKey($key, $minimal, sprintf('Expected key %s in minimal normalized payload', $key)); } } }