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); }