public function testSerializeEmbedOneDiscriminatorMap() { $apple = new EmbeddedApple(); $apple->setColor('red'); $fruitBowl = new FruitBowl(); $fruitBowl->setEmbeddedSingleFruit($apple); $correct = ['embeddedSingleFruit' => ['_doctrine_class_name' => 'apple', 'color' => 'red']]; $array = $this->serializer->toArray($fruitBowl); $this->assertEquals($correct, $array); }
public function testSerializeReferenceDiscriminator() { $apple = new Apple(); $apple->setVariety('granny smith'); $orange = new Orange(); $orange->setVariety('naval'); $fruitBowl = new FruitBowl(); $fruitBowl->setReferencedFruit(new ArrayCollection([$apple, $orange])); $this->documentManager->persist($fruitBowl); $this->documentManager->flush(); $correct = array('id' => $fruitBowl->getId(), 'referencedFruit' => [['id' => $fruitBowl->getReferencedFruit()[0]->getId(), 'type' => 'apple', 'variety' => 'granny smith'], ['id' => $fruitBowl->getReferencedFruit()[1]->getId(), 'type' => 'orange', 'variety' => 'naval']]); $array = $this->serializer->toArray($fruitBowl); $this->assertEquals($correct, $array); }