expect(fread($req->getBody(), 11))->toBe('Hello World'); }); }); describe('->getParsedBody', function () { it('returns parsed body when is application/x-www-form-urlencoded', function () { Monkey::patch('fopen', function ($filename, $mode) { if ($filename === 'php://input') { $input = fopen('php://temp', 'r+'); fwrite($input, 'hello=world&foo=bar'); fseek($input, 0); return $input; } return fopen($filename, $mode); }); $req = new ServerRequest(['REQUEST_METHOD' => 'POST', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => 17]); expect($req->getParsedBody())->toBe(['hello' => 'world', 'foo' => 'bar']); }); }); describe('->isSecure', function () { it('returns true when the HTTPS header is on', function () { expect((new ServerRequest(['HTTPS' => 'on']))->isSecure())->toBe(TRUE); }); }); describe('->normalizeServer', function () { it('returns HTTPS when SCRIPT_URI starts with https://', function () { $req = new ServerRequest(['HTTPS' => 'off', 'SCRIPT_URI' => 'https://ochenta/']); expect($req->getUri())->toContainKey('scheme'); expect($req->getUri()['scheme'])->toBe('https'); }); it('returns HTTPS in lowercase, defaults to off', function () { expect((new ServerRequest([]))->getUri()['scheme'])->toBe('http');