Skip to content

Commit 8396cd4

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: [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 7d573a1 + 50e4fa8 commit 8396cd4

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
@@ -2311,7 +2311,26 @@ when making HTTP requests you might face errors at transport level.
23112311

23122312
That's why it's useful to test how your application behaves in case of a transport
23132313
error. :class:`Symfony\\Component\\HttpClient\\Response\\MockResponse` allows
2314-
you to do so, by yielding the exception from its body::
2314+
you to do so in multiple ways.
2315+
2316+
In order to test errors that occur before headers have been received,
2317+
set the ``error`` option value when creating the ``MockResponse``.
2318+
Transport errors of this kind occur, for example, when a host name
2319+
cannot be resolved or the host was unreachable. The
2320+
``TransportException`` will be thrown as soon as a method like
2321+
``getStatusCode()`` or ``getHeaders()`` is called.
2322+
2323+
In order to test errors that occur while a response is being streamed
2324+
(that is, after the headers have already been received), provide the
2325+
exception to ``MockResponse`` as part of the ``body``
2326+
parameter. You can either use an exception directly, or yield the
2327+
exception from a callback. For exceptions of this kind,
2328+
``getStatusCode()`` may indicate a success (200), but accessing
2329+
``getContent()`` fails.
2330+
2331+
The following example code illustrates all three options.
2332+
2333+
body::
23152334

23162335
// ExternalArticleServiceTest.php
23172336
use PHPUnit\Framework\TestCase;
@@ -2326,10 +2345,16 @@ you to do so, by yielding the exception from its body::
23262345
{
23272346
$requestData = ['title' => 'Testing with Symfony HTTP Client'];
23282347
$httpClient = new MockHttpClient([
2329-
// You can create the exception directly in the body...
2348+
// Mock a transport level error at a time before
2349+
// headers have been received (e. g. host unreachable)
2350+
new MockResponse(info: ['error' => 'host unreachable']),
2351+
2352+
// Mock a response with headers indicating
2353+
// success, but a failure while retrieving the body by
2354+
// creating the exception directly in the body...
23302355
new MockResponse([new \RuntimeException('Error at transport level')]),
23312356

2332-
// ... or you can yield the exception from a callback
2357+
// ... or by yielding it from a callback.
23332358
new MockResponse((static function (): \Generator {
23342359
yield new TransportException('Error at transport level');
23352360
})()),

0 commit comments

Comments
 (0)