/** * @test */ public function it_should_hydrate_embedded_fields() { $user = new HydrationUser(); $user->setId(1); $user->setName('username'); $data = array('id' => 1, 'name' => 'name'); $strategy = $this->getStrategy($this->dm, $user, 'embedOne'); $result = $strategy->hydrate($data); $this->assertEquals('name', $result->getName()); }
/** * @test */ public function it_should_hydrate_referenced_fields() { $user = new HydrationUser(); $user->setId(1); $user->setName('username'); $id = $this->createReference('name'); $data = $id; $strategy = $this->getStrategy($this->dm, $user, 'referenceOne'); $result = $strategy->hydrate($data); $this->assertEquals('name', $result->getName()); }
/** * @test */ public function it_should_hydrate_embedded_collections() { $user = new HydrationUser(); $user->setId(1); $user->setName('username'); $data = array(array('id' => 1, 'name' => 'name')); $strategy = $this->getStrategy($this->dm, $user, 'embedMany'); $strategy->hydrate($data); $embedMany = $user->getEmbedMany(); $this->assertEquals('name', $embedMany[0]->getName()); }
/** * @test */ public function it_should_hydrate_referenced_collections() { $user = new HydrationUser(); $user->setId(1); $user->setName('username'); $id = $this->createReference('name'); $data = array($id); $strategy = $this->getStrategy($this->dm, $user, 'referenceMany'); $strategy->hydrate($data); $referenceMany = $user->getReferenceMany(); $this->assertEquals('name', $referenceMany[0]->getName()); }
/** * @test */ public function it_should_extract_a_document() { $creationDate = new \DateTime(); $birthday = new \DateTime('1 january 2014'); $user = new HydrationUser(); $user->setId(1); $user->setName('user'); $user->setCreatedAt($creationDate->getTimestamp()); $user->setBirthday($birthday); $embedOne = new HydrationEmbedOne(); $embedOne->setId(1); $embedOne->setName('name'); $user->setEmbedOne($embedOne); $embedMany = new HydrationEmbedMany(); $embedMany->setId(1); $embedMany->setName('name'); $user->addEmbedMany(array($embedMany)); $referenceOne = new HydrationReferenceOne(); $referenceOne->setId(1); $referenceOne->setName('name'); $user->setReferenceOne($referenceOne); $referenceMany = new HydrationEmbedMany(); $referenceMany->setId(1); $referenceMany->setName('name'); $user->addReferenceMany(array($referenceMany)); $hydrator = new DoctrineObject($this->dm); $result = $hydrator->extract($user); $this->assertEquals(1, $result['id']); $this->assertEquals('user', $result['name']); $this->assertEquals($creationDate->getTimestamp(), $result['createdAt']); $this->assertEquals($birthday->getTimestamp(), $result['birthday']); $this->assertEquals(1, $result['embedOne']['id']); $this->assertEquals('name', $result['embedOne']['name']); $this->assertEquals(1, $result['embedMany'][0]['id']); $this->assertEquals('name', $result['embedMany'][0]['name']); $this->assertEquals(1, $result['referenceOne']); $this->assertEquals(1, $result['referenceMany'][0]); }