Пример #1
0
 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);
 }
Пример #2
0
 protected function deserialize($content, $type, Context $context = null)
 {
     return $this->serializer->deserialize($content, Type::from($type), $this->getFormat(), $context);
 }
Пример #3
0
 /**
  * @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()));
 }