예제 #1
0
 public function testPostElementRequest()
 {
     $dm = $this->_getDrestManager($this->_em);
     $representation = new \DrestCommon\Representation\Json();
     // id's added for comparison but not used for persistence (see DrestTests\Entities\Typical\User::populatePost())
     $user = array('id' => 1, 'username' => 'leedavis81', 'email_address' => '*****@*****.**', 'phone_numbers' => array(array('id' => 1, 'number' => '02087856589'), array('id' => 2, 'number' => '07584565445'), array('id' => 3, 'number' => '02078545896')));
     $representation->write(\DrestCommon\ResultSet::create($user, 'user'));
     $request = \Symfony\Component\HttpFoundation\Request::create('/user', 'POST', [], [], [], array('HTTP_CONTENT_TYPE' => $representation->getContentType()), $representation->__toString());
     $response = $dm->dispatch($request);
     $this->assertEquals(201, $response->getStatusCode());
     $this->assertEquals($dm->getRequest()->getUrl() . '/user/1', $response->getHttpHeader('Location'));
     // Ensure this item exists in persistence
     $query = $this->_em->createQuery('SELECT u, p FROM DrestTests\\Entities\\Typical\\User u JOIN u.phone_numbers p');
     $this->assertEquals($user, $query->getSingleResult(\Doctrine\ORM\Query::HYDRATE_ARRAY));
 }
예제 #2
0
 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());
 }