Skip to content

Commit

Permalink
Merge pull request #671 from magnetik/autoconfigure-handlers-2.x
Browse files Browse the repository at this point in the history
Add autoconfigure for handlers
  • Loading branch information
goetas committed Jul 11, 2018
2 parents 22eb9a2 + 3c90ba7 commit 9fe4d5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/JMSSerializerExtension.php
Expand Up @@ -4,6 +4,7 @@

use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\Exception\RuntimeException;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -21,6 +22,10 @@ public function loadInternal(array $config, ContainerBuilder $container)
$container
->registerForAutoconfiguration(EventSubscriberInterface::class)
->addTag('jms_serializer.event_subscriber');

$container
->registerForAutoconfiguration(SubscribingHandlerInterface::class)
->addTag('jms_serializer.subscribing_handler');
}

$loader = new XmlFileLoader($container, new FileLocator(array(
Expand Down
17 changes: 17 additions & 0 deletions Tests/DependencyInjection/JMSSerializerExtensionTest.php
Expand Up @@ -3,6 +3,7 @@
namespace JMS\SerializerBundle\Tests\DependencyInjection;

use Doctrine\Common\Annotations\AnnotationReader;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\SerializerBundle\JMSSerializerBundle;
Expand Down Expand Up @@ -531,6 +532,22 @@ public function testAutoconfigureSubscribers()
$this->assertTrue($autoconfigureInstance[EventSubscriberInterface::class]->hasTag('jms_serializer.event_subscriber'));
}

public function testAutoconfigureHandlers()
{
$container = $this->getContainerForConfig(array());

if (!method_exists($container, 'registerForAutoconfiguration')) {
$this->markTestSkipped(
'registerForAutoconfiguration method is not available in the container'
);
}

$autoconfigureInstance = $container->getAutoconfiguredInstanceof();

$this->assertTrue(array_key_exists(SubscribingHandlerInterface::class, $autoconfigureInstance));
$this->assertTrue($autoconfigureInstance[SubscribingHandlerInterface::class]->hasTag('jms_serializer.subscribing_handler'));
}

private function getContainerForConfig(array $configs, callable $configurator = null)
{
$bundle = new JMSSerializerBundle();
Expand Down

0 comments on commit 9fe4d5d

Please sign in to comment.