Skip to content

Commit 583f015

Browse files
bug #44428 [HttpClient] Fix response id property check in MockResponse (fancyweb)
This PR was merged into the 6.0 branch. Discussion ---------- [HttpClient] Fix response id property check in MockResponse | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Since we typed the `$id` property, the check must be changed to not trigger the "accessed before initialization" error. Commits ------- cb4706410c [HttpClient] Fix response id property check in MockResponse
2 parents 99e42b5 + f904e30 commit 583f015

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Response/MockResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static function fromRequest(string $method, string $url, array $options,
159159
*/
160160
protected static function schedule(self $response, array &$runningResponses): void
161161
{
162-
if (!$response->id) {
162+
if (!isset($response->id)) {
163163
throw new InvalidArgumentException('MockResponse instances must be issued by MockHttpClient before processing.');
164164
}
165165

Tests/Response/MockResponseTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Component\HttpClient\Tests\Response;
44

55
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
67
use Symfony\Component\HttpClient\Exception\JsonException;
78
use Symfony\Component\HttpClient\Exception\TransportException;
89
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -107,4 +108,12 @@ public function testErrorIsTakenIntoAccountInInitialization()
107108
'error' => 'ccc error',
108109
]))->getStatusCode();
109110
}
111+
112+
public function testMustBeIssuedByMockHttpClient()
113+
{
114+
$this->expectException(InvalidArgumentException::class);
115+
$this->expectExceptionMessage('MockResponse instances must be issued by MockHttpClient before processing.');
116+
117+
(new MockResponse())->getContent();
118+
}
110119
}

0 commit comments

Comments
 (0)