Completed
Push — master ( efde7d...b6dd08 )
by Alexis
07:32
created

UserTest::testConfirmationToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace AWurth\SilexUser\Tests\Entity;
4
5
use AWurth\SilexUser\Entity\User;
6
use PHPUnit\Framework\TestCase;
7
8
class UserTest extends TestCase
9
{
10
    /**
11
     * @var User
12
     */
13
    protected $user;
14
15
    public function setUp()
16
    {
17
        $this->user = $this->getMockForAbstractClass(User::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...ser\Entity\User::class) of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<AWurth\SilexUser\Entity\User> of property $user.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
18
    }
19
    
20
    public function testUsername()
21
    {
22
        $this->assertNull($this->user->getUsername());
23
24
        $this->user->setUsername('awurth');
25
        $this->assertSame('awurth', $this->user->getUsername());
26
    }
27
28
    public function testEmail()
29
    {
30
        $this->assertNull($this->user->getEmail());
31
32
        $this->user->setEmail('[email protected]');
33
        $this->assertSame('[email protected]', $this->user->getEmail());
34
    }
35
36
    public function testPassword()
37
    {
38
        $this->assertNull($this->user->getPassword());
39
40
        $this->user->setPassword('my_password');
41
        $this->assertSame('my_password', $this->user->getPassword());
42
    }
43
44
    public function testPlainPassword()
45
    {
46
        $this->assertNull($this->user->getPlainPassword());
47
48
        $this->user->setPlainPassword('my_plain_password');
49
        $this->assertSame('my_plain_password', $this->user->getPlainPassword());
50
    }
51
52 View Code Duplication
    public function testSalt()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $this->assertNull($this->user->getSalt());
55
56
        $salt = rtrim(str_replace('+', '.', base64_encode(random_bytes(32))), '=');
57
58
        $this->user->setSalt($salt);
59
        $this->assertSame($salt, $this->user->getSalt());
60
    }
61
62
    public function testEnabled()
63
    {
64
        $this->assertFalse($this->user->isEnabled());
65
66
        $this->user->setEnabled(true);
67
        $this->assertTrue($this->user->isEnabled());
68
    }
69
70 View Code Duplication
    public function testConfirmationToken()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $this->assertNull($this->user->getConfirmationToken());
73
74
        $token = rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '=');
75
76
        $this->user->setConfirmationToken($token);
77
        $this->assertSame($token, $this->user->getConfirmationToken());
78
    }
79
80
    public function testRoles()
81
    {
82
        $this->assertSame([User::ROLE_DEFAULT], $this->user->getRoles());
83
84
        $this->user->setRoles(['ROLE_ADMIN', 'ROLE_SUPER_ADMIN']);
85
        $this->assertSame(['ROLE_ADMIN', 'ROLE_SUPER_ADMIN', User::ROLE_DEFAULT], $this->user->getRoles());
86
    }
87
    
88
    public function testHasRole()
89
    {
90
        $defaultRole = User::ROLE_DEFAULT;
91
        $newRole = 'ROLE_ADMIN';
92
        $this->assertTrue($this->user->hasRole($defaultRole));
93
        $this->assertFalse($this->user->hasRole($newRole));
94
95
        $this->user->addRole($defaultRole);
96
        $this->assertTrue($this->user->hasRole($defaultRole));
97
        $this->user->addRole($newRole);
98
        $this->assertTrue($this->user->hasRole($newRole));
99
100
        $this->user->removeRole($defaultRole);
101
        $this->assertTrue($this->user->hasRole($defaultRole));
102
        $this->user->removeRole($newRole);
103
        $this->assertFalse($this->user->hasRole($newRole));
104
    }
105
}
106