fa12454fd094e49af1ab8be3cf94afb01f60868a
[yaffs-website] / vendor / symfony / serializer / Tests / DependencyInjection / SerializerPassTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Serializer\Tests\DependencyInjection;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
18
19 /**
20  * Tests for the SerializerPass class.
21  *
22  * @author Javier Lopez <f12loalf@gmail.com>
23  */
24 class SerializerPassTest extends TestCase
25 {
26     /**
27      * @expectedException \RuntimeException
28      * @expectedExceptionMessage You must tag at least one service as "serializer.normalizer" to use the "serializer" service
29      */
30     public function testThrowExceptionWhenNoNormalizers()
31     {
32         $container = new ContainerBuilder();
33         $container->register('serializer');
34
35         $serializerPass = new SerializerPass();
36         $serializerPass->process($container);
37     }
38
39     /**
40      * @expectedException \RuntimeException
41      * @expectedExceptionMessage You must tag at least one service as "serializer.encoder" to use the "serializer" service
42      */
43     public function testThrowExceptionWhenNoEncoders()
44     {
45         $container = new ContainerBuilder();
46         $container->register('serializer')
47             ->addArgument(array())
48             ->addArgument(array());
49         $container->register('normalizer')->addTag('serializer.normalizer');
50
51         $serializerPass = new SerializerPass();
52         $serializerPass->process($container);
53     }
54
55     public function testServicesAreOrderedAccordingToPriority()
56     {
57         $container = new ContainerBuilder();
58
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');
63
64         $serializerPass = new SerializerPass();
65         $serializerPass->process($container);
66
67         $expected = array(
68             new Reference('n1'),
69             new Reference('n2'),
70             new Reference('n3'),
71         );
72         $this->assertEquals($expected, $definition->getArgument(0));
73         $this->assertEquals($expected, $definition->getArgument(1));
74     }
75 }