Set-Cookie: bin=baz; Path=/ Set-Cookie: foo=bin; Path=/foo {"hello":"world"} EOD; expect($response->toMessage())->toBe($expected); }); }); describe("->toString()", function () { it("casts the response as a string", function () { $response = new Response(['format' => 'json', 'data' => ['hello' => 'world']]); $cookies = $response->headers->cookies; $cookies['foo'] = 'bar'; $cookies['bin'] = 'baz'; $cookies['foo'] = ['value' => 'bin', 'path' => '/foo']; expect($response->toString())->toBe('{"hello":"world"}'); }); }); describe("->__toString()", function () { it("echoes the response and populates headers", function () { $headers = []; Monkey::patch('header', function () use(&$headers) { $headers[] = func_get_args(); }); $closure = function () { $response = new Response(['format' => 'json', 'data' => ['hello' => 'world']]); (string) $response; }; expect($closure)->toEcho('{"hello":"world"}'); expect($headers)->toEqual([["HTTP/1.1 200 OK"], ["Content-Type: application/json"], ["Content-Length: 17"]]); });