/** * Test the creation of an Person object in database. */ public function testCreatePerson() { // GIVEN $birthDate = new \DateTime('2000-01-01'); $person = new Person(); $person->setGivenName('Jean'); $person->setFamilyName('Dupond'); $person->setGender('Male'); $person->setJobTitle('president'); $person->setNationality('FR'); $person->setEmail('*****@*****.**'); $person->setDescription('These few words describe what Jean Dupond wants to do and what he have done.'); $person->setTelephone('+1 650-253-0000'); $person->setBirthDate($birthDate); // WHEN $this->getPersonRepository()->save($person); // THEN $testPerson = $this->getPersonRepository()->find($person->getId()); $this->assertEquals('Jean', $testPerson->getGivenName()); $this->assertEquals('Dupond', $testPerson->getFamilyName()); $this->assertEquals('Male', $testPerson->getGender()); $this->assertEquals('president', $testPerson->getJobTitle()); $this->assertEquals('FR', $testPerson->getNationality()); $this->assertEquals($birthDate->format('Y-m-d'), $testPerson->getBirthDate()->format('Y-m-d')); $this->assertEquals('*****@*****.**', $testPerson->getEmail()); $this->assertEquals('These few words describe what Jean Dupond wants to do and what he have done.', $testPerson->getDescription()); $this->assertEquals('+1 650-253-0000', $testPerson->getTelephone()); }
/** * {@inheritdoc} */ public function hydrate(array $data) { // TODO: make a factory $person = new Person(); $person->setId(isset($data['id']) ? $data['id'] : null); $person->setBirthDate(isset($data['birthDate']) ? $data['birthDate'] : null); $person->setDescription(isset($data['description']) ? $data['description'] : null); $person->setEmail(isset($data['email']) ? $data['email'] : null); $person->setFamilyName(isset($data['familyName']) ? $data['familyName'] : null); $person->setGender(isset($data['gender']) ? $data['gender'] : null); $person->setGivenName(isset($data['givenName']) ? $data['givenName'] : null); $person->setJobTitle(isset($data['jobTitle']) ? $data['jobTitle'] : null); $person->setNationality(isset($data['nationality']) ? $data['nationality'] : null); $person->setTelephone(isset($data['telephone']) ? $data['telephone'] : null); if (isset($data['studies'])) { foreach ($data['studies'] as $studyData) { $person->addStudy($this->studyHydrator->hydrate($studyData)); } } if (isset($data['experiences'])) { foreach ($data['experiences'] as $studyData) { $person->addExperience($this->experienceHydrator->hydrate($studyData)); } } return $person; }