Completed
Push — master ( 7ff671...be21d3 )
by Mahmoud
03:25
created

UpdateUserTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 61.9 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 39
loc 63
rs 10
c 3
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testUpdateExistingUser_() 24 24 1
A testUpdateExistingUserWithoutData_() 0 10 1
A testUpdateExistingUserWithEmptyValues() 15 15 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\TestCase;
6
7
/**
8
 * Class UpdateUserTest.
9
 *
10
 * @author Mahmoud Zalt <[email protected]>
11
 */
12
class UpdateUserTest extends TestCase
13
{
14
15
    protected $endpoint = 'put@users';
16
17
    protected $access = [
18
        'roles'       => '',
19
        'permissions' => 'update-users',
20
    ];
21
22 View Code Duplication
    public function testUpdateExistingUser_()
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...
23
    {
24
        $user = $this->getTestingUser();
25
26
        $data = [
27
            'name'     => 'Updated Name',
28
            'password' => 'updated#Password',
29
        ];
30
31
        // send the HTTP request
32
        $response = $this->makeCall($data);
33
34
        // assert response status is correct
35
        $this->assertEquals('200', $response->getStatusCode());
36
37
        // assert returned user is the updated one
38
        $this->assertResponseContainKeyValue([
39
            'email' => $user->email,
40
            'name'  => $data['name'],
41
        ], $response);
42
43
        // assert data was updated in the database
44
        $this->seeInDatabase('users', ['name' => $data['name']]);
45
    }
46
47
    public function testUpdateExistingUserWithoutData_()
48
    {
49
        $data = [];
50
51
        // send the HTTP request
52
        $response = $this->makeCall($data);
53
54
        // assert response status is correct
55
        $this->assertEquals('417', $response->getStatusCode());
56
    }
57
58
59 View Code Duplication
    public function testUpdateExistingUserWithEmptyValues()
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...
60
    {
61
        $data = []; // empty data
62
63
        // send the HTTP request
64
        $response = $this->makeCall($data);
65
66
        // assert response status is correct
67
        $this->assertEquals('417', $response->getStatusCode());
68
69
        // assert message is correct
70
        $this->assertResponseContainKeyValue([
71
            'message' => 'Inputs are empty.',
72
        ], $response);
73
    }
74
}
75