PasswordHashListenerSpec   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 2
dl 0
loc 155
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 9 1
A it_should_be_doctrine2_event_subscriber() 0 4 1
A it_should_support_persist_and_update_events() 0 7 1
A its_prePersist_should_rehash_user_password_if_new_password_providen() 0 11 1
A its_prePersist_should_erase_password_recovery_key_for_recoverable_user() 0 13 1
A its_prePersist_should_not_touch_entity_if_no_new_password_providen() 0 10 1
A its_prePersist_should_not_touch_entities_without_interface() 0 6 1
A its_preUpdate_should_rehash_user_password_if_new_password_providen() 0 15 1
A its_preUpdate_should_erase_password_recovery_key_for_recoverable_user() 0 15 1
A its_preUpdate_should_not_touch_entity_if_password_is_not_updated() 0 10 1
A its_preUpdate_should_not_touch_entities_without_interface() 0 6 1
1
<?php
2
3
namespace spec\Knp\RadBundle\Doctrine\Listener;
4
5
use PhpSpec\ObjectBehavior;
6
use Doctrine\ORM\Events;
7
8
class PasswordHashListenerSpec extends ObjectBehavior
9
{
10
    /**
11
     * @param Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface  $encoderFactory
12
     * @param Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface $encoder
13
     */
14
    function let($encoderFactory, $encoder)
15
    {
16
        $encoderFactory->getEncoder(\Prophecy\Argument::any())->willReturn($encoder);
17
        $encoder->encodePassword(\Prophecy\Argument::cetera())->will(function($args) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
18
            return $args[0].'#'.$args[1];
19
        });
20
21
        $this->beConstructedWith($encoderFactory);
22
    }
23
24
    function it_should_be_doctrine2_event_subscriber()
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::it_should_be_doctrine2_event_subscriber" is not in camel caps format
Loading history...
25
    {
26
        $this->shouldBeAnInstanceOf('Doctrine\Common\EventSubscriber');
27
    }
28
29
    function it_should_support_persist_and_update_events()
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::it_should_support_persist_and_update_events" is not in camel caps format
Loading history...
30
    {
31
        $this->getSubscribedEvents()->shouldReturn(array(
32
            Events::prePersist,
33
            Events::preUpdate,
34
        ));
35
    }
36
37
    /**
38
     * @param Doctrine\ORM\Event\LifecycleEventArgs $args
39
     * @param Knp\RadBundle\Security\UserInterface  $entity
40
     */
41
    function its_prePersist_should_rehash_user_password_if_new_password_providen($args, $entity)
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::its_prePersist_should_rehash_user_password_if_new_password_providen" is not in camel caps format
Loading history...
42
    {
43
        $args->getEntity()->willReturn($entity);
44
45
        $entity->getPlainPassword()->willReturn('custom_pass');
46
        $entity->getSalt()->willReturn('some_salt');
47
        $entity->setPassword('custom_pass#some_salt')->shouldBeCalled();
48
        $entity->eraseCredentials()->shouldBeCalled();
49
50
        $this->prePersist($args);
51
    }
52
53
    /**
54
     * @param Doctrine\ORM\Event\LifecycleEventArgs           $args
55
     * @param Knp\RadBundle\Security\RecoverableUserInterface $entity
56
     */
57
    function its_prePersist_should_erase_password_recovery_key_for_recoverable_user($args, $entity)
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::its_prePersist_should_erase_password_recovery_key_for_recoverable_user" is not in camel caps format
Loading history...
58
    {
59
        $args->getEntity()->willReturn($entity);
60
61
        $entity->getPlainPassword()->willReturn('custom_pass');
62
        $entity->getSalt()->willReturn('some_salt');
63
64
        $entity->erasePasswordRecoveryKey()->shouldBeCalled();
65
        $entity->setPassword('custom_pass#some_salt')->shouldBeCalled();
66
        $entity->eraseCredentials()->shouldBeCalled();
67
68
        $this->prePersist($args);
69
    }
70
71
    /**
72
     * @param Doctrine\ORM\Event\LifecycleEventArgs $args
73
     * @param Knp\RadBundle\Security\UserInterface  $entity
74
     */
