Skip to content

Commit edee61f

Browse files
Merge branch '6.2' into 6.3
* 6.2: [Serializer] Fix serializedpath for non scalar types [Serializer] Preserve array keys while denormalize variadic parameters [FrameworkBundle] enable metadata cache when annotation is disabled [DependencyInjection] Fix setting the class of auto-discovery services [FrameworkBundle] Fix auto-discovering validator constraints 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 15b1370 + 66391ba commit edee61f

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
@@ -102,6 +102,10 @@ public function cancel(): void
102102
} catch (TransportException $e) {
103103
// ignore errors when canceling
104104
}
105+
106+
$onProgress = $this->requestOptions['on_progress'] ?? static function () {};
107+
$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);
108+
$onProgress($this->offset, $dlSize, $this->info);
105109
}
106110

107111
public function __destruct()

Tests/MockHttpClientTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,25 @@ public function testResetsRequestCount()
533533
$client->reset();
534534
$this->assertSame(0, $client->getRequestsCount());
535535
}
536+
537+
public function testCancellingMockResponseExecutesOnProgressWithUpdatedInfo()
538+
{
539+
$client = new MockHttpClient(new MockResponse(['foo', 'bar', 'ccc']));
540+
$canceled = false;
541+
$response = $client->request('GET', 'https://example.com', [
542+
'on_progress' => static function (int $dlNow, int $dlSize, array $info) use (&$canceled): void {
543+
$canceled = $info['canceled'];
544+
},
545+
]);
546+
547+
foreach ($client->stream($response) as $response => $chunk) {
548+
if ('bar' === $chunk->getContent()) {
549+
$response->cancel();
550+
551+
break;
552+
}
553+
}
554+
555+
$this->assertTrue($canceled);
556+
}
536557
}

0 commit comments

Comments
 (0)