function __construct(array $server = NULL, array $query = NULL, array $xargs = NULL, array $files = NULL, array $cookie = NULL) { $this->server = $server ?: $_SERVER; $this->cookie = $cookie ?: $_COOKIE; parent::__construct($server, $query, $xargs, $files); foreach ($this->headers as $name => $header) { $this->headerNames[$name] = str_replace(' ', '-', ucwords(str_replace('-', ' ', strtolower($name)))); } }
expect($req->getUri())->not->toContainKey('port'); }); it('returns host in lowercase', function () { $req = new ServerRequest(['REQUEST_URI' => '/path?queryString', 'HTTP_HOST' => 'OcHeNtA']); expect($req->getUri())->toContainKey('host'); expect($req->getUri()['host'])->toBe('ochenta'); }); it('throws UnexpectedValueException when invalid host', function () { expect(function () { new ServerRequest(['REQUEST_URI' => 'http://☃.com/path?queryString']); })->toThrow(new UnexpectedValueException()); }); it('returns port from SERVER_PORT environment variable', function () { $req = new ServerRequest(['REQUEST_URI' => '/path?queryString', 'SERVER_PORT' => '443']); expect($req->getUri())->toContainKey('port'); expect($req->getUri()['port'])->toEqual(443); }); it('doesn\'t returns port when SERVER_PORT is 80', function () { $req = new ServerRequest(['REQUEST_URI' => '/path?queryString', 'SERVER_PORT' => 80]); expect($req->getUri())->not->toContainKey('port'); }); it('doesn\'t returns port when SERVER_PORT is 443 in HTTPS', function () { $req = new ServerRequest(['REQUEST_URI' => 'https://example.com/path?queryString', 'SERVER_PORT' => 443, 'HTTPS' => 'on']); expect($req->getUri())->not->toContainKey('port'); }); it('doesn\'t returns port when is 443 in HTTPS', function () { $req = new ServerRequest(['REQUEST_URI' => 'https://example.com:443/path?queryString']); expect($req->getUri())->not->toContainKey('port'); }); }); });