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) |
|
|
|
|
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) |
|
|
|
|
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
|
|
|
'success' => true, |
33
|
|
|
'data' => [ |
34
|
|
|
'user' => [ |
35
|
|
|
'first' => 'Bob', |
36
|
|
|
'last' => 'Tester', |
37
|
|
|
'email' => '[email protected]', |
38
|
|
|
] |
39
|
|
|
] |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function updateNonExistingUser(ApiTester $I) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$I->wantTo('update non existing user'); |
46
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
47
|
|
|
$I->sendPUT('/user/0', [ |
48
|
|
|
'first' => 'John', |
49
|
|
|
'last' => 'Tester', |
50
|
|
|
'email' => '[email protected]', |
51
|
|
|
]); |
52
|
|
|
$I->seeResponseCodeIs(HttpCode::NOT_FOUND); |
53
|
|
|
$I->seeResponseContainsJson([ |
54
|
|
|
'success' => false, |
55
|
|
|
'data' => [ |
56
|
|
|
'user' => null |
57
|
|
|
] |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function updateUserSetId(ApiTester $I) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$I->wantTo('update user and attempt to set id'); |
64
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
65
|
|
|
$I->sendPUT('/user/1', [ |
66
|
|
|
'id' => 2, |
67
|
|
|
'first' => 'John', |
68
|
|
|
'last' => 'Tester', |
69
|
|
|
'email' => '[email protected]', |
70
|
|
|
]); |
71
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
72
|
|
|
$I->seeResponseContainsJson([ |
73
|
|
|
'success' => true, |
74
|
|
|
'data' => [ |
75
|
|
|
'user' => [ |
76
|
|
|
'id' => 1, |
77
|
|
|
'first' => 'John', |
78
|
|
|
'last' => 'Tester', |
79
|
|
|
'email' => '[email protected]', |
80
|
|
|
] |
81
|
|
|
] |
82
|
|
|
]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function updateUserInvalidEmail(ApiTester $I) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$I->wantTo('update user set invalid email'); |
88
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
89
|
|
|
$I->sendPUT('/user/1', [ |
90
|
|
|
'first' => 'Tester', |
91
|
|
|
'last' => 'Tester', |
92
|
|
|
'email' => 'testing', |
93
|
|
|
]); |
94
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
95
|
|
|
$I->seeResponseContainsJson([ |
96
|
|
|
'success' => false, |
97
|
|
|
'data' => [ |
98
|
|
|
'user' => null, |
99
|
|
|
'validation' => [ |
100
|
|
|
'field' => 'email', |
101
|
|
|
] |
102
|
|
|
] |
103
|
|
|
]); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function updateUserSetExistingEmail(ApiTester $I) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$I->wantTo('update user set existing email'); |
109
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
110
|
|
|
$I->sendPUT('/user/1', [ |
111
|
|
|
'first' => 'Tester', |
112
|
|
|
'last' => 'Tester', |
113
|
|
|
'email' => '[email protected]', |
114
|
|
|
]); |
115
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
116
|
|
|
$I->seeResponseContainsJson([ |
117
|
|
|
'success' => false, |
118
|
|
|
'data' => [ |
119
|
|
|
'user' => [ |
120
|
|
|
'first' => 'Tester', |
121
|
|
|
'last' => 'Tester', |
122
|
|
|
'email' => '[email protected]', |
123
|
|
|
] |
124
|
|
|
] |
125
|
|
|
]); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
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.