RegisterSecurityVotersPassSpec   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 159
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A it_should_be_a_compiler_pass() 0 4 1
B it_should_register_security_voters_found_in_the_bundle() 0 42 1
B it_should_not_register_security_voters_that_do_not_implement_correct_interface() 0 31 1
A it_should_abort_processing_when_decision_manager_is_not_defined() 0 9 1
B it_should_use_configured_decision_manager() 0 31 1
A let() 0 8 1
1
<?php
2
3
namespace spec\Knp\RadBundle\DependencyInjection\Compiler;
4
5
use PhpSpec\ObjectBehavior;
6
7
class RegisterSecurityVotersPassSpec extends ObjectBehavior
8
{
9
    /**
10
     * @param  Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
11
     * @param  Symfony\Component\DependencyInjection\ContainerBuilder $container
12
     * @param  Knp\RadBundle\Finder\ClassFinder $classFinder
13
     * @param  Knp\RadBundle\DependencyInjection\Definition\SecurityVoterFactory $definitionFactory
14
     * @param  Knp\RadBundle\DependencyInjection\ReferenceFactory $referenceFactory
15
     * @param  Knp\RadBundle\DependencyInjection\ServiceIdGenerator $serviceIdGenerator
16
     * @param  Knp\RadBundle\DependencyInjection\DefinitionManipulator $definitionManipulator
17
     */
18
    function let($bundle, $container, $classFinder, $definitionFactory, $referenceFactory, $serviceIdGenerator, $definitionManipulator)
19
    {
20
        $container->getParameter('knp_rad.detect.security_voter')->willReturn(true);
21
        $this->beConstructedWith($bundle, $classFinder, $definitionFactory, $referenceFactory, $serviceIdGenerator, $definitionManipulator);
22
23
        $bundle->getPath()->willReturn('/my/project/src/App');
24
        $bundle->getNamespace()->willReturn('App');
25
    }
26
27
    function it_should_be_a_compiler_pass()
0 ignored issues
show
Coding Style introduced by
Method name "RegisterSecurityVotersPassSpec::it_should_be_a_compiler_pass" is not in camel caps format
Loading history...
28
    {
29
        $this->shouldBeAnInstanceOf('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface');
30
    }
31
32
    /**
33
     * @param  Symfony\Component\DependencyInjection\Definition $decisionManagerDef
34
     * @param  Symfony\Component\DependencyInjection\Definition $cheeseVoterDef
35
     * @param  Symfony\Component\DependencyInjection\Definition $customerVoterDef
36
     * @param  Symfony\Component\DependencyInjection\Reference $cheeseVoterRef
37
     * @param  Symfony\Component\DependencyInjection\Reference $customerVoterRef
38
     */
39
    function it_should_register_security_voters_found_in_the_bundle($bundle, $container, $classFinder, $definitionFactory, $serviceIdGenerator, $referenceFactory, $definitionManipulator, $decisionManagerDef, $cheeseVoterDef, $customerVoterDef, $cheeseVoterRef, $customerVoterRef)
0 ignored issues
show
Coding Style introduced by
Method name "RegisterSecurityVotersPassSpec::it_should_register_security_voters_found_in_the_bundle" is not in camel caps format
Loading history...
40
    {
41
        $container->getParameter('knp_rad.decision_manager.id')->willReturn('security.access.decision_manager');
42
        $container->hasDefinition('security.access.decision_manager')->willReturn(true);
43
        $container->getDefinition('security.access.decision_manager')->willReturn($decisionManagerDef);
44
45
        $classes = array(
46
            'App\Security\Voter\CheeseVoter',
47
            'App\Security\Voter\CustomerVoter',
48
        );
49
50
        $classFinder->findClassesMatching('/my/project/src/App/Security', 'App\Security', 'Voter$')->willReturn($classes);
51
52
        $classFinder->filterClassesImplementing(
53
            $classes,
54
            'Symfony\Component\Security\Core\Authorization\Voter\VoterInterface')
55
            ->willReturn(array(
56
                'App\Security\Voter\CheeseVoter',
57
                'App\Security\Voter\CustomerVoter',
58
            )
59
        );
60
61
        $container->hasDefinition('app.security.voter.cheese_voter')->willReturn(false)->shouldBeCalled();
62
        $container->hasDefinition('app.security.voter.customer_voter')->willReturn(false)->shouldBeCalled();
63
64
        $definitionFactory->createDefinition('App\Security\Voter\CheeseVoter')->willReturn($cheeseVoterDef);
65
        $definitionFactory->createDefinition('App\Security\Voter\CustomerVoter')->willReturn($customerVoterDef);
66
67
        $serviceIdGenerator->generateForBundleClass($bundle, 'App\Security\Voter\CheeseVoter')->shouldBeCalled()->willReturn('app.security.voter.cheese_voter');
68
        $serviceIdGenerator->generateForBundleClass($bundle, 'App\Security\Voter\CustomerVoter')->shouldBeCalled()->willReturn('app.security.voter.customer_voter');
69
70
        $container->setDefinition('app.security.voter.cheese_voter', $cheeseVoterDef)->shouldBeCalled();
71
        $container->setDefinition('app.security.voter.customer_voter', $customerVoterDef)->shouldBeCalled();
72
73
        $referenceFactory->createReference('app.security.voter.cheese_voter')->willReturn($cheeseVoterRef);
74
        $referenceFactory->createReference('app.security.voter.customer_voter')->willReturn($customerVoterRef);
75
76
        $definitionManipulator->appendArgumentValue($decisionManagerDef, 0, $cheeseVoterRef)->shouldBeCalled();
77
        $definitionManipulator->appendArgumentValue($decisionManagerDef, 0, $customerVoterRef)->shouldBeCalled();
78
79
        $this->process($container);
80
    }
81
82
    /**
83
     * @param  Symfony\Component\DependencyInjection\Definition $decisionManagerDef
84
     * @param  Symfony\Component\DependencyInjection\Definition $customerVoterDef
85
     * @param  Symfony\Component\DependencyInjection\Reference $customerVoterRef
86
     */
87
    function it_should_not_register_security_voters_that_do_not_implement_correct_interface($bundle, $container, $classFinder, $definitionFactory, $serviceIdGenerator, $referenceFactory, $definitionManipulator, $decisionManagerDef, $customerVoterDef, $customerVoterRef)
0 ignored issues
show
Coding Style introduced by
Method name "RegisterSecurityVotersPassSpec::it_should_not_register_security_voters_that_do_not_implement_correct_interface" is not in camel caps format
Loading history...
88
    {
89
        $container->getParameter('knp_rad.decision_manager.id')->willReturn('security.access.decision_manager');
90
        $container->hasDefinition('security.access.decision_manager')->willReturn(true);
91
        $container->getDefinition('security.access.decision_manager')->willReturn($decisionManagerDef);
92
93
        $classes = array(
94
            'App\Security\Voter\CheeseVoter',
95
            'App\Security\Voter\CustomerVoter',
96
        );
97
98
        $classFinder->findClassesMatching('/my/project/src/App/Security', 'App\Security', 'Voter$')->willReturn($classes);
99
100
        $classFinder->filterClassesImplementing($classes, 'Symfony\Component\Security\Core\Authorization\Voter\VoterInterface')
101
            ->willReturn(array(
102
                'App\Security\Voter\CustomerVoter',
103
            )
104
        );
105
106
        $container->hasDefinition('app.security.voter.cheese_voter')->shouldNotBeCalled();
107
        $container->hasDefinition('app.security.voter.customer_voter')->shouldBeCalled();
108
109
        $definitionFactory->createDefinition('App\Security\Voter\CustomerVoter')->willReturn($customerVoterDef);
110
111
        $serviceIdGenerator->generateForBundleClass($bundle, 'App\Security\Voter\CustomerVoter')->shouldBeCalled()->willReturn('app.security.voter.customer_voter');
112
        $container->setDefinition('app.security.voter.customer_voter', $customerVoterDef)->shouldBeCalled();
113
        $referenceFactory->createReference('app.security.voter.customer_voter')->willReturn($customerVoterRef);
114
        $definitionManipulator->appendArgumentValue($decisionManagerDef, 0, $customerVoterRef)->shouldBeCalled();
115
116
        $this->process($container);
117
    }
118
119
    function it_should_abort_processing_when_decision_manager_is_not_defined($container, $classFinder)
0 ignored issues
show
Coding Style introduced by
Method name "RegisterSecurityVotersPassSpec::it_should_abort_processing_when_decision_manager_is_not_defined" is not in camel caps format
Loading history...
120
    {
121
        $container->getParameter('knp_rad.decision_manager.id')->willReturn('security.access.decision_manager');
122
        $container->hasDefinition('security.access.decision_manager')->willReturn(false);
123
        $container->getDefinition('security.access.decision_manager')->shouldNotBeCalled();
124
        $classFinder->findClassesMatching(\Prophecy\Argument::cetera())->shouldNotBeCalled();
125
126
        $this->process($container);
127
    }
128
129
    /**
130
     * @param  Symfony\Component\DependencyInjection\Definition $decisionManagerDef
131
     * @param  Symfony\Component\DependencyInjection\Definition $customerVoterDef
132
     * @param  Symfony\Component\DependencyInjection\Reference $customerVoterRef
133
     */
134
    function it_should_use_configured_decision_manager($bundle, $container, $classFinder, $definitionFactory, $serviceIdGenerator, $referenceFactory, $definitionManipulator, $decisionManagerDef, $customerVoterDef, $customerVoterRef)
0 ignored issues
show
Coding Style introduced by
Method name "RegisterSecurityVotersPassSpec::it_should_use_configured_decision_manager" is not in camel caps format
Loading history...
135
    {
136
        $container->getParameter('knp_rad.decision_manager.id')->willReturn('security.access.decision_manager.delegate');
137
        $container->hasDefinition('security.access.decision_manager.delegate')->willReturn(true);
138
        $container->getDefinition('security.access.decision_manager.delegate')->willReturn($decisionManagerDef);
139
140
        $classes = array(
141
            'App\Security\Voter\CheeseVoter',
142
            'App\Security\Voter\CustomerVoter',
143
        );
144
145
        $classFinder->findClassesMatching('/my/project/src/App/Security', 'App\Security', 'Voter$')->willReturn($classes);
146
147
        $classFinder->filterClassesImplementing($classes, 'Symfony\Component\Security\Core\Authorization\Voter\VoterInterface')
148
            ->willReturn(array(
149
                'App\Security\Voter\CustomerVoter',
150
            )
151
        );
152
153
        $container->hasDefinition('app.security.voter.cheese_voter')->shouldNotBeCalled();
154
        $container->hasDefinition('app.security.voter.customer_voter')->shouldBeCalled();
155
156
        $definitionFactory->createDefinition('App\Security\Voter\CustomerVoter')->willReturn($customerVoterDef);
157
158
        $serviceIdGenerator->generateForBundleClass($bundle, 'App\Security\Voter\CustomerVoter')->shouldBeCalled()->willReturn('app.security.voter.customer_voter');
159
        $container->setDefinition('app.security.voter.customer_voter', $customerVoterDef)->shouldBeCalled();
160
        $referenceFactory->createReference('app.security.voter.customer_voter')->willReturn($customerVoterRef);
161
        $definitionManipulator->appendArgumentValue($decisionManagerDef, 0, $customerVoterRef)->shouldBeCalled();
162
163
        $this->process($container);
164
    }
165
}
166