Skip to content

Commit 66391ba

Browse files
Merge branch '5.4' into 6.2
* 5.4: [Serializer] Preserve array keys while denormalize variadic parameters [FrameworkBundle] enable metadata cache when annotation is disabled TranslatorBag::diff now iterates over catalogue domains instead of operation domains [HttpClient] Fix not calling the on progress callback when canceling a MockResponse [TwigBridge] Fix raw content rendering in HTML notification emails
2 parents 7c3172e + 4cd1b7e commit 66391ba

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Response/MockResponse.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public function cancel(): void
104104
} catch (TransportException $e) {
105105
// ignore errors when canceling
106106
}
107+
108+
$onProgress = $this->requestOptions['on_progress'] ?? static function () {};
109+
$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);
110+
$onProgress($this->offset, $dlSize, $this->info);
107111
}
108112

109113
protected function close(): void

Tests/MockHttpClientTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,25 @@ public function testResetsRequestCount()
543543
$client->reset();
544544
$this->assertSame(0, $client->getRequestsCount());
545545
}
546+
547+
public function testCancellingMockResponseExecutesOnProgressWithUpdatedInfo()
548+
{
549+
$client = new MockHttpClient(new MockResponse(['foo', 'bar', 'ccc']));
550+
$canceled = false;
551+
$response = $client->request('GET', 'https://example.com', [
552+
'on_progress' => static function (int $dlNow, int $dlSize, array $info) use (&$canceled): void {
553+
$canceled = $info['canceled'];
554+
},
555+
]);
556+
557+
foreach ($client->stream($response) as $response => $chunk) {
558+
if ('bar' === $chunk->getContent()) {
559+
$response->cancel();
560+
561+
break;
562+
}
563+
}
564+
565+
$this->assertTrue($canceled);
566+
}
546567
}

0 commit comments

Comments
 (0)