15
15
16
16
use ApiPlatform \Core \Bridge \Symfony \Bundle \DependencyInjection \Compiler \MetadataAwareNameConverterPass ;
17
17
use PHPUnit \Framework \TestCase ;
18
+ use Prophecy \Argument ;
19
+ use Symfony \Component \DependencyInjection \Alias ;
18
20
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
19
21
use Symfony \Component \DependencyInjection \ContainerBuilder ;
20
22
use Symfony \Component \DependencyInjection \Definition ;
@@ -30,18 +32,17 @@ public function testConstruct()
30
32
$ this ->assertInstanceOf (CompilerPassInterface::class, new MetadataAwareNameConverterPass ());
31
33
}
32
34
33
- public function testProcess ()
35
+ public function testProcessFirstArgumentConfigured ()
34
36
{
35
37
$ pass = new MetadataAwareNameConverterPass ();
36
38
37
- $ arguments = [new Reference ('serializer.mapping.class_metadata_factory ' ), new Reference ('app.name_converter ' )];
38
-
39
39
$ definition = $ this ->prophesize (Definition::class);
40
- $ definition ->getArguments ()->willReturn ($ arguments )->shouldBeCalled ();
41
- $ definition ->getArgument (1 )->willReturn ($ arguments [ 1 ] )->shouldBeCalled ();
40
+ $ definition ->getArguments ()->willReturn ([ 0 , 1 ] )->shouldBeCalled ();
41
+ $ definition ->getArgument (1 )->willReturn (new Reference ( ' app.name_converter ' ) )->shouldBeCalled ();
42
42
43
43
$ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
44
- $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->willReturn (false )->shouldBeCalled ();
44
+ $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (true );
45
+ $ containerBuilderProphecy ->getAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (Argument::any ());
45
46
$ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->willReturn (true )->shouldBeCalled ();
46
47
$ containerBuilderProphecy ->getDefinition ('serializer.name_converter.metadata_aware ' )->willReturn ($ definition )->shouldBeCalled ();
47
48
$ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldBeCalled ();
@@ -53,11 +54,19 @@ public function testProcessWithNameConverter()
53
54
{
54
55
$ pass = new MetadataAwareNameConverterPass ();
55
56
57
+ $ reference = new Reference ('app.name_converter ' );
58
+
59
+ $ definition = $ this ->prophesize (Definition::class);
60
+ $ definition ->getArguments ()->willReturn ([0 , 1 ])->shouldBeCalled ();
61
+ $ definition ->getArgument (1 )->willReturn (null )->shouldBeCalled ();
62
+ $ definition ->setArgument (1 , $ reference )->shouldBeCalled ();
63
+
56
64
$ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
57
65
$ 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 ();
60
- $ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ();
66
+ $ containerBuilderProphecy ->getAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (new Alias ('app.name_converter ' ));
67
+ $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->shouldBeCalled ()->willReturn (true );
68
+ $ containerBuilderProphecy ->getDefinition ('serializer.name_converter.metadata_aware ' )->shouldBeCalled ()->willReturn ($ definition );
69
+ $ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldBeCalled ();
61
70
62
71
$ pass ->process ($ containerBuilderProphecy ->reveal ());
63
72
}
@@ -67,28 +76,26 @@ public function testProcessWithoutMetadataAwareDefinition()
67
76
$ pass = new MetadataAwareNameConverterPass ();
68
77
69
78
$ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
70
- $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->willReturn (false )->shouldBeCalled ();
71
79
$ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->willReturn (false )->shouldBeCalled ();
72
80
$ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ();
73
81
74
82
$ pass ->process ($ containerBuilderProphecy ->reveal ());
75
83
}
76
84
77
- public function testProcessWithMetadataAwareDefinitionSecondArgumentNull ()
85
+ public function testProcessOnlyOneArg ()
78
86
{
79
87
$ pass = new MetadataAwareNameConverterPass ();
80
88
81
- $ arguments = [new Reference ('serializer.mapping.class_metadata_factory ' ), null ];
82
-
83
89
$ definition = $ this ->prophesize (Definition::class);
84
- $ definition ->getArguments ()->willReturn ($ arguments )->shouldBeCalled ();
85
- $ definition ->getArgument ( 1 )-> willReturn ( $ arguments [ 1 ] )->shouldBeCalled ();
90
+ $ definition ->getArguments ()->willReturn ([ 0 ] )->shouldBeCalled ();
91
+ $ definition ->addArgument ( new Reference ( ' app.name_converter ' ) )->shouldBeCalled ();
86
92
87
93
$ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
88
- $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->willReturn (false )->shouldBeCalled ();
89
94
$ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->willReturn (true )->shouldBeCalled ();
90
- $ containerBuilderProphecy ->getDefinition ('serializer.name_converter.metadata_aware ' )->willReturn ($ definition )->shouldBeCalled ();
91
- $ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldNotBeCalled ();
95
+ $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (true );
96
+ $ containerBuilderProphecy ->getAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (new Alias ('app.name_converter ' ));
97
+ $ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldBeCalled ();
98
+ $ containerBuilderProphecy ->getDefinition ('serializer.name_converter.metadata_aware ' )->shouldBeCalled ()->willReturn ($ definition );
92
99
93
100
$ pass ->process ($ containerBuilderProphecy ->reveal ());
94
101
}
0 commit comments