예제 #1
0
 /**
  * @param object $object
  * @param bool   $mapResponse
  * @param array  $parameters
  * @param array  $requirements
  *
  * @return object
  */
 public function save($object, $mapResponse = false, array $parameters = [], array $requirements = [])
 {
     if (!$object instanceof $this->class) {
         throw new InvalidArgumentException();
     }
     $request = $this->requestFactory->createSaveRequest($object, $parameters, $requirements);
     $response = $this->client->send($request);
     if (true === $mapResponse) {
         return $this->responseMapper->map($response, get_class($object), 'json');
     }
     return $object;
 }
예제 #2
0
 /**
  * @dataProvider getFormatAndBodyWithoutId
  */
 public function testCreateSaveRequestForEntityWithUrlRequirements($format, $expectedBody, $parameters, $requirements, $expectedQueryString)
 {
     $this->factory->setFormat($format);
     $post = new Post();
     $post->body = 'Hello World!';
     $requirements['blogId'] = 321;
     $this->urlGenerator->expects($this->once())->method('getCreateUrl')->with('blogs/{{blogId}}/posts', $parameters, $requirements)->will($this->returnValue('/blogs/321/posts' . $expectedQueryString));
     $request = $this->factory->createSaveRequest($post, $parameters, $requirements);
     $this->assertEquals('POST', $request->getMethod());
     $this->assertEquals('application/' . $format, $request->getHeaderLine('Content-Type'));
     $this->assertEquals('/blogs/321/posts' . $expectedQueryString, $request->getUri());
     $this->assertEquals($expectedBody, (string) $request->getBody());
 }