Completed
Push — scalar-types/user ( 04f6b1 )
by Kamil
23:44
created

UserSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\User\Model;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\User\Model\User;
18
use Sylius\Component\User\Model\UserInterface;
19
20
/**
21
 * @author Alexandre Bacco <[email protected]>
22
 * @author Bartosz Siejka <[email protected]>
23
 */
24
final class UserSpec extends ObjectBehavior
25
{
26
    function it_implements_user_interface(): void
27
    {
28
        $this->shouldImplement(UserInterface::class);
29
    }
30
31
    function its_not_verified_by_default(): void
32
    {
33
        $this->isVerified()->shouldReturn(false);
34
    }
35
36
    function its_verified_at_date_is_mutable(\DateTime $date): void
37
    {
38
        $this->setVerifiedAt($date);
39
40
        $this->getVerifiedAt()->shouldReturn($date);
41
    }
42
43
    function its_verified_when_verified_at_is_not_empty(\DateTime $date): void
44
    {
45
        $this->setVerifiedAt($date);
46
47
        $this->isVerified()->shouldReturn(true);
48
    }
49
50
    function it_has_no_password_requested_at_date_by_default(): void
51
    {
52
        $this->getPasswordRequestedAt()->shouldReturn(null);
53
    }
54
55
    function its_password_requested_at_date_is_mutable(): void
56
    {
57
        $date = new \DateTime();
58
        $this->setPasswordRequestedAt($date);
59
60
        $this->getPasswordRequestedAt()->shouldReturn($date);
61
    }
62
63
    function it_should_return_true_if_password_request_is_non_expired(): void
64
    {
65
        $passwordRequestedAt = new \DateTime('-1 hour');
66
        $this->setPasswordRequestedAt($passwordRequestedAt);
67
        $ttl = new \DateInterval('P1D');
68
69
        $this->isPasswordRequestNonExpired($ttl)->shouldReturn(true);
70
    }
71
72
    function it_should_return_false_if_password_request_is_expired(): void
73
    {
74
        $passwordRequestedAt = new \DateTime('-2 hour');
75
        $this->setPasswordRequestedAt($passwordRequestedAt);
76
        $ttl = new \DateInterval('PT1H');
77
78
        $this->isPasswordRequestNonExpired($ttl)->shouldReturn(false);
79
    }
80
81
    function it_has_email_and_email_canonical(): void
82
    {
83
        $this->setEmail('[email protected]');
84
        $this->setEmailCanonical('[email protected]');
85
86
        $this->getEmail()->shouldReturn('[email protected]');
87
        $this->getEmailCanonical()->shouldReturn('[email protected]');
88
    }
89
}
90