public function testSerializer() { $user = new User(); $user->setUsername('superdweebie'); $user->setPassword('secret'); //uses Serialize Ignore annotation $user->defineLocation('here'); $user->addGroup(new Group('groupA')); $user->addGroup(new Group('groupB')); $user->setProfile(new Profile('Tim', 'Roediger')); $correct = array('username' => 'superdweebie', 'location' => 'here', 'groups' => array(array('name' => 'groupA'), array('name' => 'groupB')), 'profile' => array('firstname' => 'Tim', 'lastname' => 'Roediger')); $array = $this->serializer->toArray($user); $this->assertEquals($correct, $array); }
public function testUnserializeUpdateEmptyCollection() { $documentManager = $this->documentManager; $user = new User(); $user->addGroup(new Group('groupA')); $user->addGroup(new Group('groupB')); $documentManager->persist($user); $documentManager->flush(); $id = $user->getId(); /* @var $updated User */ $updated = $this->unserializer->fromArray(['id' => $id, 'groups' => []], self::USER_CLASS, null, Unserializer::UNSERIALIZE_UPDATE); $this->assertCount(0, $updated->getGroups()); $documentManager->flush(); $documentManager->clear(); $userFind = $documentManager->find(self::USER_CLASS, $id); $this->assertCount(0, $userFind->getGroups()); }