Completed
Push — master ( 630401...3eb757 )
by Oleg
02:43
created

UpdateUserCest::updateUserSetExistingEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
rs 9.584
cc 1
nc 1
nop 1
1
<?php
2
3
namespace codecept;
4
5
use Codeception\Util\HttpCode;
6
use SlayerBirden\DataFlowServer\Domain\Entities\User;
7
8
class UpdateUserCest
9
{
10
    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...
11
    {
12
        $I->haveInRepository(User::class, [
13
            'id' => 2,
14
            'first' => 'Tester2',
15
            'last' => 'Tester2',
16
            'email' => '[email protected]',
17
        ]);
18
    }
19
20
    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...
21
    {
22
        $I->wantTo('update user');
23
        $I->haveHttpHeader('Content-Type', 'application/json');
24
        $I->sendPUT('/user/1', [
25
            'first' => 'Bob',
26
            'last' => 'Tester',
27
            'email' => '[email protected]',
28
        ]);
29
        $I->seeResponseCodeIs(HttpCode::OK);
30
        $I->seeResponseContainsJson([
31
            'success' => true,
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
            'success' => false,
54
            'data' => [
55
                'user' => null
56
            ]
57
        ]);
58
    }
59
60
    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...
61
    {
62
        $I->wantTo('update user and attempt to set id');
63
        $I->haveHttpHeader('Content-Type', 'application/json');
64
        $I->sendPUT('/user/1', [
65
            'id' => 2,
66
            'first' => 'John',
67
            'last' => 'Tester',
68
            'email' => '[email protected]',
69
        ]);
70
        $I->seeResponseCodeIs(HttpCode::OK);
71
        $I->seeResponseContainsJson([
72
            'success' => true,
73
            'data' => [
74
                'user' => [
75
                    'id' => 1,
76
                    'first' => 'John',
77
                    'last' => 'Tester',
78
                    'email' => '[email protected]',
79
                ]
80
            ]
81
        ]);
82
    }
83
84
    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...
85
    {
86
        $I->wantTo('update user set invalid email');
87
        $I->haveHttpHeader('Content-Type', 'application/json');
88
        $I->sendPUT('/user/1', [
89
            'first' => 'Tester',
90
            'last' => 'Tester',
91
            'email' => 'testing',
92
        ]);
93
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
94
        $I->seeResponseContainsJson([
95
            'success' => false,
96
            'data' => [
97
                'user' => null,
98
                'validation' => [
99
                    'field' => 'email',
100
                ]
101
            ]
102
        ]);
103
    }
104
105
    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...
106
    {
107
        $I->wantTo('update user set existing email');
108
        $I->haveHttpHeader('Content-Type', 'application/json');
109
        $I->sendPUT('/user/1', [
110
            'first' => 'Tester',
111
            'last' => 'Tester',
112
            'email' => '[email protected]',
113
        ]);
114
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
115
        $I->seeResponseContainsJson([
116
            'success' => false,
117
            'data' => [
118
                'user' => [
119
                    'first' => 'Tester',
120
                    'last' => 'Tester',
121
                    'email' => '[email protected]',
122
                ]
123
            ]
124
        ]);
125
    }
126
}
127