createResponse(); $clone = $response->withStatus(200); $this->assertSame(200, (function () { return $this->status; })->call($clone)); } public function test_default_body_is_empty(): void { $response = $this->createResponse(); $this->assertEquals('', $response->getBody()); } // ── withStatus() ───────────────────────────────────────────────────────── public function test_with_status_returns_clone(): void { $response = $this->createResponse(); $newResponse = $response->withStatus(404); $this->assertNotSame($response, $newResponse); } public function test_with_status_sets_code(): void { $response = $this->createResponse(); $newResponse = $response->withStatus(404); $ref = new ReflectionClass($newResponse); $prop = $ref->getProperty('status'); $this->assertEquals(404, $prop->getValue($newResponse)); } public function test_with_status_does_not_mutate_original(): void { $response = $this->createResponse(); $response->withStatus(404); $ref = new ReflectionClass($response); $prop = $ref->getProperty('status'); $this->assertEquals(200, $prop->getValue($response)); } public function test_with_status_various_codes(): void { foreach ([200, 201, 301, 400, 401, 403, 404, 500, 503] as $code) { $newResponse = $this->createResponse()->withStatus($code); $ref = new ReflectionClass($newResponse); $prop = $ref->getProperty('status'); $this->assertEquals($code, $prop->getValue($newResponse)); } } // ── withHeader() ───────────────────────────────────────────────────────── public function test_with_header_returns_clone(): void { $response = $this->createResponse(); $newResponse = $response->withHeader('Content-Type', 'text/html'); $this->assertNotSame($response, $newResponse); } public function test_with_header_sets_value(): void { $response = $this->createResponse(); $newResponse = $response->withHeader('Content-Type', 'application/json'); $ref = new ReflectionClass($newResponse); $prop = $ref->getProperty('headers'); $this->assertEquals(['Content-Type' => 'application/json'], $prop->getValue($newResponse)); } public function test_with_header_does_not_mutate_original(): void { $response = $this->createResponse(); $response->withHeader('X-Foo', 'bar'); $ref = new ReflectionClass($response); $prop = $ref->getProperty('headers'); $this->assertEquals([], $prop->getValue($response)); } public function test_with_header_overwrites_existing(): void { $response = $this->createResponse(); $r1 = $response->withHeader('Content-Type', 'text/html'); $r2 = $r1->withHeader('Content-Type', 'application/json'); $ref = new ReflectionClass($r2); $prop = $ref->getProperty('headers'); $this->assertEquals(['Content-Type' => 'application/json'], $prop->getValue($r2)); } public function test_with_header_multiple_headers(): void { $response = $this->createResponse(); $newResponse = $response ->withHeader('Content-Type', 'text/html') ->withHeader('X-Custom', 'value'); $ref = new ReflectionClass($newResponse); $prop = $ref->getProperty('headers'); $headers = $prop->getValue($newResponse); $this->assertEquals('text/html', $headers['Content-Type']); $this->assertEquals('value', $headers['X-Custom']); } // ── withBody() ─────────────────────────────────────────────────────────── public function test_with_body_returns_clone(): void { $response = $this->createResponse(); $newResponse = $response->withBody('hello'); $this->assertNotSame($response, $newResponse); } public function test_with_body_sets_content(): void { $response = $this->createResponse(); $newResponse = $response->withBody('hello world'); $this->assertEquals('hello world', $newResponse->getBody()); } public function test_with_body_does_not_mutate_original(): void { $response = $this->createResponse(); $response->withBody('changed'); $this->assertEquals('', $response->getBody()); } public function test_body_json_content(): void { $json = json_encode(['status' => 'ok']); $response = $this->createResponse()->withBody($json); $this->assertEquals($json, $response->getBody()); } // ── send() ─────────────────────────────────────────────────────────────── public function test_send_does_not_throw(): void { $response = $this->createResponse()->withBody('test'); // send() calls header() and http_response_code() which throw in CLI // PHPUnit suppresses these in some versions, but we catch them $this->expectNotToPerformAssertions(); $response->send(); } }