mock->addResponse( new Response(201, ['Location' => 'http://somewhere/a-path']) ); $order = new Order($this->connector); $location = $order->create(['data' => 'goes here']) ->getLocation(); $this->assertEquals('http://somewhere/a-path', $location); $request = $this->history->getLastRequest(); $this->assertEquals('POST', $request->getMethod()); $this->assertEquals('/checkout/v3/orders', $request->getPath()); $this->assertEquals('application/json', $request->getHeader('Content-Type')); $this->assertEquals('{"data":"goes here"}', strval($request->getBody())); $this->assertAuthorization($request); } /** * Make sure that the request sent is correct and that the updated data * is accessible. * * @return void */ public function testUpdate() { $json = <<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 that the request sent and retrieved data is correct. * * @return void */ public function testFetch() { $json = <<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); } }