Skip to content

Commit 3c414d8

Browse files
dinamicdkarlovi
authored andcommitted
+ added unit test for OAuthFactory
1 parent dad5b08 commit 3c414d8

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace FOS\OAuthServerBundle\Tests\DependencyInjection\Security\Factory;
4+
5+
use FOS\OAuthServerBundle\DependencyInjection\Security\Factory\OAuthFactory;
6+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Definition;
9+
use Symfony\Component\DependencyInjection\DefinitionDecorator;
10+
use Symfony\Component\DependencyInjection\Reference;
11+
12+
/**
13+
* Class OAuthFactoryTest
14+
* @package FOS\OAuthServerBundle\Tests\DependencyInjection\Security\Factory
15+
* @author Nikola Petkanski <[email protected]>
16+
*/
17+
class OAuthFactoryTest extends \PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @var OAuthFactory
21+
*/
22+
protected $instance;
23+
24+
public function setUp()
25+
{
26+
$this->instance = new OAuthFactory();
27+
28+
parent::setUp();
29+
}
30+
31+
public function testGetPosition()
32+
{
33+
$this->assertSame('pre_auth', $this->instance->getPosition());
34+
}
35+
36+
public function testGetKey()
37+
{
38+
$this->assertSame('fos_oauth', $this->instance->getKey());
39+
}
40+
41+
public function testCreate()
42+
{
43+
$container = $this->createMock(ContainerBuilder::class);
44+
$id = '12';
45+
$config = [];
46+
$userProvider = 'mock.user.provider.service';
47+
$defaultEntryPoint = '';
48+
49+
$definition = $this->createMock(Definition::class);
50+
51+
$container
52+
->expects($this->exactly(2))
53+
->method('setDefinition')
54+
->withConsecutive(
55+
[
56+
'security.authentication.provider.fos_oauth_server.'. $id,
57+
new DefinitionDecorator('fos_oauth_server.security.authentication.provider')
58+
],
59+
[
60+
'security.authentication.listener.fos_oauth_server.'. $id,
61+
new DefinitionDecorator('fos_oauth_server.security.authentication.listener')
62+
]
63+
)
64+
->willReturnOnConsecutiveCalls(
65+
$definition,
66+
null
67+
)
68+
;
69+
70+
$definition
71+
->expects($this->once())
72+
->method('replaceArgument')
73+
->with(0, new Reference($userProvider))
74+
->willReturn(null)
75+
;
76+
77+
$this->assertSame([
78+
'security.authentication.provider.fos_oauth_server.'. $id,
79+
'security.authentication.listener.fos_oauth_server.'. $id,
80+
'fos_oauth_server.security.entry_point'
81+
], $this->instance->create($container, $id, $config, $userProvider, $defaultEntryPoint));
82+
}
83+
84+
public function testAddConfigurationDoesNothing()
85+
{
86+
$nodeDefinition = $this->createMock(NodeDefinition::class);
87+
$this->assertNull($this->instance->addConfiguration($nodeDefinition));
88+
}
89+
}

0 commit comments

Comments
 (0)