Esempio n. 1
0
 function __construct(int $statusCode = 200, array $headers = [], $body = NULL)
 {
     foreach ($headers as $name => $header) {
         $this->headerNames[strtoupper($name)] = $name;
     }
     parent::__construct($statusCode, $headers, $body);
     $this->headerNames += ['CACHE-CONTROL' => 'Cache-Control', 'CONTENT-TYPE' => 'Content-Type'];
 }
Esempio n. 2
0
        it('assigns content type, defaults to text/html', function () {
            expect((new Response(200, []))->getHeaders()['CONTENT-TYPE'])->toBe(['text/html; charset=utf-8']);
        });
        it('assigns content type charset, defaults to utf-8', function () {
            expect((new Response(200, ['Content-Type' => 'text/html']))->getHeaders()['CONTENT-TYPE'])->toBe(['text/html; charset=utf-8']);
        });
        it('throws InvalidArgumentException on invalid body', function () {
            expect(function () {
                new Response(200, [], []);
            })->toThrow(new InvalidArgumentException());
        });
    });
    describe('->prepare', function () {
        it('returns a clone of the response', function () {
            $old = new Response(200);
            $new = $old->prepare(new Request('GET', '/'));
            expect($old)->not->toBe($new);
            expect($new)->toBeAnInstanceOf(Response::class);
        });
        it('removes body if request is HEAD', function () {
            $res = new Response(200, [], 'Hello World');
            $req = new Request('HEAD', '/');
            expect($res->prepare($req)->getBody())->toBeNull();
        });
    });
    describe('->isRedirect', function () {
        it('returns true when status code is 302', function () {
            expect((new Response(302))->isRedirect())->toBe(TRUE);
        });
    });
});