Completed
Push — feature/auth-multi-strategy-co... ( 0e8a44...9d43fb )
by
unknown
05:55
created

AuthenticationKeyFinderPassTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 84
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testProcess() 0 76 1
1
<?php
2
/**
3
 * Class AuthenticationKeyFinderPassTest
4
 */
5
6
namespace Graviton\SecurityBundle\Tests\DepedencyInjection\Compiler;
7
8
use Graviton\SecurityBundle\DependencyInjection\Compiler\AuthenticationKeyFinderPass;
9
10
/**
11
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
12
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
13
 * @link     http://swisscom.ch
14
 */
15
class AuthenticationKeyFinderPassTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * test process method
19
     *
20
     * @return void
21
     */
22
    public function testProcess()
23
    {
24
        $message = 'The service (strategy.doesnotExists) is not registered in the application kernel.';
25
26
        $loggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface')
27
            ->setMethods(array('warning'))
28
            ->getMockForAbstractClass();
29
        $loggerMock
30
            ->expects($this->once())
31
            ->method('warning')
32
            ->with($this->equalTo($message));
33
34
        $definitionMock = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Definition')
35
            ->disableOriginalConstructor()
36
            ->getMock();
37
38
        $container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder')
39
            ->setMethods(
40
                [
41
                    'findTaggedServiceIds',
42
                    'getDefinition',
43
                    'getParameter',
44
                    'hasParameter',
45
                    'findDefinition',
46
                    'hasDefinition'
47
                ]
48
            )
49
            ->getMock();
50
        $container
51
            ->expects($this->exactly(1))
52
            ->method('findDefinition')
53
            ->will($this->returnValue($definitionMock));
54
        $container
55
            ->expects($this->exactly(1))
56
            ->method('hasParameter')
57
            ->will($this->returnValue(true));
58
        $container
59
            ->expects($this->exactly(2))
60
            ->method('getParameter')
61
            ->will(
62
                $this->onConsecutiveCalls(
63
                    $this->returnValue('graviton.security.authentication.strategy.multi'),
64
                    $this->returnValue(
65
                        [
66
                            'graviton.security.authentication.strategy.subnet',
67
                            'graviton.security.authentication.strategy.header',
68
                            'graviton.security.authentication.strategy.cookie',
69
                            'strategy.doesnotExists'
70
                        ]
71
                    )
72
                )
73
            );
74
        $container
75
            ->expects($this->exactly(1))
76
            ->method('getDefinition')
77
            ->will(
78
                $this->onConsecutiveCalls(
79
                    $this->returnValue($loggerMock)
80
                )
81
            );
82
        $container
83
            ->expects($this->exactly(5))
84
            ->method('hasDefinition')
85
            ->will(
86
                $this->onConsecutiveCalls(
87
                    $this->returnValue(true), // service id
88
                    $this->returnValue(true), // service id
89
                    $this->returnValue(true), // service id
90
                    $this->returnValue(false), // not exists service id
91
                    $this->returnValue(true) // logger service id
92
                )
93
            );
94
95
        $compilerPass = new AuthenticationKeyFinderPass();
96
        $compilerPass->process($container);
97
    }
98
}
99