$request = new Request(['host' => 'www.domain.com', 'port' => 90]); expect((string) $request->headers['Host'])->toBe('Host: www.domain.com:90'); }); it("sets cookies", function () { $request = new Request(['cookies' => ['foo' => 'bar', 'bar' => 'foo']]); expect($request->headers->cookies->data())->toEqual(['foo' => 'bar', 'bar' => 'foo']); }); }); describe("::parseUrl()", function () { it("parses absolute url", function () { $request = Request::parseUrl('https://*****:*****@www.domain.com:8000/foo?bar=baz#quz'); expect($request->export())->toEqual(['method' => 'GET', 'scheme' => 'https', 'version' => '1.1', 'host' => 'www.domain.com:8000', 'port' => 8000, 'path' => '/foo', 'query' => '?bar=baz', 'fragment' => 'quz', 'username' => 'username', 'password' => 'password', 'url' => 'https://www.domain.com:8000/foo?bar=baz#quz', 'stream' => $request->stream()]); }); it("throw an exception when the passed url is invalid", function () { $closure = function () { Request::parseUrl('/relative/url'); }; expect($closure)->toThrow(new NetException("Invalid url: `'/relative/url'`.")); }); }); describe("->host()", function () { it("sets the host", function () { $request = new Request(); $request->host('www.example.com:8000'); expect($request->host())->toBe('www.example.com:8000'); expect($request->hostname())->toBe('www.example.com'); expect($request->port())->toBe('8000'); expect((string) $request->headers['Host'])->toBe('Host: www.example.com:8000'); }); }); describe("->scheme()", function () {
it("creates a new request with the provided request target asterisk", function () { $request = new Request(); $new = $request->withRequestTarget('*'); expect($new)->not->toBe($request); expect($new->getRequestTarget())->toBe('*'); }); it("creates a new request with the provided request target origin", function () { $request = new Request(); $new = $request->withRequestTarget('/index.php?foo=bar#baz'); expect($new)->not->toBe($request); expect($new->getRequestTarget())->toBe('/index.php?foo=bar#baz'); }); }); describe("->getUri()", function () { it("returns the request URI", function () { $request = Request::parseUrl('https://*****:*****@www.domain.com:8000/foo?bar=baz#quz'); $uri = $request->getUri(); expect($uri)->toBeAnInstanceOf('Psr\\Http\\Message\\UriInterface'); expect((string) $uri)->toBe('https://*****:*****@www.domain.com:8000/foo?bar=baz#quz'); }); }); describe("->withUri()", function () { it("creates a new request with the provided URI", function () { $request = new Request(); $new = $request->withUri(new Uri('https://*****:*****@www.domain.com:8000/foo?bar=baz#quz')); expect($new)->not->toBe($request); $uri = $new->getUri(); expect($uri)->toBeAnInstanceOf('Psr\\Http\\Message\\UriInterface'); expect((string) $uri)->toBe('https://*****:*****@www.domain.com:8000/foo?bar=baz#quz'); expect($new->getHeaderLine('Host'))->toBe('www.domain.com:8000'); });