RegisterUserTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 183
Duplicated Lines 53.55 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 98
loc 183
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testRegisterNewUserWithCredentials_() 26 26 1
A testRegisterNewUserUsingGetVerb() 0 18 1
A testRegisterExistingUser() 0 27 1
A testRegisterNewUserWithoutEmail() 18 18 1
A testRegisterNewUserWithoutName() 18 18 1
A testRegisterNewUserWithoutPassword() 17 17 1
A testRegisterNewUserWithInvalidEmail() 19 19 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Containers\User\UI\API\Tests\Functional;
4
5
use App\Containers\User\Tests\ApiTestCase;
6
7
/**
8
 * Class RegisterUserTest.
9
 *
10
 * @group user
11
 * @group api
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class RegisterUserTest extends ApiTestCase
16
{
17
18
    protected $endpoint = '[email protected]/register';
19
20
    protected $auth = false;
21
22
    protected $access = [
23
        'roles'       => '',
24
        'permissions' => '',
25
    ];
26
27
    /**
28
     * @test
29
     */
30 View Code Duplication
    public function testRegisterNewUserWithCredentials_()
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
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...
31
    {
32
        $data = [
33
            'email'    => '[email protected]',
34
            'name'     => 'Apiato',
35
            'password' => 'secretpass',
36
        ];
37
38
        // send the HTTP request
39
        $response = $this->makeCall($data);
40
41
        // assert response status is correct
42
        $response->assertStatus(200);
43
44
        $this->assertResponseContainKeyValue([
45
            'email' => $data['email'],
46
            'name'  => $data['name'],
47
        ]);
48
49
        $responseContent = $this->getResponseContentObject();
50
51
        $this->assertNotEmpty($responseContent->data);
52
53
         // assert the data is stored in the database
54
        $this->assertDatabaseHas('users', ['email' => $data['email']]);
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function testRegisterNewUserUsingGetVerb()
61
    {
62
        $data = [
63
            'email'    => '[email protected]',
64
            'name'     => 'Apiato',
65
            'password' => 'secret',
66
        ];
67
68
        // send the HTTP request
69
        $response = $this->endpoint('[email protected]/register')->makeCall($data);
70
71
        // assert response status is correct
72
        $response->assertStatus(405);
73
74
        $this->assertResponseContainKeyValue([
75
            'errors' => 'Method Not Allowed!',
76
        ]);
77
    }
78
79
    /**
80
     * @test
81
     */
82
    public function testRegisterExistingUser()
83
    {
84
        $userDetails = [
85
            'email'    => '[email protected]',
86
            'name'     => 'Apiato',
87
            'password' => 'secret',
88
        ];
89
90
        // get the logged in user (create one if no one is logged in)
91
        $this->getTestingUser($userDetails);
92
93
        $data = [
94
            'email'    => $userDetails['email'],
95
            'name'     => $userDetails['name'],
96
            'password' => $userDetails['password'],
97
        ];
98
99
        // send the HTTP request
100
        $response = $this->makeCall($data);
101
102
        // assert response status is correct
103
        $response->assertStatus(422);
104
105
        $this->assertValidationErrorContain([
106
            'email' => 'The email has already been taken.',
107
        ]);
108
    }
109
110
    /**
111
     * @test
112
     */
113 View Code Duplication
    public function testRegisterNewUserWithoutEmail()
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
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...
114
    {
115
        $data = [
116
            'name'     => 'Apiato',
117
            'password' => 'secret',
118
        ];
119
120
        // send the HTTP request
121
        $response = $this->makeCall($data);
122
123
        // assert response status is correct
124
        $response->assertStatus(422);
125
126
        // assert response contain the correct message
127
        $this->assertValidationErrorContain([
128
            'email' => 'The email field is required.',
129
        ]);
130
    }
131
132
    /**
133
     * @test
134
     */
135 View Code Duplication
    public function testRegisterNewUserWithoutName()
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
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...
136
    {
137
        $data = [
138
            'email'    => '[email protected]',
139
            'password' => 'secret',
140
        ];
141
142
        // send the HTTP request
143
        $response = $this->makeCall($data);
144
145
        // assert response status is correct
146
        $response->assertStatus(422);
147
148
        // assert response contain the correct message
149
        $this->assertValidationErrorContain([
150
            'name' => 'The name field is required.',
151
        ]);
152
    }
153
154
    /**
155
     * @test
156
     */
157 View Code Duplication
    public function testRegisterNewUserWithoutPassword()
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
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...
158
    {
159
        $data = [
160
            'email' => '[email protected]',
161
            'name'  => 'Apiato',
162
        ];
163
164
        $response = $this->makeCall($data);
165
166
        // assert response status is correct
167
        $response->assertStatus(422);
168
169
        // assert response contain the correct message
170
        $this->assertValidationErrorContain([
171
            'password' => 'The password field is required.',
172
        ]);
173
    }
174
175
    /**
176
     * @test
177
     */
178 View Code Duplication
    public function testRegisterNewUserWithInvalidEmail()
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
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...
179
    {
180
        $data = [
181
            'email'    => 'missing-at.dev',
182
            'name'     => 'Apiato',
183
            'password' => 'secret',
184
        ];
185
186
        // send the HTTP request
187
        $response = $this->makeCall($data);
188
189
        // assert response status is correct
190
        $response->assertStatus(422);
191
192
        // assert response contain the correct message
193
        $this->assertValidationErrorContain([
194
            'email' => 'The email must be a valid email address.',
195
        ]);
196
    }
197
}
198