/** * Make sure that the request sent and retrieved data is correct. * * @return void */ public function testFetch() { $json = <<<JSON { "order_id": "0002", "updated": "from json" } 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('/checkout/v3/orders/0002', $request->getPath()); $this->assertAuthorization($request); }
/** * Make sure fetched data is accessible. * * @return void */ public function testFetch() { $this->connector->expects($this->once())->method('createRequest')->with('/checkout/v3/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']; $this->response->expects($this->once())->method('json')->will($this->returnValue($data)); $order = new Order($this->connector, '12345'); $order['data'] = 'is overwritten'; $order->fetch(); $this->assertEquals('from response json', $order['data']); $this->assertEquals('12345', $order->getId()); }