/** * testGet method * * @return void */ public function testGet() { $request = new HttpRequest(); $response = $request->get('httpbin.org/get', array('foo' => 'bar')); $this->assertEquals(200, $response->statusCode); $result = $response->json(); $this->assertEquals(array('foo' => 'bar'), $result['args']); //Custom header $result = $request->header('X-Custom-Header', 'foobar'); $this->assertSame($request, $result); $response = $request->get('httpbin.org/get'); $this->assertEquals(200, $response->statusCode); $result = $response->json(); $this->assertArrayHasKey('X-Custom-Header', $result['headers']); $this->assertEquals('foobar', $result['headers']['X-Custom-Header']); $this->assertEquals(array(), $result['args']); }
/** * Sets the common headers for each request to the API. * * @param HttpRequest $request * @return HttpRequest */ protected function prepareRequest($request) { $request->header('X-M2X-KEY', $this->apiKey); $request->header('User-Agent', $this->userAgent); return $request; }