Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 public function testUnserializeUpdateGeneral()
 {
     $documentManager = $this->documentManager;
     $user = new User();
     $user->setUsername('superdweebie');
     $user->setPassword('secret');
     //uses Serialize Ignore annotation
     $user->defineLocation('here');
     $user->setProfile(new Profile('Tim', 'Roediger'));
     $user->setActive(true);
     $documentManager->persist($user);
     $documentManager->flush();
     $id = $user->getId();
     $documentManager->clear();
     /* @var $updated User */
     $updated = $this->unserializer->fromArray(['id' => $id, 'location' => 'there', 'active' => false, 'profile' => ['firstname' => 'Tom']], self::USER_CLASS, null, Unserializer::UNSERIALIZE_UPDATE);
     $this->assertEquals('there', $updated->location());
     $this->assertEquals(false, $updated->getActive());
     $this->assertEquals(null, $updated->getUsername());
     $this->assertEquals('Tom', $updated->getProfile()->getFirstname());
     $this->assertEquals(null, $updated->getProfile()->getLastname());
 }