1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Kreta 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
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace Spec\Kreta\IdentityAccess\Application\DataTransformer; |
16
|
|
|
|
17
|
|
|
use BenGorFile\File\Domain\Model\FileName; |
18
|
|
|
use BenGorUser\User\Domain\Model\UserEmail; |
19
|
|
|
use BenGorUser\User\Domain\Model\UserId; |
20
|
|
|
use BenGorUser\User\Domain\Model\UserPassword; |
21
|
|
|
use BenGorUser\User\Domain\Model\UserRole; |
22
|
|
|
use Kreta\IdentityAccess\Application\DataTransformer\UserDTODataTransformer; |
23
|
|
|
use Kreta\IdentityAccess\Domain\Model\User\FullName; |
24
|
|
|
use Kreta\IdentityAccess\Domain\Model\User\Image; |
25
|
|
|
use Kreta\IdentityAccess\Domain\Model\User\User; |
26
|
|
|
use Kreta\IdentityAccess\Domain\Model\User\Username; |
27
|
|
|
use PhpSpec\ObjectBehavior; |
28
|
|
|
|
29
|
|
|
class UserDTODataTransformerSpec extends ObjectBehavior |
30
|
|
|
{ |
31
|
|
|
function it_is_initializable() |
32
|
|
|
{ |
33
|
|
|
$this->shouldHaveType(UserDTODataTransformer::class); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_extends_bengor_user_user_dto_data_transformer() |
37
|
|
|
{ |
38
|
|
|
$this->shouldHaveType(\BenGorUser\User\Application\DataTransformer\UserDTODataTransformer::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
function it_transforms( |
|
|
|
|
42
|
|
|
User $user, |
43
|
|
|
\DateTimeImmutable $createdOn, |
44
|
|
|
\DateTimeImmutable $lastLogin, |
45
|
|
|
\DateTimeImmutable $updatedOn, |
46
|
|
|
FullName $fullName, |
47
|
|
|
Username $username, |
48
|
|
|
Image $image |
49
|
|
|
) { |
50
|
|
|
$this->read()->shouldReturn([]); |
51
|
|
|
|
52
|
|
|
$this->write($user); |
53
|
|
|
|
54
|
|
|
$user->roles()->shouldBeCalled()->willReturn([new UserRole('ROLE_USER')]); |
55
|
|
|
|
56
|
|
|
$password = UserPassword::fromEncoded('encoded-password', 'user-password-salt'); |
57
|
|
|
|
58
|
|
|
$user->id()->shouldBeCalled()->willReturn(new UserId('user-id')); |
59
|
|
|
$user->confirmationToken()->shouldBeCalled()->willReturn(null); |
60
|
|
|
$user->createdOn()->shouldBeCalled()->willReturn($createdOn); |
61
|
|
|
$user->email()->shouldBeCalled()->willReturn(new UserEmail('[email protected]')); |
62
|
|
|
$user->invitationToken()->shouldBeCalled()->willReturn(null); |
63
|
|
|
$user->lastLogin()->shouldBeCalled()->willReturn($lastLogin); |
64
|
|
|
$user->password()->shouldBeCalled()->willReturn($password); |
65
|
|
|
$user->rememberPasswordToken()->shouldBeCalled()->willReturn(null); |
66
|
|
|
$user->updatedOn()->shouldBeCalled()->willReturn($updatedOn); |
67
|
|
|
|
68
|
|
|
$user->username()->shouldBeCalled()->willReturn($username); |
69
|
|
|
$username->username()->shouldBeCalled()->willReturn('user11111'); |
70
|
|
|
|
71
|
|
|
$user->fullName()->shouldBeCalled()->willReturn($fullName); |
72
|
|
|
$fullName->firstName()->shouldBeCalled()->willReturn('The user first name'); |
73
|
|
|
$fullName->lastName()->shouldBeCalled()->willReturn('The user last name'); |
74
|
|
|
$fullName->fullName()->shouldBeCalled()->willReturn('The user first name The user last name'); |
75
|
|
|
|
76
|
|
|
$user->image()->shouldBeCalled()->willReturn($image); |
77
|
|
|
$imageName = new FileName('image-name.png'); |
78
|
|
|
$image->name()->shouldBeCalled()->willReturn($imageName); |
79
|
|
|
|
80
|
|
|
$this->read()->shouldReturn([ |
81
|
|
|
'id' => 'user-id', |
82
|
|
|
'confirmation_token' => null, |
83
|
|
|
'created_on' => $createdOn, |
84
|
|
|
'email' => '[email protected]', |
85
|
|
|
'invitation_token' => null, |
86
|
|
|
'last_login' => $lastLogin, |
87
|
|
|
'encoded_password' => 'encoded-password', |
88
|
|
|
'salt' => 'user-password-salt', |
89
|
|
|
'remember_password_token' => null, |
90
|
|
|
'roles' => ['ROLE_USER'], |
91
|
|
|
'updated_on' => $updatedOn, |
92
|
|
|
'user_id' => 'user-id', |
93
|
|
|
'user_name' => 'user11111', |
94
|
|
|
'first_name' => 'The user first name', |
95
|
|
|
'last_name' => 'The user last name', |
96
|
|
|
'full_name' => 'The user first name The user last name', |
97
|
|
|
'image' => '/image-name.png', |
98
|
|
|
]); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
View Code Duplication |
function it_transforms_with_other_upload_destination( |
|
|
|
|
102
|
|
|
User $user, |
103
|
|
|
\DateTimeImmutable $createdOn, |
104
|
|
|
\DateTimeImmutable $lastLogin, |
105
|
|
|
\DateTimeImmutable $updatedOn, |
106
|
|
|
FullName $fullName, |
107
|
|
|
Username $username, |
108
|
|
|
Image $image |
109
|
|
|
) { |
110
|
|
|
$this->beConstructedWith('/other-upload-destination'); |
111
|
|
|
|
112
|
|
|
$this->read()->shouldReturn([]); |
113
|
|
|
|
114
|
|
|
$this->write($user); |
115
|
|
|
|
116
|
|
|
$user->roles()->shouldBeCalled()->willReturn([new UserRole('ROLE_USER')]); |
117
|
|
|
|
118
|
|
|
$password = UserPassword::fromEncoded('encoded-password', 'user-password-salt'); |
119
|
|
|
|
120
|
|
|
$user->id()->shouldBeCalled()->willReturn(new UserId('user-id')); |
121
|
|
|
$user->confirmationToken()->shouldBeCalled()->willReturn(null); |
122
|
|
|
$user->createdOn()->shouldBeCalled()->willReturn($createdOn); |
123
|
|
|
$user->email()->shouldBeCalled()->willReturn(new UserEmail('[email protected]')); |
124
|
|
|
$user->invitationToken()->shouldBeCalled()->willReturn(null); |
125
|
|
|
$user->lastLogin()->shouldBeCalled()->willReturn($lastLogin); |
126
|
|
|
$user->password()->shouldBeCalled()->willReturn($password); |
127
|
|
|
$user->rememberPasswordToken()->shouldBeCalled()->willReturn(null); |
128
|
|
|
$user->updatedOn()->shouldBeCalled()->willReturn($updatedOn); |
129
|
|
|
|
130
|
|
|
$user->username()->shouldBeCalled()->willReturn($username); |
131
|
|
|
$username->username()->shouldBeCalled()->willReturn('user11111'); |
132
|
|
|
|
133
|
|
|
$user->fullName()->shouldBeCalled()->willReturn($fullName); |
134
|
|
|
$fullName->firstName()->shouldBeCalled()->willReturn('The user first name'); |
135
|
|
|
$fullName->lastName()->shouldBeCalled()->willReturn('The user last name'); |
136
|
|
|
$fullName->fullName()->shouldBeCalled()->willReturn('The user first name The user last name'); |
137
|
|
|
|
138
|
|
|
$user->image()->shouldBeCalled()->willReturn($image); |
139
|
|
|
$imageName = new FileName('image-name.png'); |
140
|
|
|
$image->name()->shouldBeCalled()->willReturn($imageName); |
141
|
|
|
|
142
|
|
|
$this->read()->shouldReturn([ |
143
|
|
|
'id' => 'user-id', |
144
|
|
|
'confirmation_token' => null, |
145
|
|
|
'created_on' => $createdOn, |
146
|
|
|
'email' => '[email protected]', |
147
|
|
|
'invitation_token' => null, |
148
|
|
|
'last_login' => $lastLogin, |
149
|
|
|
'encoded_password' => 'encoded-password', |
150
|
|
|
'salt' => 'user-password-salt', |
151
|
|
|
'remember_password_token' => null, |
152
|
|
|
'roles' => ['ROLE_USER'], |
153
|
|
|
'updated_on' => $updatedOn, |
154
|
|
|
'user_id' => 'user-id', |
155
|
|
|
'user_name' => 'user11111', |
156
|
|
|
'first_name' => 'The user first name', |
157
|
|
|
'last_name' => 'The user last name', |
158
|
|
|
'full_name' => 'The user first name The user last name', |
159
|
|
|
'image' => '/other-upload-destination/image-name.png', |
160
|
|
|
]); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
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.