Skip to content

Commit f904e30

Browse files
committed
[HttpClient] Fix response id property check in MockResponse
1 parent 6309807 commit f904e30

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)