@@ -227,6 +227,43 @@ public function testThrowExceptionInBodyGenerator()
227227 $ this ->assertSame ('bar ccc ' , $ chunks [2 ]->getError ());
228228 }
229229
230+ public function testExceptionDirectlyInBody ()
231+ {
232+ $ mockHttpClient = new MockHttpClient ([
233+ new MockResponse (['foo ' , new \RuntimeException ('foo ccc ' )]),
234+ new MockResponse ((static function (): \Generator {
235+ yield 'bar ' ;
236+ yield new TransportException ('bar ccc ' );
237+ })()),
238+ ]);
239+
240+ try {
241+ $ mockHttpClient ->request ('GET ' , 'https://symfony.com ' , [])->getContent ();
242+ $ this ->fail ();
243+ } catch (TransportException $ e ) {
244+ $ this ->assertEquals (new \RuntimeException ('foo ccc ' ), $ e ->getPrevious ());
245+ $ this ->assertSame ('foo ccc ' , $ e ->getMessage ());
246+ }
247+
248+ $ chunks = [];
249+ try {
250+ foreach ($ mockHttpClient ->stream ($ mockHttpClient ->request ('GET ' , 'https://symfony.com ' , [])) as $ chunk ) {
251+ $ chunks [] = $ chunk ;
252+ }
253+ $ this ->fail ();
254+ } catch (TransportException $ e ) {
255+ $ this ->assertEquals (new TransportException ('bar ccc ' ), $ e ->getPrevious ());
256+ $ this ->assertSame ('bar ccc ' , $ e ->getMessage ());
257+ }
258+
259+ $ this ->assertCount (3 , $ chunks );
260+ $ this ->assertEquals (new FirstChunk (0 , '' ), $ chunks [0 ]);
261+ $ this ->assertEquals (new DataChunk (0 , 'bar ' ), $ chunks [1 ]);
262+ $ this ->assertInstanceOf (ErrorChunk::class, $ chunks [2 ]);
263+ $ this ->assertSame (3 , $ chunks [2 ]->getOffset ());
264+ $ this ->assertSame ('bar ccc ' , $ chunks [2 ]->getError ());
265+ }
266+
230267 protected function getHttpClient (string $ testCase ): HttpClientInterface
231268 {
232269 $ responses = [];
0 commit comments