Skip to content

Commit b67bfc0

Browse files
committed
Enhancement: Tag clients
1 parent 48714e7 commit b67bfc0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

integrations/symfony-bundle.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,32 @@ services are:
244244
my_client:
245245
service: 'my_custom_client_service'
246246
247+
.. versionadded:: 1.17
248+
249+
All configured clients are tagged with ``'httplug.client'`` (the value of the constant ``Http\HttplugBundle\DependencyInjection\HttplugExtension::HTTPLUG_CLIENT_TAG``),
250+
so they can be easily retrieved. This is useful for functional tests, where one might want to replace every
251+
configured client with a mock client, so they can be retrieved and configured later
252+
253+
.. code-block:: php
254+
255+
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
256+
use Http\Mock\Client;
257+
use Symfony\Component\DependencyInjection\ContainerBuilder;
258+
259+
/** @var ContainerBuilder $container */
260+
$serviceIds = array_keys($container->findTaggedServiceIds(HttplugExtension::HTTPLUG_CLIENT_TAG));
261+
262+
foreach ($serviceIds as $serviceId) {
263+
$decoratingServiceId = \sprintf(
264+
'%s.mock',
265+
$serviceId
266+
);
267+
268+
$container->register($decoratingServiceId, Client::class)
269+
->setDecoratedService($serviceId)
270+
->setPublic(true);
271+
}
272+
247273
Plugins
248274
```````
249275

0 commit comments

Comments
 (0)