it_should_not_use_isEqualTo_if_no_UserInterface()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 4
1
<?php
2
3
namespace spec\Knp\RadBundle\Security\Voter;
4
5
use PhpSpec\ObjectBehavior;
6
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
7
8
class IsOwnerVoterSpec extends ObjectBehavior
9
{
10
    /**
11
     * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token
0 ignored issues
show
Bug introduced by
There is no parameter named $token. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
12
     **/
13
    function let()
14
    {
15
    }
16
17
    function it_should_be_initializable()
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_be_initializable" is not in camel caps format
Loading history...
18
    {
19
        $this->shouldHaveType('Knp\RadBundle\Security\Voter\IsOwnerVoter');
20
    }
21
22
    function it_should_only_support_IS_OWNER_attribute()
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_only_support_IS_OWNER_attribute" is not in camel caps format
Loading history...
23
    {
24
        $this->supportsAttribute('IS_OWNER')->shouldReturn(true);
25
        $this->supportsAttribute('IS_SOMETHING_ELSE')->shouldReturn(false);
26
    }
27
28
    /**
29
     * @param Knp\RadBundle\Security\OwnerInterface   $user
30
     * @param Knp\RadBundle\Security\OwnableInterface $object
31
     **/
32
    function it_should_vote_yes_for_owned_object($token, $user, $object)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_vote_yes_for_owned_object" is not in camel caps format
Loading history...
33
    {
34
        $token->getUser()->willReturn($user);
35
        $object->getOwner()->willReturn($user);
36
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_GRANTED);
37
    }
38
39
    /**
40
     * @param Knp\RadBundle\Security\OwnerInterface   $user
41
     * @param Knp\RadBundle\Security\OwnerInterface   $otherUser
42
     * @param Knp\RadBundle\Security\OwnableInterface $object
43
     **/
44
    function it_should_vote_no_for_not_owned_object($token, $user, $otherUser, $object)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_vote_no_for_not_owned_object" is not in camel caps format
Loading history...
45
    {
46
        $token->getUser()->willReturn($user);
47
        $object->getOwner()->willReturn($otherUser);
48
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_DENIED);
49
    }
50
51
    /**
52
     * @param Knp\RadBundle\Security\OwnerInterface   $user
53
     * @param stdClass $object
54
     **/
55
    function it_should_abstain_to_vote_for_not_ownable_object($token, $user, $object)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_abstain_to_vote_for_not_ownable_object" is not in camel caps format
Loading history...
56
    {
57
        $token->getUser()->willReturn($user);
58
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_ABSTAIN);
59
    }
60
61
    /**
62
     * @param stdClass  $user
63
     * @param Knp\RadBundle\Security\OwnableInterface $object
64
     **/
65
    function it_should_abstain_to_vote_for_not_owner_token_user($token, $user, $object)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_abstain_to_vote_for_not_owner_token_user" is not in camel caps format
Loading history...
66
    {
67
        $token->getUser()->willReturn($user);
68
        $object->getOwner()->willReturn($user);
69
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_ABSTAIN);
70
    }
71
72
    /**
73
     * @param Knp\RadBundle\Security\OwnerInterface   $user
74
     * @param Knp\RadBundle\Security\OwnableInterface $object
75
     **/
76
    function it_should_abstain_to_vote_for_unknown_attribute($token, $user, $object)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_abstain_to_vote_for_unknown_attribute" is not in camel caps format
Loading history...
77
    {
78
        $token->getUser()->willReturn($user);
79
        $object->getOwner()->willReturn($user);
80
        $this->vote($token, $object, array('IS_TEST'))->shouldReturn(VoterInterface::ACCESS_ABSTAIN);
81
    }
82
83
    /**
84
     * @param Knp\RadBundle\Security\OwnableInterface $object
85
     * @param Symfony\Component\Security\Core\User\UserInterface $equatableUser
86
     * @param stdClass $user
87
     **/
