Esempio n. 1
0
 public function testPutElementRequest()
 {
     $dm = $this->_getDrestManager($this->_em);
     $representation = new \DrestCommon\Representation\Json();
     $user = new \DrestTests\Entities\Typical\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('HTTP_CONTENT_TYPE' => $representation->getContentType()), $representation->__toString());
     $response = $dm->dispatch($request);
     $this->assertEquals(200, $response->getStatusCode());
     $putUser = $this->_em->find('DrestTests\\Entities\\Typical\\User', $user->getId());
     $this->assertEquals($putEmail, $putUser->getEmailAddress());
 }
Esempio n. 2
0
 public function testGetElementRequest()
 {
     $dm = $this->_getDrestManager($this->_em);
     $representation = new \DrestCommon\Representation\Json();
     $user = new \DrestTests\Entities\Typical\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('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']);
 }
Esempio n. 3
0
 /**
  * @expectedException \Doctrine\ORM\ORMException
  */
 public function testDeleteElementRequest()
 {
     $dm = $this->_getDrestManager($this->_em);
     $representation = new \DrestCommon\Representation\Json();
     $user = new \DrestTests\Entities\Typical\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\\Typical\\User')->find($user->getId());
     $this->assertEquals($entity, $user);
     $request = \Symfony\Component\HttpFoundation\Request::create('/user/' . $user->getId(), 'DELETE', [], [], [], array('HTTP_ACCEPT' => $representation->getContentType()));
     $response = $dm->dispatch($request);
     $this->assertEquals(200, $response->getStatusCode());
     $deletedEntity = $this->_em->getRepository('DrestTests\\Entities\\Typical\\User')->find($user->getId());
     $this->assertNull($deletedEntity);
 }
Esempio n. 4
0
 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\Typical\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('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']);
     }
 }
Esempio n. 5
0
 public function testDeleteCollectionRequestOnInvalidParameter()
 {
     $dm = $this->_getDrestManager($this->_em);
     $users = array(array('email_address' => '*****@*****.**', 'username' => 'same'), array('email_address' => '*****@*****.**', 'username' => 'same'));
     foreach ($users as $user) {
         $userObj = new \DrestTests\Entities\Typical\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\\Typical\\User')->find($userObj->getId());
         $this->assertEquals($userObj, $entity);
     }
     $this->assertCount(sizeof($users), $this->_em->getRepository('DrestTests\\Entities\\Typical\\User')->findAll());
     $response = $dm->dispatch(null, null, 'DrestTests\\Entities\\Typical\\User::delete_users_by_username', ['wrongparam' => 'same']);
     // This SHOULD be a 500, currently getting 404 due to wrong service mapping. see https://github.com/leedavis81/drest/issues/16
     $this->assertEquals(500, $response->getStatusCode());
     // Should still have 2, as the above request would have failed
     $deletedEntities = $this->_em->getRepository('DrestTests\\Entities\\Typical\\User')->findAll();
     $this->assertCount(2, $deletedEntities);
 }