UpdateUserCest::updateUserSetId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace codecept\user;
4
5
use codecept\ApiTester;
6
use Codeception\Util\HttpCode;
7
use SlayerBirden\DataFlowServer\Domain\Entities\User;
8
9
class UpdateUserCest
10
{
11
    public function _before(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
12
    {
13
        $I->haveInRepository(User::class, [
14
            'id' => 2,
15
            'first' => 'Tester2',
16
            'last' => 'Tester2',
17
            'email' => '[email protected]',
18
        ]);
19
    }
20
21
    public function updateUser(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
22
    {
23
        $I->wantTo('update user');
24
        $I->haveHttpHeader('Content-Type', 'application/json');
25
        $I->sendPUT('/user/1', [
26
            'first' => 'Bob',
27
            'last' => 'Tester',
28
            'email' => '[email protected]',
29
        ]);
30
        $I->seeResponseCodeIs(HttpCode::OK);
31
        $I->seeResponseContainsJson([
32
            'data' => [
33
                'user' => [
34
                    'first' => 'Bob',
35
                    'last' => 'Tester',
36
                    'email' => '[email protected]',
37
                ]
38
            ]
39
        ]);
40
    }
41
42
    public function updateNonExistingUser(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
43
    {
44
        $I->wantTo('update non existing user');
45
        $I->haveHttpHeader('Content-Type', 'application/json');
46
        $I->sendPUT('/user/0', [
47
            'first' => 'John',
48
            'last' => 'Tester',
49
            'email' => '[email protected]',
50
        ]);
51
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
52
        $I->seeResponseContainsJson([
53
            'data' => [
54
                'user' => null
55
            ]
56
        ]);
57
    }
58
59
    public function updateUserSetId(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
60
    {
61
        $I->wantTo('update user and attempt to set id');
62
        $I->haveHttpHeader('Content-Type', 'application/json');
63
        $I->sendPUT('/user/1', [
64
            'id' => 2,
65
            'first' => 'John',
66
            'last' => 'Tester',
67
            'email' => '[email protected]',
68
        ]);
69
        $I->seeResponseCodeIs(HttpCode::OK);
70
        $I->seeResponseContainsJson([
71
            'data' => [
72
                'user' => [
73
                    'id' => 1,
74
                    'first' => 'John',
75
                    'last' => 'Tester',
76
                    'email' => '[email protected]',
77
                ]
78
            ]
79
        ]);
80
    }
81
82
    public function updateUserInvalidEmail(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
83
    {
84
        $I->wantTo('update user set invalid email');
85
        $I->haveHttpHeader('Content-Type', 'application/json');
86
        $I->sendPUT('/user/1', [
87
            'first' => 'Tester',
88
            'last' => 'Tester',
89
            'email' => 'testing',
90
        ]);
91
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
92
        $I->seeResponseContainsJson([
93
            'data' => [
94
                'user' => null,
95
                'validation' => [
96
                    'field' => 'email',
97
                ]
98
            ]
99
        ]);
100
    }
101
102
    public function updateUserSetExistingEmail(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
103
    {
104
        $I->wantTo('update user set existing email');
105
        $I->haveHttpHeader('Content-Type', 'application/json');
106
        $I->sendPUT('/user/1', [
107
            'first' => 'Tester',
108
            'last' => 'Tester',
109
            'email' => '[email protected]',
110
        ]);
111
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
112
        $I->seeResponseContainsJson([
113
            'data' => [
114
                'user' => [
115
                    'first' => 'Tester',
116
                    'last' => 'Tester',
117
                    'email' => '[email protected]',
118
                ]
119
            ]
120
        ]);
121
    }
122
}
123