Example #1
0
    /**
     * Make sure that the request sent and retrieved data is correct when fetching
     * the order.
     *
     * @return void
     */
    public function testFetch()
    {
        $json = <<<JSON
{
    "order_id": "0002",
    "updated": "from json",
    "captures": [
        {
            "capture_id": "1002",
            "test": "data"
        }
    ]
}
JSON;
        $this->mock->addResponse(new Response(200, ['Content-Type' => 'application/json'], Stream::factory($json)));
        $order = new Order($this->connector, '0002');
        $order['updated'] = 'not from json';
        $order->fetch();
        $this->assertEquals('from json', $order['updated']);
        $this->assertEquals('0002', $order->getId());
        $request = $this->history->getLastRequest();
        $this->assertEquals('GET', $request->getMethod());
        $this->assertEquals('/ordermanagement/v1/orders/0002', $request->getPath());
        $this->assertAuthorization($request);
        $capture = $order['captures'][0];
        $this->assertInstanceOf('Klarna\\Rest\\OrderManagement\\Capture', $capture);
        $this->assertEquals($capture->getId(), $capture['capture_id']);
        $this->assertEquals('1002', $capture->getId());
        $this->assertEquals('data', $capture['test']);
    }
Example #2
0
 /**
  * Make sure fetched data is accessible.
  *
  * @return void
  */
 public function testFetch()
 {
     $this->connector->expects($this->once())->method('createRequest')->with('/ordermanagement/v1/orders/12345', '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', 'order_id' => '12345', 'captures' => [['capture_id' => '1002', 'data' => 'also from json'], ['capture_id' => '1003', 'data' => 'something else']]];
     $this->response->expects($this->once())->method('json')->will($this->returnValue($data));
     $order = new Order($this->connector, '12345');
     $order['data'] = 'is overwritten';
     $order['captures'][] = new \ArrayObject();
     $order->fetch();
     $this->assertEquals('from response json', $order['data']);
     $this->assertEquals('12345', $order->getId());
     $this->assertCount(2, $order['captures']);
     $this->assertContainsOnlyInstancesOf('Klarna\\Rest\\OrderManagement\\Capture', $order['captures']);
     $this->assertEquals('1002', $order['captures'][0]->getId());
     $this->assertEquals('also from json', $order['captures'][0]['data']);
     $this->assertEquals('1003', $order['captures'][1]->getId());
     $this->assertEquals('something else', $order['captures'][1]['data']);
 }