Skip to content

Commit

Permalink
Merge pull request #268 from localheinz/feature/tag
Browse files Browse the repository at this point in the history
Enhancement: Tag clients
  • Loading branch information
dbu committed Jul 5, 2019
2 parents 48714e7 + b67bfc0 commit b36b869
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions integrations/symfony-bundle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,32 @@ services are:
my_client:
service: 'my_custom_client_service'
.. versionadded:: 1.17

All configured clients are tagged with ``'httplug.client'`` (the value of the constant ``Http\HttplugBundle\DependencyInjection\HttplugExtension::HTTPLUG_CLIENT_TAG``),
so they can be easily retrieved. This is useful for functional tests, where one might want to replace every
configured client with a mock client, so they can be retrieved and configured later

.. code-block:: php
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
use Http\Mock\Client;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/** @var ContainerBuilder $container */
$serviceIds = array_keys($container->findTaggedServiceIds(HttplugExtension::HTTPLUG_CLIENT_TAG));
foreach ($serviceIds as $serviceId) {
$decoratingServiceId = \sprintf(
'%s.mock',
$serviceId
);
$container->register($decoratingServiceId, Client::class)
->setDecoratedService($serviceId)
->setPublic(true);
}
Plugins
```````

Expand Down

0 comments on commit b36b869

Please sign in to comment.