|
4 | 4 |
|
5 | 5 | use FOS\OAuthServerBundle\DependencyInjection\Security\Factory\OAuthFactory;
|
6 | 6 | use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
| 7 | +use Symfony\Component\DependencyInjection\ChildDefinition; |
7 | 8 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
8 | 9 | use Symfony\Component\DependencyInjection\Definition;
|
9 | 10 | use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
@@ -39,6 +40,17 @@ public function testGetKey()
|
39 | 40 | }
|
40 | 41 |
|
41 | 42 | public function testCreate()
|
| 43 | + { |
| 44 | + if (class_exists('Symfony\Component\DependencyInjection\DefinitionDecorator')) { |
| 45 | + return $this->useDefinitionDecorator(); |
| 46 | + } elseif (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) { |
| 47 | + return $this->useChildDefinition(); |
| 48 | + } |
| 49 | + |
| 50 | + throw new \Exception('Neither DefinitionDecorator nor ChildDefinition exist'); |
| 51 | + } |
| 52 | + |
| 53 | + protected function useDefinitionDecorator() |
42 | 54 | {
|
43 | 55 | $container = $this->getMockBuilder(ContainerBuilder::class)
|
44 | 56 | ->disableOriginalConstructor()
|
@@ -91,6 +103,59 @@ public function testCreate()
|
91 | 103 | ], $this->instance->create($container, $id, $config, $userProvider, $defaultEntryPoint));
|
92 | 104 | }
|
93 | 105 |
|
| 106 | + protected function useChildDefinition() |
| 107 | + { |
| 108 | + $container = $this->getMockBuilder(ContainerBuilder::class) |
| 109 | + ->disableOriginalConstructor() |
| 110 | + ->setMethods([ |
| 111 | + 'setDefinition', |
| 112 | + |
| 113 | + ]) |
| 114 | + ->getMock() |
| 115 | + ; |
| 116 | + $id = '12'; |
| 117 | + $config = []; |
| 118 | + $userProvider = 'mock.user.provider.service'; |
| 119 | + $defaultEntryPoint = ''; |
| 120 | + |
| 121 | + $definition = $this->getMockBuilder(Definition::class) |
| 122 | + ->disableOriginalConstructor() |
| 123 | + ->getMock() |
| 124 | + ; |
| 125 | + |
| 126 | + $container |
| 127 | + ->expects($this->exactly(2)) |
| 128 | + ->method('setDefinition') |
| 129 | + ->withConsecutive( |
| 130 | + [ |
| 131 | + 'security.authentication.provider.fos_oauth_server.'. $id, |
| 132 | + new ChildDefinition('fos_oauth_server.security.authentication.provider') |
| 133 | + ], |
| 134 | + [ |
| 135 | + 'security.authentication.listener.fos_oauth_server.'. $id, |
| 136 | + new ChildDefinition('fos_oauth_server.security.authentication.listener') |
| 137 | + ] |
| 138 | + ) |
| 139 | + ->willReturnOnConsecutiveCalls( |
| 140 | + $definition, |
| 141 | + null |
| 142 | + ) |
| 143 | + ; |
| 144 | + |
| 145 | + $definition |
| 146 | + ->expects($this->once()) |
| 147 | + ->method('replaceArgument') |
| 148 | + ->with(0, new Reference($userProvider)) |
| 149 | + ->willReturn(null) |
| 150 | + ; |
| 151 | + |
| 152 | + $this->assertSame([ |
| 153 | + 'security.authentication.provider.fos_oauth_server.'. $id, |
| 154 | + 'security.authentication.listener.fos_oauth_server.'. $id, |
| 155 | + 'fos_oauth_server.security.entry_point' |
| 156 | + ], $this->instance->create($container, $id, $config, $userProvider, $defaultEntryPoint)); |
| 157 | + } |
| 158 | + |
94 | 159 | public function testAddConfigurationDoesNothing()
|
95 | 160 | {
|
96 | 161 | $nodeDefinition = $this->getMockBuilder(NodeDefinition::class)
|
|
0 commit comments