public function orderUpdate(KCConnector $connector, $order_id, $order_data) { try { $checkout = new KCOrder($connector, $order_id); $checkout->update($order_data); return $checkout->fetch(); } catch (\Exception $e) { $this->log($e->getMessage(), 1); return false; } }
/** * Make sure that the request sent is correct and that the updated data * is accessible. * * @return void */ public function testUpdate() { $json = <<<JSON { "order_id": "0001", "updated": "from json" } JSON; $this->mock->addResponse(new Response(200, ['Content-Type' => 'application/json'], Stream::factory($json))); $order = new Order($this->connector, '0001'); $order['updated'] = 'not from json'; $order->update(['data' => 'sent in']); $this->assertEquals('from json', $order['updated']); $this->assertEquals('0001', $order->getId()); $request = $this->history->getLastRequest(); $this->assertEquals('POST', $request->getMethod()); $this->assertEquals('/checkout/v3/orders/0001', $request->getPath()); $this->assertEquals('application/json', $request->getHeader('Content-Type')); $this->assertEquals('{"data":"sent in"}', strval($request->getBody())); $this->assertAuthorization($request); }
/** * Make sure a non-JSON response results in an exception. * * @return void */ public function testUpdateNotJson() { $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('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); $this->setExpectedException('RuntimeException', 'Unexpected Content-Type header received: text/plain'); $order->update(['data' => 'goes here']); }