File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
src/Symfony/Bundle/DependencyInjection/Compiler
tests/Symfony/Bundle/DependencyInjection/Compiler Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -39,14 +39,20 @@ public function process(ContainerBuilder $container): void
39
39
}
40
40
41
41
$ definition = $ container ->getDefinition ('serializer.name_converter.metadata_aware ' );
42
- $ num = \count ($ definition ->getArguments ());
42
+ $ key = '$fallbackNameConverter ' ;
43
+ $ arguments = $ definition ->getArguments ();
44
+ if (false === \array_key_exists ($ key , $ arguments )) {
45
+ $ key = 1 ;
46
+ }
43
47
44
48
if ($ container ->hasAlias ('api_platform.name_converter ' )) {
45
49
$ nameConverter = new Reference ((string ) $ container ->getAlias ('api_platform.name_converter ' ));
46
- if (1 === $ num ) {
50
+
51
+ // old symfony versions
52
+ if (false === \array_key_exists ($ key , $ arguments )) {
47
53
$ definition ->addArgument ($ nameConverter );
48
- } elseif (1 < $ num && null === $ definition ->getArgument (1 )) {
49
- $ definition ->setArgument (1 , $ nameConverter );
54
+ } elseif (null === $ definition ->getArgument ($ key )) {
55
+ $ definition ->setArgument ($ key , $ nameConverter );
50
56
}
51
57
}
52
58
Original file line number Diff line number Diff line change @@ -101,4 +101,23 @@ public function testProcessOnlyOneArg(): void
101
101
102
102
$ pass ->process ($ containerBuilderProphecy ->reveal ());
103
103
}
104
+
105
+ public function testProcessWithAbstractMetadataAware (): void
106
+ {
107
+ $ pass = new MetadataAwareNameConverterPass ();
108
+
109
+ $ definition = $ this ->prophesize (Definition::class);
110
+ $ definition ->getArguments ()->willReturn (['$metadataFactory ' => [], '$fallbackNameConverter ' => null ])->shouldBeCalled ();
111
+ $ definition ->getArgument ('$fallbackNameConverter ' )->willReturn (null )->shouldBeCalled ();
112
+ $ definition ->setArgument ('$fallbackNameConverter ' , new Reference ('app.name_converter ' ))->willReturn ($ definition )->shouldBeCalled ();
113
+
114
+ $ containerBuilderProphecy = $ this ->prophesize (ContainerBuilder::class);
115
+ $ containerBuilderProphecy ->hasDefinition ('serializer.name_converter.metadata_aware ' )->willReturn (true )->shouldBeCalled ();
116
+ $ containerBuilderProphecy ->hasAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (true );
117
+ $ containerBuilderProphecy ->getAlias ('api_platform.name_converter ' )->shouldBeCalled ()->willReturn (new Alias ('app.name_converter ' ));
118
+ $ containerBuilderProphecy ->setAlias ('api_platform.name_converter ' , 'serializer.name_converter.metadata_aware ' )->shouldBeCalled ();
119
+ $ containerBuilderProphecy ->getDefinition ('serializer.name_converter.metadata_aware ' )->shouldBeCalled ()->willReturn ($ definition );
120
+
121
+ $ pass ->process ($ containerBuilderProphecy ->reveal ());
122
+ }
104
123
}
You can’t perform that action at this time.
0 commit comments