75
    function its_prePersist_should_not_touch_entity_if_no_new_password_providen($args, $entity)
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::its_prePersist_should_not_touch_entity_if_no_new_password_providen" is not in camel caps format
Loading history...
76
    {
77
        $args->getEntity()->willReturn($entity);
78
79
        $entity->getPlainPassword()->willReturn(null);
80
        $entity->getSalt()->willReturn('some_salt');
81
        $entity->setPassword(\Prophecy\Argument::any())->shouldNotBeCalled();
82
83
        $this->prePersist($args);
84
    }
85
86
    /**
87
     * @param Doctrine\ORM\Event\LifecycleEventArgs $args
88
     * @param stdClass                              $entity
89
     */
90
    function its_prePersist_should_not_touch_entities_without_interface($args, $entity)
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::its_prePersist_should_not_touch_entities_without_interface" is not in camel caps format
Loading history...
91
    {
92
        $args->getEntity()->willReturn($entity);
93
94
        $this->prePersist($args);
95
    }
96
97
    /**
98
     * @param Doctrine\ORM\Event\PreUpdateEventArgs $args
99
     * @param Knp\RadBundle\Security\UserInterface  $entity
100
     */
101
    function its_preUpdate_should_rehash_user_password_if_new_password_providen($args, $entity)
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::its_preUpdate_should_rehash_user_password_if_new_password_providen" is not in camel caps format
Loading history...
102
    {
103
        $args->getEntity()->willReturn($entity);
104
105
        $entity->getPlainPassword()->willReturn('custom_pass');
106
        $entity->getSalt()->willReturn('some_salt');
107
108
        $entity->setPassword('custom_pass#some_salt')->shouldBeCalled();
109
        $entity->eraseCredentials()->shouldBeCalled();
110
111
        $entity->getPassword()->willReturn('custom_pass#some_salt');
112
        $args->setNewValue('password', 'custom_pass#some_salt')->shouldBeCalled();
113
114
        $this->preUpdate($args);
115
    }
116
117
    /**
118
     * @param Doctrine\ORM\Event\PreUpdateEventArgs           $args
119
     * @param Knp\RadBundle\Security\RecoverableUserInterface $entity
120
     */
121
    function its_preUpdate_should_erase_password_recovery_key_for_recoverable_user($args, $entity)
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::its_preUpdate_should_erase_password_recovery_key_for_recoverable_user" is not in camel caps format
Loading history...
122
    {
123
        $args->getEntity()->willReturn($entity);
124
        $args->setNewValue('password', 'custom_pass#some_salt')->shouldBeCalled();
125
126
        $entity->getPlainPassword()->willReturn('custom_pass');
127
        $entity->getSalt()->willReturn('some_salt');
128
        $entity->getPassword()->willReturn('custom_pass#some_salt');
129
130
        $entity->setPassword('custom_pass#some_salt')->shouldBeCalled();
131
        $entity->eraseCredentials()->shouldBeCalled();
132
        $entity->erasePasswordRecoveryKey()->shouldBeCalled();
133
134
        $this->preUpdate($args);
135
    }
136
137
    /**
138
     * @param Doctrine\ORM\Event\PreUpdateEventArgs $args
139
     * @param Knp\RadBundle\Security\UserInterface  $entity
140
     */
141
    function its_preUpdate_should_not_touch_entity_if_password_is_not_updated($args, $entity)
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::its_preUpdate_should_not_touch_entity_if_password_is_not_updated" is not in camel caps format
Loading history...
142
    {
143
        $args->getEntity()->willReturn($entity);
144
        $args->getEntityManager()->shouldNotBeCalled();
145
146
        $entity->getPlainPassword()->willReturn(null);
147
        $entity->setPassword(\Prophecy\Argument::any())->shouldNotBeCalled();
148
149
        $this->preUpdate($args);
150
    }
151
152
    /**
153
     * @param Doctrine\ORM\Event\PreUpdateEventArgs $args
154
     * @param stdClass                              $entity
155
     */
156
    function its_preUpdate_should_not_touch_entities_without_interface($args, $entity)
0 ignored issues
show
Coding Style introduced by
Method name "PasswordHashListenerSpec::its_preUpdate_should_not_touch_entities_without_interface" is not in camel caps format
Loading history...
157
    {
158
        $args->getEntity()->willReturn($entity);
159
160
        $this->preUpdate($args);
161
    }
162
}
163