1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 10/1/17 |
7
|
|
|
* Time: 1:11 PM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Entity\Traits; |
11
|
|
|
|
12
|
|
|
use Tfboe\FmLib\Entity\UserInterface; |
13
|
|
|
use Tfboe\FmLib\Tests\Entity\User; |
14
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class UserTest |
18
|
|
|
* @package Tfboe\FmLib\Tests\Unit\Entity |
19
|
|
|
*/ |
20
|
|
|
class UserTest extends UnitTestCase |
21
|
|
|
{ |
22
|
|
|
//<editor-fold desc="Public Methods"> |
23
|
|
|
/** |
24
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::init |
25
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::getJWTCustomClaims |
26
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::getJwtVersion |
27
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::getConfirmedAGBVersion |
28
|
|
|
*/ |
29
|
|
|
public function testConstructor() |
30
|
|
|
{ |
31
|
|
|
$user = $this->user(); |
32
|
|
|
self::assertInstanceOf(User::class, $user); |
33
|
|
|
self::assertEquals(['ver' => 1], $user->getJWTCustomClaims()); |
34
|
|
|
self::assertEquals(1, $user->getJwtVersion()); |
35
|
|
|
self::assertEquals(0, $user->getConfirmedAGBVersion()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::setEmail |
40
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::getEmail |
41
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::init |
42
|
|
|
*/ |
43
|
|
|
public function testEmail() |
44
|
|
|
{ |
45
|
|
|
$user = $this->user(); |
46
|
|
|
$user->setEmail("[email protected]"); |
47
|
|
|
self::assertEquals("[email protected]", $user->getEmail()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::getJWTCustomClaims |
52
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::setJwtVersion |
53
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::init |
54
|
|
|
*/ |
55
|
|
|
public function testJWTCustomClaims() |
56
|
|
|
{ |
57
|
|
|
$user = $this->user(); |
58
|
|
|
$user->setJwtVersion(5); |
59
|
|
|
self::assertEquals(['ver' => 5], $user->getJWTCustomClaims()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::getJWTIdentifier |
64
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::init |
65
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getId |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function testJWTIdentifier() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$user = $this->user(); |
70
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
71
|
|
|
self::getProperty(get_class($user), 'id')->setValue($user, 'user-id'); |
72
|
|
|
self::assertEquals('user-id', $user->getJWTIdentifier()); |
73
|
|
|
self::assertEquals($user->getId(), $user->getJWTIdentifier()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::getJwtVersion() |
78
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::setJwtVersion |
79
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::init |
80
|
|
|
*/ |
81
|
|
|
public function testJwtVersion() |
82
|
|
|
{ |
83
|
|
|
$user = $this->user(); |
84
|
|
|
$user->setJwtVersion(5); |
85
|
|
|
self::assertEquals(5, $user->getJwtVersion()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::getConfirmedAGBVersion |
90
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\User::setConfirmedAGBVersion |
91
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\User::init |
92
|
|
|
*/ |
93
|
|
|
public function testLastConfirmedAGBVersion() |
94
|
|
|
{ |
95
|
|
|
$user = $this->user(); |
96
|
|
|
$user->setConfirmedAGBVersion(5); |
97
|
|
|
self::assertEquals(5, $user->getConfirmedAGBVersion()); |
98
|
|
|
} |
99
|
|
|
//</editor-fold desc="Public Methods"> |
100
|
|
|
|
101
|
|
|
//<editor-fold desc="Private Methods"> |
102
|
|
|
/** |
103
|
|
|
* @return UserInterface a new user |
104
|
|
|
*/ |
105
|
|
|
private function user(): UserInterface |
106
|
|
|
{ |
107
|
|
|
return new User(); |
108
|
|
|
} |
109
|
|
|
//</editor-fold desc="Private Methods"> |
110
|
|
|
} |
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.