Skip to content

Commit 638c6cd

Browse files
claudedeviantintegral
authored andcommitted
fix: replace deprecated stream_for() with Utils::streamFor()
- Replace deprecated GuzzleHttp\Psr7\stream_for() function with Utils::streamFor() - Update import statement from function import to class import - Add tests for getBody() and withBody() methods to ensure proper StreamInterface handling Fixes deprecation warning in src/Adapter/Psr7/Response.php:11,50
1 parent 5fe68b7 commit 638c6cd

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/Adapter/Psr7/Response.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
namespace Deviantintegral\Har\Adapter\Psr7;
66

77
use Deviantintegral\Har\Content;
8+
use GuzzleHttp\Psr7\Utils;
89
use Psr\Http\Message\ResponseInterface;
910
use Psr\Http\Message\StreamInterface;
1011

11-
use function GuzzleHttp\Psr7\stream_for;
12-
1312
final class Response extends MessageBase implements ResponseInterface
1413
{
1514
/**
@@ -47,7 +46,7 @@ public function getReasonPhrase(): string
4746

4847
public function getBody(): StreamInterface
4948
{
50-
return stream_for($this->response->getContent()->getText());
49+
return Utils::streamFor($this->response->getContent()->getText());
5150
}
5251

5352
public function withBody(StreamInterface $body): \Psr\Http\Message\MessageInterface

tests/src/Unit/Adapter/Psr7/ResponseTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,28 @@ public function testWithAddedHeaderArrayValue()
128128
$withAdded = $this->response->withAddedHeader('X-Custom', ['value1', 'value2']);
129129
$this->assertEquals(['value1', 'value2'], $withAdded->getHeader('X-Custom'));
130130
}
131+
132+
public function testGetBody()
133+
{
134+
$body = $this->response->getBody();
135+
$this->assertInstanceOf(\Psr\Http\Message\StreamInterface::class, $body);
136+
137+
// Verify the body content matches the response content
138+
$bodyContent = $body->getContents();
139+
$this->assertIsString($bodyContent);
140+
$this->assertNotEmpty($bodyContent);
141+
}
142+
143+
public function testWithBody()
144+
{
145+
$newBodyContent = 'Test body content';
146+
$newBody = \GuzzleHttp\Psr7\Utils::streamFor($newBodyContent);
147+
148+
$withBody = $this->response->withBody($newBody);
149+
$this->assertInstanceOf(Response::class, $withBody);
150+
151+
// Verify the new body content
152+
$resultBody = $withBody->getBody();
153+
$this->assertEquals($newBodyContent, $resultBody->getContents());
154+
}
131155
}

0 commit comments

Comments
 (0)