/** * @param User $user * * @return User */ public function createUser(User $user) { $user->setCreatedDate(new \DateTime()); $user->setEditedDate(new \DateTime()); $this->entityManager->persist($user); $this->entityManager->flush(); return $user; }
/** * @depends testUserAdd * * @param $userId */ public function testUserGet($userId) { $response = $this->guzzleClient->get('users/' . $userId); $this->assertEquals(200, $response->getStatusCode()); $user = json_decode($response->getBody(), true); $this->assertEquals($this->testUser->getUsername(), $user['username']); $this->assertEquals($this->testUser->getFirstName(), $user['firstName']); $this->assertEquals($this->testUser->getLastName(), $user['lastName']); $this->assertEquals($this->testUser->getEmail(), $user['email']); return $userId; }
/** * @inheritDoc * @return User */ public function convertFromRequestBody($null, Request $request) { $decoded = json_decode($request->getContent(), true); $user = User::createUser($decoded['username'] ?: null, $decoded['firstName'] ?: null, $decoded['lastName'] ?: null, $decoded['email'] ?: null, $decoded['password'] ?: null); if ($user === null) { throw new \InvalidArgumentException('User could not be created, invalid arguments.', 400); } else { return $user; } }