Skip to content

Commit af43e5b

Browse files
committed
ResponseError implements Stringable
1 parent 3481742 commit af43e5b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/ResponseError.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
namespace Framework\HTTP\Client;
1111

1212
use JetBrains\PhpStorm\ArrayShape;
13+
use Stringable;
1314

1415
/**
1516
* Class ResponseError.
1617
*
1718
* @package http-client
1819
*/
19-
class ResponseError
20+
class ResponseError implements Stringable
2021
{
2122
protected Request $request;
2223
protected string $error;
@@ -44,6 +45,11 @@ public function __construct(
4445
$this->info = $info;
4546
}
4647

48+
public function __toString() : string
49+
{
50+
return 'Error ' . $this->getErrorNumber() . ': ' . $this->getError();
51+
}
52+
4753
public function getRequest() : Request
4854
{
4955
return $this->request;

tests/ClientTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,18 @@ public function testResponseError() : void
189189
self::assertSame(6, $responses[2]->getErrorNumber());
190190
self::assertSame([], $responses[2]->getInfo());
191191
}
192+
193+
public function testResponseErrorToString() : void
194+
{
195+
$requests = [
196+
new Request('https://aplus-framework.tld'),
197+
];
198+
foreach ($this->client->runMulti($requests) as $response) {
199+
self::assertInstanceOf(ResponseError::class, $response);
200+
self::assertSame(
201+
'Error 6: Could not resolve host: aplus-framework.tld',
202+
(string) $response
203+
);
204+
}
205+
}
192206
}

0 commit comments

Comments
 (0)