expectException(\LengthException::class); BoundedResponseBody::read(new Response(200, [], '123456'), 5); } public function testRejectsOversizedDeclaredContentLengthBeforeReading(): void { $this->expectException(\LengthException::class); BoundedResponseBody::read( new Response(200, ['Content-Length' => '100'], 'small'), 10, ); } public function testReadsWhilePreservingStreamPosition(): void { $response = new Response(200, [], 'abcdef'); $response->getBody()->seek(3); static::assertSame('abcdef', BoundedResponseBody::readPreservingPosition($response, 6)); static::assertSame(3, $response->getBody()->tell()); } public function testPreservingReadReturnsNullForOversizedBodyAndRestoresPosition(): void { $response = new Response(200, [], 'abcdef'); $response->getBody()->seek(2); static::assertNull(BoundedResponseBody::readPreservingPosition($response, 5)); static::assertSame(2, $response->getBody()->tell()); } }