/** * @dataProvider providerRequestParameters */ public function testCreateRequestInstance($method, $path) { $request = new Request($method, $path, Request::HTTP, '1.1', ['Host' => 'http://wikipedia.com', 'User-Agent' => 'Mozilla/Firefox']); $this->assertSame($method, $request->getMethod()); $this->assertSame($path, $request->getPath()); $this->assertSame(Request::HTTP, $request->getScheme()); $this->assertSame('1.1', $request->getSchemeVersion()); $this->assertCount(2, $request->getHeaders()); $this->assertSame(['host' => 'http://wikipedia.com', 'user-agent' => 'Mozilla/Firefox'], $request->getHeaders()); $this->assertSame('http://wikipedia.com', $request->getHeader('Host')); $this->assertSame('Mozilla/Firefox', $request->getHeader('User-Agent')); $this->assertEmpty($request->getBody()); }
/** * @dataProvider provideValidHttpMethod * @param $method * @param $path * @param $http */ public function testCreateRequestInstance($method, $path, $http) { $request = new Request($method, $path, $http, "1.1", ["Host" => "http://www.google.com", "Content-Type" => "text/html", "Accept" => "application/json"]); $this->assertSame($method, $request->getMethod(), "Assert of request method"); $this->assertSame($path, $request->getPath(), "Assert of path"); $this->assertSame($http, $request->getScheme(), "Assert of scheme"); $this->assertSame("1.1", $request->getSchemeVersion(), "Assert of scheme version"); $this->assertCount(3, $request->getHeaders()); $this->assertSame(["host" => "http://www.google.com", "content-type" => "text/html", "accept" => "application/json"], $request->getHeaders()); $this->assertSame("http://www.google.com", $request->getHeader("Host")); $this->assertSame("application/json", $request->getHeader("Accept")); $this->assertSame("text/html", $request->getHeader("Content-Type")); $this->assertEmpty($request->getBody(), "Assert of body"); }
/** * @dataProvider provideRequestParameters */ public function testCreateRequestInstance($method, $path) { $body = '{ "foo": "bar" }'; $headers = ['Host' => 'http://wikipedia.com', 'User-Agent' => 'Mozilla/Firefox', 'Content-Type' => 'application/json']; $request = new Request($method, $path, Request::HTTP, '1.1', $headers, $body); $this->assertSame($method, $request->getMethod()); $this->assertSame($path, $request->getPath()); $this->assertSame(Request::HTTP, $request->getScheme()); $this->assertSame('1.1', $request->getSchemeVersion()); $this->assertSame($body, $request->getBody()); $this->assertCount(3, $request->getHeaders()); $this->assertSame(['host' => 'http://wikipedia.com', 'user-agent' => 'Mozilla/Firefox', 'content-type' => 'application/json'], $request->getHeaders()); $this->assertSame('http://wikipedia.com', $request->getHeader('Host')); $this->assertSame('Mozilla/Firefox', $request->getHeader('User-Agent')); $this->assertSame('application/json', $request->getHeader('Content-Type')); }
public function testAddingHeader() { $headers = ['User-Agent' => 'Mozilla']; $request = new Request(Request::GET, '/', Request::HTTP, Request::VERSION_1_0, $headers); $this->assertSame($request->getHeader('User-Agent'), 'Mozilla'); }