Skip to content

Commit 4c390ad

Browse files
dinamicdkarlovi
authored andcommitted
~ fixed unit test for OAuthFactory to test with ChildDefinition or DefinitionDecorator, depending on what's available
1 parent dedbdce commit 4c390ad

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use FOS\OAuthServerBundle\DependencyInjection\Security\Factory\OAuthFactory;
66
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
7+
use Symfony\Component\DependencyInjection\ChildDefinition;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
89
use Symfony\Component\DependencyInjection\Definition;
910
use Symfony\Component\DependencyInjection\DefinitionDecorator;
@@ -39,6 +40,17 @@ public function testGetKey()
3940
}
4041

4142
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()
4254
{
4355
$container = $this->getMockBuilder(ContainerBuilder::class)
4456
->disableOriginalConstructor()
@@ -91,6 +103,59 @@ public function testCreate()
91103
], $this->instance->create($container, $id, $config, $userProvider, $defaultEntryPoint));
92104
}
93105

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+
94159
public function testAddConfigurationDoesNothing()
95160
{
96161
$nodeDefinition = $this->getMockBuilder(NodeDefinition::class)

0 commit comments

Comments
 (0)