|
23 | 23 | */
|
24 | 24 | class SerializerPassTest extends TestCase
|
25 | 25 | {
|
| 26 | + /** |
| 27 | + * @expectedException \RuntimeException |
| 28 | + * @expectedExceptionMessage You must tag at least one service as "serializer.normalizer" to use the "serializer" service |
| 29 | + */ |
26 | 30 | public function testThrowExceptionWhenNoNormalizers()
|
27 | 31 | {
|
28 |
| - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds'))->getMock(); |
29 |
| - |
30 |
| - $container->expects($this->once()) |
31 |
| - ->method('hasDefinition') |
32 |
| - ->with('serializer') |
33 |
| - ->will($this->returnValue(true)); |
34 |
| - |
35 |
| - $container->expects($this->once()) |
36 |
| - ->method('findTaggedServiceIds') |
37 |
| - ->with('serializer.normalizer') |
38 |
| - ->will($this->returnValue(array())); |
39 |
| - |
40 |
| - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\RuntimeException::class); |
| 32 | + $container = new ContainerBuilder(); |
| 33 | + $container->register('serializer'); |
41 | 34 |
|
42 | 35 | $serializerPass = new SerializerPass();
|
43 | 36 | $serializerPass->process($container);
|
44 | 37 | }
|
45 | 38 |
|
| 39 | + /** |
| 40 | + * @expectedException \RuntimeException |
| 41 | + * @expectedExceptionMessage You must tag at least one service as "serializer.encoder" to use the "serializer" service |
| 42 | + */ |
46 | 43 | public function testThrowExceptionWhenNoEncoders()
|
47 | 44 | {
|
48 |
| - $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock(); |
49 |
| - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock(); |
50 |
| - |
51 |
| - $container->expects($this->once()) |
52 |
| - ->method('hasDefinition') |
53 |
| - ->with('serializer') |
54 |
| - ->will($this->returnValue(true)); |
55 |
| - |
56 |
| - $container->expects($this->any()) |
57 |
| - ->method('findTaggedServiceIds') |
58 |
| - ->will($this->onConsecutiveCalls( |
59 |
| - array('n' => array('serializer.normalizer')), |
60 |
| - array() |
61 |
| - )); |
62 |
| - |
63 |
| - $container->expects($this->any()) |
64 |
| - ->method('getDefinition') |
65 |
| - ->will($this->returnValue($definition)); |
66 |
| - |
67 |
| - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\RuntimeException::class); |
| 45 | + $container = new ContainerBuilder(); |
| 46 | + $container->register('serializer') |
| 47 | + ->addArgument(array()) |
| 48 | + ->addArgument(array()); |
| 49 | + $container->register('normalizer')->addTag('serializer.normalizer'); |
68 | 50 |
|
69 | 51 | $serializerPass = new SerializerPass();
|
70 | 52 | $serializerPass->process($container);
|
|
0 commit comments