예제 #1
0
 /**
  * Make sure fetched data is accessible.
  *
  * @return void
  */
 public function testFetch()
 {
     $this->connector->expects($this->once())->method('createRequest')->with('/orders/1/captures/2', 'GET', [])->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('200'));
     $this->response->expects($this->once())->method('hasHeader')->with('Content-Type')->will($this->returnValue(true));
     $this->response->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json'));
     $data = ['data' => 'from response json', 'capture_id' => '2'];
     $this->response->expects($this->once())->method('json')->will($this->returnValue($data));
     $capture = new Capture($this->connector, '/orders/1', '2');
     $capture['data'] = 'is overwritten';
     $capture->fetch();
     $this->assertEquals('from response json', $capture['data']);
     $this->assertEquals('2', $capture->getId());
 }
예제 #2
0
    /**
     * Make sure that the request sent and retrieved data is correct.
     *
     * @return void
     */
    public function testFetch()
    {
        $json = <<<JSON
{
    "capture_id": "1002",
    "updated": "from json"
}
JSON;
        $this->mock->addResponse(new Response(200, ['Content-Type' => 'application/json'], Stream::factory($json)));
        $capture = new Capture($this->connector, '/path', '1002');
        $capture['updated'] = 'not from json';
        $capture->fetch();
        $this->assertEquals('from json', $capture['updated']);
        $this->assertEquals('1002', $capture->getId());
        $request = $this->history->getLastRequest();
        $this->assertEquals('GET', $request->getMethod());
        $this->assertEquals('/path/captures/1002', $request->getPath());
        $this->assertAuthorization($request);
    }