Skip to content

Commit 58bb78d

Browse files
committed
[HttpClient] Fix canceling MockResponse
1 parent 4cd1b7e commit 58bb78d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Response/MockResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function cancel(): void
112112
}
113113

114114
$onProgress = $this->requestOptions['on_progress'] ?? static function () {};
115-
$dlSize = isset($this->headers['content-encoding']) || 'HEAD' === $this->info['http_method'] || \in_array($this->info['http_code'], [204, 304], true) ? 0 : (int) ($this->headers['content-length'][0] ?? 0);
115+
$dlSize = isset($this->headers['content-encoding']) || 'HEAD' === ($this->info['http_method'] ?? null) || \in_array($this->info['http_code'], [204, 304], true) ? 0 : (int) ($this->headers['content-length'][0] ?? 0);
116116
$onProgress($this->offset, $dlSize, $this->info);
117117
}
118118

Tests/MockHttpClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public function testResetsRequestCount()
507507
$this->assertSame(0, $client->getRequestsCount());
508508
}
509509

510-
public function testCancellingMockResponseExecutesOnProgressWithUpdatedInfo()
510+
public function testCancelingMockResponseExecutesOnProgressWithUpdatedInfo()
511511
{
512512
$client = new MockHttpClient(new MockResponse(['foo', 'bar', 'ccc']));
513513
$canceled = false;

Tests/Response/MockResponseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,12 @@ public function testErrorIsTakenIntoAccountInInitialization()
116116
'error' => 'ccc error',
117117
]))->getStatusCode();
118118
}
119+
120+
public function testCancelingAMockResponseNotIssuedByMockHttpClient()
121+
{
122+
$mockResponse = new MockResponse();
123+
$mockResponse->cancel();
124+
125+
$this->assertTrue($mockResponse->getInfo('canceled'));
126+
}
119127
}

0 commit comments

Comments
 (0)