SymfonyUserPasswordEncoderSpec   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 39
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_user_password_encoder() 0 4 1
A it_encodes() 0 8 1
A it_checks_password_is_valid() 0 12 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace spec\BenGorUser\SymfonySecurityBridge\Infrastructure\Security;
14
15
use BenGorUser\SymfonySecurityBridge\Infrastructure\Security\SymfonyUserPasswordEncoder;
16
use BenGorUser\User\Domain\Model\UserPassword;
17
use BenGorUser\User\Domain\Model\UserPasswordEncoder;
18
use PhpSpec\ObjectBehavior;
19
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
20
21
/**
22
 * Spec file of SymfonyUserPassword class.
23
 *
24
 * @author Beñat Espiña <[email protected]>
25
 */
26
class SymfonyUserPasswordEncoderSpec extends ObjectBehavior
27
{
28
    function let(PasswordEncoderInterface $passwordEncoder)
29
    {
30
        $this->beConstructedWith($passwordEncoder);
31
    }
32
33
    function it_is_initializable()
34
    {
35
        $this->shouldHaveType(SymfonyUserPasswordEncoder::class);
36
    }
37
38
    function it_implements_user_password_encoder()
39
    {
40
        $this->shouldImplement(UserPasswordEncoder::class);
41
    }
42
43
    function it_encodes(PasswordEncoderInterface $passwordEncoder)
44
    {
45
        $passwordEncoder->encodePassword(
46
            'plain-password', 'dummy-salt'
47
        )->shouldBeCalled()->willReturn('encoded-password');
48
49
        $this->encode('plain-password', 'dummy-salt')->shouldReturn('encoded-password');
50
    }
51
52
    function it_checks_password_is_valid(PasswordEncoderInterface $passwordEncoder)
53
    {
54
        $password = UserPassword::fromEncoded(
55
            'encoded-password',
56
            'dummy-salt'
57
        );
58
        $passwordEncoder->isPasswordValid(
59
            'encoded-password', 'plain-password', 'dummy-salt'
60
        )->shouldBeCalled()->willReturn(true);
61
62
        $this->isPasswordValid($password, 'plain-password')->shouldReturn(true);
63
    }
64
}
65