public function testDefaultHeader() { Unirest\Request::defaultHeader('Hello', 'custom'); $response = Unirest\Request::get('http://httpbin.org/get'); $this->assertEquals(200, $response->code); $headers = $response->body->headers; $properties = get_object_vars($headers); $this->assertTrue(array_key_exists('Hello', $properties)); $this->assertEquals('custom', $headers->Hello); $response = Unirest\Request::get('http://httpbin.org/get'); $this->assertEquals(200, $response->code); $headers = $response->body->headers; $properties = get_object_vars($headers); $this->assertTrue(array_key_exists('Hello', $properties)); $this->assertEquals('custom', $headers->Hello); Unirest\Request::clearDefaultHeaders(); $response = Unirest\Request::get('http://httpbin.org/get'); $this->assertEquals(200, $response->code); $headers = $response->body->headers; $properties = get_object_vars($headers); $this->assertFalse(array_key_exists('Hello', $properties)); }
public function testSetMashapeKey() { Unirest\Request::setMashapeKey('abcd'); $response = Unirest\Request::get('http://mockbin.com/request'); $this->assertEquals(200, $response->code); $this->assertTrue(property_exists($response->body->headers, 'x-mashape-key')); $this->assertEquals('abcd', $response->body->headers->{'x-mashape-key'}); // send another request $response = Unirest\Request::get('http://mockbin.com/request'); $this->assertEquals(200, $response->code); $this->assertTrue(property_exists($response->body->headers, 'x-mashape-key')); $this->assertEquals('abcd', $response->body->headers->{'x-mashape-key'}); Unirest\Request::clearDefaultHeaders(); $response = Unirest\Request::get('http://mockbin.com/request'); $this->assertEquals(200, $response->code); $this->assertFalse(property_exists($response->body->headers, 'x-mashape-key')); }