Exemplo n.º 1
0
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded

19
name1=value1&name2=value2
0

EOD;
            expect($request->toMessage())->toBe($expected);
        });
        it("throws an exception when Content-Length is required but not be determined", function () {
            $closure = function () {
                $stream = Double::instance(['extends' => 'Lead\\Storage\\Stream\\Stream']);
                allow($stream)->toReceive('length')->andReturn(null);
                $request = new Request(['method' => 'POST', 'type' => 'application/x-www-form-urlencoded', 'body' => $stream]);
                $request->toMessage();
            };
            expect($closure)->toThrow(new NetException('A Content-Length header is required but the request stream has a `null` length.'));
        });
    });
    describe("->export()", function () {
        it("exports default values", function () {
            $request = new Request();
            expect($request->export())->toEqual(['method' => 'GET', 'scheme' => 'http', 'version' => '1.1', 'host' => 'localhost', 'port' => 80, 'path' => '/', 'query' => '', 'fragment' => '', 'username' => null, 'password' => null, 'url' => 'http://localhost/', 'stream' => $request->stream()]);
        });
        it("exports a request", function () {
            $request = new Request(['scheme' => 'http', 'host' => 'www.domain.com', 'port' => 80, 'username' => 'username', 'password' => 'password', 'path' => 'index.php']);
            expect($request->export())->toEqual(['method' => 'GET', 'scheme' => 'http', 'version' => '1.1', 'host' => 'www.domain.com', 'port' => 80, 'path' => '/index.php', 'query' => '', 'fragment' => '', 'username' => 'username', 'password' => 'password', 'url' => 'http://www.domain.com/index.php', 'stream' => $request->stream()]);
        });
    });
    describe("->toString()", function () {