/** * 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']); }
public function omRetrieve(KCConnector $connector, $order_id) { try { $order = new KCOrder($connector, $order_id); return $order->fetch(); } catch (\Exception $e) { $this->log($e->getMessage()); return false; } }
/** * Make sure a non-JSON response results in an exception. * * @return void */ public function testFetchNotJson() { $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('text/plain')); $order = new Order($this->connector, '12345'); $order['data'] = 'is overwritten'; $this->setExpectedException('RuntimeException', 'Unexpected Content-Type header received: text/plain'); $order->fetch(); }