public function testDiscriminatorIsInferredFromDoctrine() { /** @var EntityManager $em */ $em = $this->registry->getManager(); $student1 = new Student(); $student2 = new Student(); $teacher = new Teacher(); $class = new Clazz($teacher, [$student1, $student2]); $em->persist($student1); $em->persist($student2); $em->persist($teacher); $em->persist($class); $em->flush(); $em->clear(); $reloadedClass = $em->find(get_class($class), $class->getId()); $this->assertNotSame($class, $reloadedClass); $json = $this->serializer->serialize($reloadedClass, 'json'); $this->assertEquals('{"id":1,"teacher":{"id":1,"type":"teacher"},"students":[{"id":2,"type":"student"},{"id":3,"type":"student"}]}', $json); }
protected function serialize($data, Context $context = null) { return $this->serializer->serialize($data, $this->getFormat(), $context); }
/** * @dataProvider getDateTime * @group datetime */ public function testDateTimeNoCData($key, $value, $type) { $handlerRegistry = new HandlerRegistry(); $handlerRegistry->registerSubscribingHandler(new DateHandler(\DateTime::ISO8601, 'UTC', false)); $objectConstructor = new UnserializeObjectConstructor(); $serializer = new Serializer($this->factory, $handlerRegistry, $objectConstructor, $this->serializationVisitors, $this->deserializationVisitors); $this->assertEquals($this->getContent($key . '_no_cdata'), $serializer->serialize($value, $this->getFormat())); }