コード例 #1
0
 /**
  * Make sure that the request sent is correct and that the location is updated
  * when creating the capture.
  *
  * @return void
  */
 public function testCreate()
 {
     $this->mock->addResponse(new Response(201, ['Location' => 'http://somewhere/a-path']));
     $capture = new Capture($this->connector, '/path/to/order');
     $location = $capture->create(['data' => 'goes here'])->getLocation();
     $this->assertEquals('http://somewhere/a-path', $location);
     $request = $this->history->getLastRequest();
     $this->assertEquals('POST', $request->getMethod());
     $this->assertEquals('/path/to/order/captures', $request->getPath());
     $this->assertEquals('application/json', $request->getHeader('Content-Type'));
     $this->assertEquals('{"data":"goes here"}', strval($request->getBody()));
     $this->assertAuthorization($request);
 }
コード例 #2
0
ファイル: Order.php プロジェクト: sam-akopyan/hamradio
 /**
  * Capture all or part of an order.
  *
  * @param array $data Capture data
  *
  * @see Capture::create() For more information on how to create a capture
  *
  * @throws ConnectorException When the API replies with an error response
  * @throws RequestException   When an error is encountered
  * @throws \RuntimeException  If the location header is missing
  * @throws \RuntimeException  If the API replies with an unexpected response
  * @throws \LogicException    When Guzzle cannot populate the response
  *
  * @return Capture
  */
 public function createCapture(array $data)
 {
     $capture = new Capture($this->connector, $this->getLocation());
     $capture->create($data);
     $this['captures'][] = $capture;
     return $capture;
 }
コード例 #3
0
 /**
  * Make sure a missing location header in the response results in an exception.
  *
  * @return void
  */
 public function testCreateNoLocation()
 {
     $this->connector->expects($this->once())->method('createRequest')->will($this->returnValue($this->request));
     $this->connector->expects($this->once())->method('send')->with($this->request)->will($this->returnValue($this->response));
     $this->response->expects($this->once())->method('getStatusCode')->will($this->returnValue('201'));
     $this->response->expects($this->once())->method('hasHeader')->with('Location')->will($this->returnValue(false));
     $capture = new Capture($this->connector, '/orders/1');
     $this->setExpectedException('RuntimeException', 'Response is missing a Location header');
     $capture->create(['data' => 'goes here']);
 }