public function testPutElementRequest() { $dm = $this->_getDrestManager($this->_em); $representation = new \DrestCommon\Representation\Json(); $user = new \DrestTests\Entities\CMS\User(); $user->setEmailAddress('*****@*****.**'); $user->setUsername('leedavis81'); $this->_em->persist($user); $this->_em->flush(); $this->_em->refresh($user); $putEmail = '*****@*****.**'; $representation->write(\DrestCommon\ResultSet::create(array('email_address' => $putEmail), 'user')); $request = \Symfony\Component\HttpFoundation\Request::create('/user/' . $user->getId(), 'PUT', array(), array(), array(), array('HTTP_CONTENT_TYPE' => $representation->getContentType()), $representation->__toString()); $response = $dm->dispatch($request); $this->assertEquals(200, $response->getStatusCode()); $putUser = $this->_em->find('DrestTests\\Entities\\CMS\\User', $user->getId()); $this->assertEquals($putEmail, $putUser->getEmailAddress()); }
/** * @expectedException \Doctrine\ORM\ORMException */ public function testDeleteElementRequest() { $dm = $this->_getDrestManager($this->_em); $representation = new \DrestCommon\Representation\Json(); $user = new \DrestTests\Entities\CMS\User(); $email = '*****@*****.**'; $username = '******'; $user->setEmailAddress($email); $user->setUsername($username); $this->_em->persist($user); $this->_em->flush(); $this->_em->refresh($user); // Ensure they've been written to storage $entity = $this->_em->getRepository('DrestTests\\Entities\\CMS\\User')->find($user->getId()); $this->assertEquals($entity, $user); $request = \Symfony\Component\HttpFoundation\Request::create('/user/' . $user->getId(), 'DELETE', array(), array(), array(), array('HTTP_ACCEPT' => $representation->getContentType())); $response = $dm->dispatch($request); $this->assertEquals(200, $response->getStatusCode()); $deletedEntity = $this->_em->getRepository('DrestTests\\Entities\\CMS\\User')->find($user->getId()); $this->assertNull($deletedEntity); }
public function testGetElementRequest() { $dm = $this->_getDrestManager($this->_em); $representation = new \DrestCommon\Representation\Json(); $user = new \DrestTests\Entities\CMS\User(); $email = '*****@*****.**'; $username = '******'; $user->setEmailAddress($email); $user->setUsername($username); $this->_em->persist($user); $this->_em->flush(); $this->_em->refresh($user); $this->assertEquals($email, $user->getEmailAddress()); $this->assertEquals($username, $user->getUsername()); $request = \Symfony\Component\HttpFoundation\Request::create('/user/' . $user->getId(), 'GET', array(), array(), array(), array('HTTP_ACCEPT' => $representation->getContentType())); $response = $dm->dispatch($request); $representation = $representation::createFromString($response->getBody()); $userArray = $representation->toArray(false); $this->assertEquals($user->getEmailAddress(), $userArray['email_address']); $this->assertEquals($user->getUsername(), $userArray['username']); }
public function testDeleteCollectionRequest() { $dm = $this->_getDrestManager($this->_em); $representation = new \DrestCommon\Representation\Json(); $users = array(array('email_address' => '*****@*****.**', 'username' => 'frodo.baggins'), array('email_address' => '*****@*****.**', 'username' => 'samwise.gamgee')); foreach ($users as $user) { $userObj = new \DrestTests\Entities\CMS\User(); $userObj->setEmailAddress($user['email_address']); $userObj->setUsername($user['username']); $this->_em->persist($userObj); $this->_em->flush(); $this->_em->refresh($userObj); $entity = $this->_em->getRepository('DrestTests\\Entities\\CMS\\User')->find($userObj->getId()); $this->assertEquals($userObj, $entity); } $request = \Symfony\Component\HttpFoundation\Request::create('/users', 'DELETE', array(), array(), array(), array('HTTP_ACCEPT' => $representation->getContentType())); $response = $dm->dispatch($request); $this->assertEquals(200, $response->getStatusCode()); $deletedEntities = $this->_em->getRepository('DrestTests\\Entities\\CMS\\User')->findAll(); $this->assertCount(0, $deletedEntities); }
public function testGetCollectionRequest() { $dm = $this->_getDrestManager($this->_em); $representation = new \DrestCommon\Representation\Json(); $users = array(array('email_address' => '*****@*****.**', 'username' => 'frodo.baggins'), array('email_address' => '*****@*****.**', 'username' => 'samwise.gamgee')); foreach ($users as $user) { $userObj = new \DrestTests\Entities\CMS\User(); $userObj->setEmailAddress($user['email_address']); $userObj->setUsername($user['username']); $this->_em->persist($userObj); $this->_em->flush(); } $request = \Symfony\Component\HttpFoundation\Request::create('/users', 'GET', array(), array(), array(), array('HTTP_ACCEPT' => $representation->getContentType())); $response = $dm->dispatch($request); $representation = $representation::createFromString($response->getBody()); $usersArray = $representation->toArray(false); for ($x = 0; $x < sizeof($users); $x++) { $this->assertEquals($users[$x]['email_address'], $usersArray[$x]['email_address']); $this->assertEquals($users[$x]['username'], $usersArray[$x]['username']); } }