88
    function it_should_vote_yes_for_equal_owners($token, $user, $object, $equatableUser)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_vote_yes_for_equal_owners" is not in camel caps format
Loading history...
89
    {
90
        $user->implement('Knp\RadBundle\Security\OwnerInterface');
91
        $user->implement('Symfony\Component\Security\Core\User\EquatableInterface');
92
93
        $token->getUser()->willReturn($user);
94
        $object->getOwner()->willReturn($equatableUser);
95
        $user->isEqualTo($equatableUser->getWrappedObject())->willReturn(true);
96
97
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_GRANTED);
98
    }
99
100
    /**
101
     * @param Knp\RadBundle\Security\OwnableInterface $object
102
     * @param Symfony\Component\Security\Core\User\UserInterface $equatableUser
103
     * @param stdClass $user
104
     **/
105
    function it_should_vote_no_for_non_equal_owners($token, $user, $object, $equatableUser)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_vote_no_for_non_equal_owners" is not in camel caps format
Loading history...
106
    {
107
        $user->implement('Knp\RadBundle\Security\OwnerInterface');
108
        $user->implement('Symfony\Component\Security\Core\User\EquatableInterface');
109
110
        $token->getUser()->willReturn($user);
111
        $object->getOwner()->willReturn($equatableUser);
112
        $user->isEqualTo($equatableUser->getWrappedObject())->willReturn(false);
113
114
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_DENIED);
115
    }
116
117
    /**
118
     * @param Knp\RadBundle\Security\OwnableInterface $object
119
     * @param Symfony\Component\Security\Core\User\UserInterface $equatableUser
120
     * @param stdClass $user
121
     **/
122
    function it_should_use_isEqualTo_if_possible($token, $user, $object, $equatableUser)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_use_isEqualTo_if_possible" is not in camel caps format
Loading history...
123
    {
124
        $user->implement('Knp\RadBundle\Security\OwnerInterface');
125
        $user->implement('Symfony\Component\Security\Core\User\EquatableInterface');
126
127
        $token->getUser()->willReturn($user);
128
        $object->getOwner()->willReturn($equatableUser);
129
        $user->isEqualTo($equatableUser->getWrappedObject())->shouldBeCalled();
130
131
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_DENIED);
132
    }
133
134
    /**
135
     * @param Knp\RadBundle\Security\OwnableInterface $object
136
     * @param Knp\RadBundle\Security\OwnerInterface $nonEquatableUser
137
     * @param stdClass $user
138
     **/
139
    function it_should_not_use_isEqualTo_if_no_UserInterface($token, $user, $object, $nonEquatableUser)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_not_use_isEqualTo_if_no_UserInterface" is not in camel caps format
Loading history...
140
    {
141
        $user->implement('Knp\RadBundle\Security\OwnerInterface');
142
        $user->implement('Symfony\Component\Security\Core\User\EquatableInterface');
143
144
        $token->getUser()->willReturn($user);
145
        $object->getOwner()->willReturn($nonEquatableUser);
146
        $user->isEqualTo($nonEquatableUser)->shouldNotBeCalled();
147
148
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_DENIED);
149
    }
150
151
    /**
152
     * @param Knp\RadBundle\Security\OwnableInterface $object
153
     * @param Symfony\Component\Security\Core\User\UserInterface $equatableUser
154
     * @param Knp\RadBundle\Security\OwnerInterface $user
155
     **/
156
    function it_should_not_use_isEqualTo_if_no_EquatableInterface($token, $user, $object, $equatableUser)
0 ignored issues
show
Coding Style introduced by
Method name "IsOwnerVoterSpec::it_should_not_use_isEqualTo_if_no_EquatableInterface" is not in camel caps format
Loading history...
157
    {
158
        $token->getUser()->willReturn($user);
159
        $object->getOwner()->willReturn($equatableUser);
160
161
        $this->vote($token, $object, array('IS_OWNER'))->shouldReturn(VoterInterface::ACCESS_DENIED);
162
    }
163
}
164