|
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
|
|
|
namespace Spec\Kreta\IdentityAccess\Application\DataTransformer; |
|
14
|
|
|
|
|
15
|
|
|
use BenGorUser\User\Domain\Model\UserEmail; |
|
16
|
|
|
use BenGorUser\User\Domain\Model\UserId; |
|
17
|
|
|
use BenGorUser\User\Domain\Model\UserPassword; |
|
18
|
|
|
use BenGorUser\User\Domain\Model\UserRole; |
|
19
|
|
|
use Kreta\IdentityAccess\Application\DataTransformer\UserDTODataTransformer; |
|
20
|
|
|
use Kreta\IdentityAccess\Domain\Model\User\FullName; |
|
21
|
|
|
use Kreta\IdentityAccess\Domain\Model\User\User; |
|
22
|
|
|
use Kreta\IdentityAccess\Domain\Model\User\Username; |
|
23
|
|
|
use PhpSpec\ObjectBehavior; |
|
24
|
|
|
|
|
25
|
|
|
class UserDTODataTransformerSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
function it_is_initializable() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->shouldHaveType(UserDTODataTransformer::class); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function it_extends_bengor_user_user_dto_data_transformer() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->shouldHaveType(\BenGorUser\User\Application\DataTransformer\UserDTODataTransformer::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
function it_transforms( |
|
38
|
|
|
User $user, |
|
39
|
|
|
\DateTimeImmutable $createdOn, |
|
40
|
|
|
\DateTimeImmutable $lastLogin, |
|
41
|
|
|
\DateTimeImmutable $updatedOn, |
|
42
|
|
|
FullName $fullName, |
|
43
|
|
|
Username $username |
|
44
|
|
|
) { |
|
45
|
|
|
$this->read()->shouldReturn([]); |
|
46
|
|
|
|
|
47
|
|
|
$this->write($user); |
|
48
|
|
|
|
|
49
|
|
|
$user->roles()->shouldBeCalled()->willReturn([new UserRole('ROLE_USER')]); |
|
50
|
|
|
|
|
51
|
|
|
$password = UserPassword::fromEncoded('encoded-password', 'user-password-salt'); |
|
52
|
|
|
|
|
53
|
|
|
$user->id()->shouldBeCalled()->willReturn(new UserId('user-id')); |
|
54
|
|
|
$user->confirmationToken()->shouldBeCalled()->willReturn(null); |
|
55
|
|
|
$user->createdOn()->shouldBeCalled()->willReturn($createdOn); |
|
56
|
|
|
$user->email()->shouldBeCalled()->willReturn(new UserEmail('[email protected]')); |
|
57
|
|
|
$user->invitationToken()->shouldBeCalled()->willReturn(null); |
|
58
|
|
|
$user->lastLogin()->shouldBeCalled()->willReturn($lastLogin); |
|
59
|
|
|
$user->password()->shouldBeCalled()->willReturn($password); |
|
60
|
|
|
$user->rememberPasswordToken()->shouldBeCalled()->willReturn(null); |
|
61
|
|
|
$user->updatedOn()->shouldBeCalled()->willReturn($updatedOn); |
|
62
|
|
|
|
|
63
|
|
|
$user->username()->shouldBeCalled()->willReturn($username); |
|
64
|
|
|
$username->username()->shouldBeCalled()->willReturn('user11111'); |
|
65
|
|
|
|
|
66
|
|
|
$user->fullName()->shouldBeCalled()->willReturn($fullName); |
|
67
|
|
|
$fullName->firstName()->shouldBeCalled()->willReturn('The user first name'); |
|
68
|
|
|
$fullName->lastName()->shouldBeCalled()->willReturn('The user last name'); |
|
69
|
|
|
$fullName->fullName()->shouldBeCalled()->willReturn('The user first name The user last name'); |
|
70
|
|
|
|
|
71
|
|
|
$this->read()->shouldReturn([ |
|
72
|
|
|
'id' => 'user-id', |
|
73
|
|
|
'confirmation_token' => null, |
|
74
|
|
|
'created_on' => $createdOn, |
|
75
|
|
|
'email' => '[email protected]', |
|
76
|
|
|
'invitation_token' => null, |
|
77
|
|
|
'last_login' => $lastLogin, |
|
78
|
|
|
'encoded_password' => 'encoded-password', |
|
79
|
|
|
'salt' => 'user-password-salt', |
|
80
|
|
|
'remember_password_token' => null, |
|
81
|
|
|
'roles' => ['ROLE_USER'], |
|
82
|
|
|
'updated_on' => $updatedOn, |
|
83
|
|
|
'user_name' => 'user11111', |
|
84
|
|
|
'first_name' => 'The user first name', |
|
85
|
|
|
'last_name' => 'The user last name', |
|
86
|
|
|
'full_name' => 'The user first name The user last name', |
|
87
|
|
|
]); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|