4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Serializer\Tests\DependencyInjection;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
20 * Tests for the SerializerPass class.
22 * @author Javier Lopez <f12loalf@gmail.com>
24 class SerializerPassTest extends TestCase
27 * @expectedException \RuntimeException
28 * @expectedExceptionMessage You must tag at least one service as "serializer.normalizer" to use the "serializer" service
30 public function testThrowExceptionWhenNoNormalizers()
32 $container = new ContainerBuilder();
33 $container->register('serializer');
35 $serializerPass = new SerializerPass();
36 $serializerPass->process($container);
40 * @expectedException \RuntimeException
41 * @expectedExceptionMessage You must tag at least one service as "serializer.encoder" to use the "serializer" service
43 public function testThrowExceptionWhenNoEncoders()
45 $container = new ContainerBuilder();
46 $container->register('serializer')
47 ->addArgument(array())
48 ->addArgument(array());
49 $container->register('normalizer')->addTag('serializer.normalizer');
51 $serializerPass = new SerializerPass();
52 $serializerPass->process($container);
55 public function testServicesAreOrderedAccordingToPriority()
57 $container = new ContainerBuilder();
59 $definition = $container->register('serializer')->setArguments(array(null, null));
60 $container->register('n2')->addTag('serializer.normalizer', array('priority' => 100))->addTag('serializer.encoder', array('priority' => 100));
61 $container->register('n1')->addTag('serializer.normalizer', array('priority' => 200))->addTag('serializer.encoder', array('priority' => 200));
62 $container->register('n3')->addTag('serializer.normalizer')->addTag('serializer.encoder');
64 $serializerPass = new SerializerPass();
65 $serializerPass->process($container);
72 $this->assertEquals($expected, $definition->getArgument(0));
73 $this->assertEquals($expected, $definition->getArgument(1));