17
17
use PHPUnit \Framework \TestCase ;
18
18
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
19
19
use Symfony \Component \DependencyInjection \ContainerBuilder ;
20
+ use Symfony \Component \DependencyInjection \Definition ;
21
+ use Symfony \Component \DependencyInjection \Reference ;
20
22
21
23
/**
22
24
* @author Antoine Bluchet <[email protected] >
23
25
*/
24
26
class MetadataAwareNameConverterPassTest extends TestCase
25
27
{
28
+ public function testConstruct ()
29
+ {
30
+ $ this ->assertInstanceOf (CompilerPassInterface::class, new MetadataAwareNameConverterPass ());
31
+ }
32
+
26
33
public function testProcess ()
27
34
{
28
35
$ pass = new MetadataAwareNameConverterPass ();
29
- $ this ->assertInstanceOf (CompilerPassInterface::class, $ pass );
36
+
37
+ $ arguments = [new Reference ('serializer.mapping.class_metadata_factory ' ), new Reference ('app.name_converter ' )];
38
+
39
+ $ definition = $ this ->prophesize (Definition::class);
40
+ $ definition ->getArguments ()->willReturn ($ arguments )->shouldBeCalled ();
41
+ $ definition ->getArgument (1 )->willReturn ($ arguments [1 ])->shouldBeCalled ();
30
42
31
43
$ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
32
- $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (false );
33
- $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->shouldBeCalled ()->willReturn (true );
44
+ $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->willReturn (false )->shouldBeCalled ();
45
+ $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->willReturn (true )->shouldBeCalled ();
46
+ $ containerBuilderProphecy ->getDefinition ('serializer.name_converter.metadata_aware ' )->willReturn ($ definition )->shouldBeCalled ();
34
47
$ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldBeCalled ();
35
48
36
49
$ pass ->process ($ containerBuilderProphecy ->reveal ());
@@ -39,11 +52,11 @@ public function testProcess()
39
52
public function testProcessWithNameConverter ()
40
53
{
41
54
$ pass = new MetadataAwareNameConverterPass ();
42
- $ this ->assertInstanceOf (CompilerPassInterface::class, $ pass );
43
55
44
56
$ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
45
- $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (true );
46
- $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ()->willReturn (true );
57
+ $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->willReturn (true )->shouldBeCalled ();
58
+ $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ();
59
+ $ containerBuilderProphecy ->getDefinition ('serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ();
47
60
$ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ();
48
61
49
62
$ pass ->process ($ containerBuilderProphecy ->reveal ());
@@ -52,11 +65,29 @@ public function testProcessWithNameConverter()
52
65
public function testProcessWithoutMetadataAwareDefinition ()
53
66
{
54
67
$ pass = new MetadataAwareNameConverterPass ();
55
- $ this ->assertInstanceOf (CompilerPassInterface::class, $ pass );
56
68
57
69
$ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
58
- $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (false );
59
- $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->shouldBeCalled ()->willReturn (false );
70
+ $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->willReturn (false )->shouldBeCalled ();
71
+ $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->willReturn (false )->shouldBeCalled ();
72
+ $ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ();
73
+
74
+ $ pass ->process ($ containerBuilderProphecy ->reveal ());
75
+ }
76
+
77
+ public function testProcessWithMetadataAwareDefinitionSecondArgumentNull ()
78
+ {
79
+ $ pass = new MetadataAwareNameConverterPass ();
80
+
81
+ $ arguments = [new Reference ('serializer.mapping.class_metadata_factory ' ), null ];
82
+
83
+ $ definition = $ this ->prophesize (Definition::class);
84
+ $ definition ->getArguments ()->willReturn ($ arguments )->shouldBeCalled ();
85
+ $ definition ->getArgument (1 )->willReturn ($ arguments [1 ])->shouldBeCalled ();
86
+
87
+ $ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
88
+ $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->willReturn (false )->shouldBeCalled ();
89
+ $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->willReturn (true )->shouldBeCalled ();
90
+ $ containerBuilderProphecy ->getDefinition ('serializer.name_converter.metadata_aware ' )->willReturn ($ definition )->shouldBeCalled ();
60
91
$ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ();
61
92
62
93
$ pass ->process ($ containerBuilderProphecy ->reveal ());
0 commit comments