/** * Transform a Model User to its representation. * * @param User|null $user * * @return UserRepresentation|null */ public function transform($user) { if (!$user) { return; } $representation = new UserRepresentation(); $representation->setId($user->getId()); $representation->setUsername($user->getUsername()); $representation->setEmail($user->getEmail()); $representation->setFirstname($user->getFirstName()); return $representation; }
/** * {@inheritDoc} */ public function getFirstName() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getFirstName', array()); return parent::getFirstName(); }
/** * @param User $user * * @return WebHomeUser */ public function entityToWebHomeUser(User $user) { $model = new WebHomeUser($user->getUsername(), '', $user->getFirstName(), $user->getLastName(), $user->getLocale(), $user->getAccessTokens()->last()->getToken(), ''); return $model; }
/** * Test is the given response is valid. * * @param Response $response * @param User $user */ private function assertIsValidV2Response(Response $response, User $user) { // Response is OK $this->assertEquals(200, $response->getStatusCode()); $result = $response->getContent(); $content = json_decode($result, true); // All key are presents $keys = array('id', 'username', 'email', 'firstname'); foreach ($keys as $key) { $this->assertArrayHasKey($key, $content); } // There is no extra key foreach ($content as $key => $value) { $this->assertContains($key, $keys); } // all values are valid $this->assertEquals($user->getId(), $content['id']); $this->assertEquals($user->getUsername(), $content['username']); $this->assertEquals($user->getEmail(), $content['email']); $this->assertEquals($user->getFirstName(), $content['firstname']); }