Exemple #1
0
 function __construct(string $method, $uri, array $headers = [], $body = NULL)
 {
     foreach ($headers as $name => $header) {
         $this->headerNames[strtoupper($name)] = $name;
     }
     parent::__construct($method, $uri, $headers, $body);
 }
Exemple #2
0
     it('assigns uri from parse_url array', function () {
         $uri = ['scheme' => 'http', 'host' => 'example.com', 'path' => '/path', 'query' => '?queryString'];
         expect((new Request('GET', $uri))->getUri())->toBeA('array')->toContainKey('host');
     });
     it('throws InvalidArgumentException on invalid uri', function () {
         expect(function () {
             new Request('GET', 'http://@/');
         })->toThrow(new InvalidArgumentException());
     });
     it('assigns headers with keys in uppercase', function () {
         $req = new Request('GET', '/', ['Host' => ['example.com'], 'Content-Type' => ['text/plain']]);
         expect($req->getHeaders())->toBeA('array')->toContainKey('HOST')->toContainKey('CONTENT-TYPE');
         expect($req->getHeaders()['HOST'])->toBe(['example.com']);
     });
     it('assigns host header from uri', function () {
         $req = new Request('GET', 'http://example.com/path?queryString');
         expect($req->getHeaders())->toBeA('array')->toContainKey('HOST');
         expect($req->getHeaders()['HOST'])->toBe(['example.com']);
     });
     it('assigns body, defaults to null', function () {
         expect((new Request('GET', '/'))->getBody())->toBeNull();
     });
     it('assigns body as resource if given is scalar', function () {
         expect((new Request('GET', '/', [], 'Hello World'))->getBody())->toBeA('resource');
     });
     it('throws InvalidArgumentException on invalid body', function () {
         expect(function () {
             new Request('GET', '/', [], []);
         })->toThrow(new InvalidArgumentException());
     });
 });