Skip to content

Commit 50e4fa8

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [HttpClient] Explain how to mock `TransportExceptions` that occur before headers are received Update DOCtor-RST config Fix the version in which AsDoctrineListener was added
2 parents b4d7fb8 + ef2613f commit 50e4fa8

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

.doctor-rst.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ whitelist:
9999
- 'The bin/console Command'
100100
- '.. _`LDAP injection`: http://projects.webappsec.org/w/page/13246947/LDAP%20Injection'
101101
- '.. versionadded:: 2.7.2' # Doctrine
102+
- '.. versionadded:: 2.8.0' # Doctrine
102103
- '.. versionadded:: 1.9.0' # Encore
103104
- '.. versionadded:: 1.18' # Flex in setup/upgrade_minor.rst
104105
- '.. versionadded:: 1.0.0' # Encore

doctrine/events.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ listener in the Symfony application by creating a new service for it and
391391
;
392392
};
393393
394-
.. versionadded:: 2.7.2
394+
.. versionadded:: 2.8.0
395395

396-
The `AsDoctrineListener`_ attribute was introduced in DoctrineBundle 2.7.2.
396+
The `AsDoctrineListener`_ attribute was introduced in DoctrineBundle 2.8.0.
397397

398398
.. tip::
399399

@@ -404,4 +404,4 @@ listener in the Symfony application by creating a new service for it and
404404
.. _`lifecycle events`: https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/events.html#lifecycle-events
405405
.. _`official docs about Doctrine events`: https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/events.html
406406
.. _`DoctrineMongoDBBundle documentation`: https://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
407-
.. _`AsDoctrineListener`: https://github.com/doctrine/DoctrineBundle/blob/2.10.x/Attribute/AsDoctrineListener.php
407+
.. _`AsDoctrineListener`: https://github.com/doctrine/DoctrineBundle/blob/2.12.x/src/Attribute/AsDoctrineListener.php

http_client.rst

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,26 @@ when making HTTP requests you might face errors at transport level.
22422242

22432243
That's why it's useful to test how your application behaves in case of a transport
22442244
error. :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse` allows
2245-
you to do so, by yielding the exception from its body::
2245+
you to do so in multiple ways.
2246+
2247+
In order to test errors that occur before headers have been received,
2248+
set the ``error`` option value when creating the ``MockResponse``.
2249+
Transport errors of this kind occur, for example, when a host name
2250+
cannot be resolved or the host was unreachable. The
2251+
``TransportException`` will be thrown as soon as a method like
2252+
``getStatusCode()`` or ``getHeaders()`` is called.
2253+
2254+
In order to test errors that occur while a response is being streamed
2255+
(that is, after the headers have already been received), provide the
2256+
exception to ``MockResponse`` as part of the ``body``
2257+
parameter. You can either use an exception directly, or yield the
2258+
exception from a callback. For exceptions of this kind,
2259+
``getStatusCode()`` may indicate a success (200), but accessing
2260+
``getContent()`` fails.
2261+
2262+
The following example code illustrates all three options.
2263+
2264+
body::
22462265

22472266
// ExternalArticleServiceTest.php
22482267
use PHPUnit\Framework\TestCase;
@@ -2257,10 +2276,16 @@ you to do so, by yielding the exception from its body::
22572276
{
22582277
$requestData = ['title' => 'Testing with Symfony HTTP Client'];
22592278
$httpClient = new MockHttpClient([
2260-
// You can create the exception directly in the body...
2279+
// Mock a transport level error at a time before
2280+
// headers have been received (e. g. host unreachable)
2281+
new MockResponse(info: ['error' => 'host unreachable']),
2282+
2283+
// Mock a response with headers indicating
2284+
// success, but a failure while retrieving the body by
2285+
// creating the exception directly in the body...
22612286
new MockResponse([new \RuntimeException('Error at transport level')]),
22622287

2263-
// ... or you can yield the exception from a callback
2288+
// ... or by yielding it from a callback.
22642289
new MockResponse((static function (): \Generator {
22652290
yield new TransportException('Error at transport level');
22662291
})()),

0 commit comments

Comments
 (0)