Completed
Pull Request — master (#329)
by Beñat
03:55
created

UserPublicDTODataTransformerSpec::it_transforms()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 36

Duplication

Lines 45
Ratio 100 %

Importance

Changes 0
Metric Value
dl 45
loc 45
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 36
nc 1
nop 7
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\Application\DataTransformer\UserDataTransformer;
19
use BenGorUser\User\Domain\Model\UserEmail;
20
use BenGorUser\User\Domain\Model\UserId;
21
use Kreta\IdentityAccess\Application\DataTransformer\UserPublicDTODataTransformer;
22
use Kreta\IdentityAccess\Domain\Model\User\FullName;
23
use Kreta\IdentityAccess\Domain\Model\User\Image;
24
use Kreta\IdentityAccess\Domain\Model\User\User;
25
use Kreta\IdentityAccess\Domain\Model\User\Username;
26
use PhpSpec\ObjectBehavior;
27
28
class UserPublicDTODataTransformerSpec extends ObjectBehavior
29
{
30
    function it_is_initializable()
31
    {
32
        $this->shouldHaveType(UserPublicDTODataTransformer::class);
33
    }
34
35
    function it_implements_user_data_transformer()
36
    {
37
        $this->shouldImplement(UserDataTransformer::class);
38
    }
39
40 View Code Duplication
    function it_transforms(
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...
41
        User $user,
42
        \DateTimeImmutable $createdOn,
43
        \DateTimeImmutable $lastLogin,
44
        \DateTimeImmutable $updatedOn,
45
        FullName $fullName,
46
        Username $username,
47
        Image $image
48
    ) {
49
        $this->read()->shouldReturn([]);
50
51
        $this->write($user);
52
53
        $user->id()->shouldBeCalled()->willReturn(new UserId('user-id'));
54
        $user->createdOn()->shouldBeCalled()->willReturn($createdOn);
55
        $user->email()->shouldBeCalled()->willReturn(new UserEmail('[email protected]'));
56
        $user->lastLogin()->shouldBeCalled()->willReturn($lastLogin);
57
        $user->updatedOn()->shouldBeCalled()->willReturn($updatedOn);
58
59
        $user->username()->shouldBeCalled()->willReturn($username);
60
        $username->username()->shouldBeCalled()->willReturn('user11111');
61
62
        $user->fullName()->shouldBeCalled()->willReturn($fullName);
63
        $fullName->firstName()->shouldBeCalled()->willReturn('The user first name');
64
        $fullName->lastName()->shouldBeCalled()->willReturn('The user last name');
65
        $fullName->fullName()->shouldBeCalled()->willReturn('The user first name The user last name');
66
67
        $user->image()->shouldBeCalled()->willReturn($image);
68
        $imageName = new FileName('image-name.png');
69
        $image->name()->shouldBeCalled()->willReturn($imageName);
70
71
        $this->read()->shouldReturn([
72
            'id'                      => 'user-id',
73
            'user_id'                 => 'user-id',
74
            'created_on'              => $createdOn,
75
            'email'                   => '[email protected]',
76
            'first_name'              => 'The user first name',
77
            'full_name'               => 'The user first name The user last name',
78
            'last_login'              => $lastLogin,
79
            'last_name'               => 'The user last name',
80
            'image'                   => '/image-name.png',
81
            'updated_on'              => $updatedOn,
82
            'user_name'               => 'user11111',
83
        ]);
84
    }
85
86 View Code Duplication
    function it_transforms_with_other_upload_destination(
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...
87
        User $user,
88
        \DateTimeImmutable $createdOn,
89
        \DateTimeImmutable $lastLogin,
90
        \DateTimeImmutable $updatedOn,
91
        FullName $fullName,
92
        Username $username,
93
        Image $image
94
    ) {
95
        $this->beConstructedWith('/other-upload-destination');
96
97
        $this->read()->shouldReturn([]);
98
99
        $this->write($user);
100
101
        $user->id()->shouldBeCalled()->willReturn(new UserId('user-id'));
102
        $user->createdOn()->shouldBeCalled()->willReturn($createdOn);
103
        $user->email()->shouldBeCalled()->willReturn(new UserEmail('[email protected]'));
104
        $user->lastLogin()->shouldBeCalled()->willReturn($lastLogin);
105
        $user->updatedOn()->shouldBeCalled()->willReturn($updatedOn);
106
107
        $user->username()->shouldBeCalled()->willReturn($username);
108
        $username->username()->shouldBeCalled()->willReturn('user11111');
109
110
        $user->fullName()->shouldBeCalled()->willReturn($fullName);
111
        $fullName->firstName()->shouldBeCalled()->willReturn('The user first name');
112
        $fullName->lastName()->shouldBeCalled()->willReturn('The user last name');
113
        $fullName->fullName()->shouldBeCalled()->willReturn('The user first name The user last name');
114
115
        $user->image()->shouldBeCalled()->willReturn($image);
116
        $imageName = new FileName('image-name.png');
117
        $image->name()->shouldBeCalled()->willReturn($imageName);
118
119
        $this->read()->shouldReturn([
120
            'id'                      => 'user-id',
121
            'user_id'                 => 'user-id',
122
            'created_on'              => $createdOn,
123
            'email'                   => '[email protected]',
124
            'first_name'              => 'The user first name',
125
            'full_name'               => 'The user first name The user last name',
126
            'last_login'              => $lastLogin,
127
            'last_name'               => 'The user last name',
128
            'image'                   => '/other-upload-destination/image-name.png',
129
            'updated_on'              => $updatedOn,
130
            'user_name'               => 'user11111',
131
        ]);
132
    }
133
}
134