SymfonyUserPasswordEncoderSpec::let()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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