1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace codecept; |
4
|
|
|
|
5
|
|
|
use Codeception\Util\HttpCode; |
6
|
|
|
|
7
|
|
|
class AddUserCest |
8
|
|
|
{ |
9
|
|
|
public function addUser(ApiTester $I) |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
$I->wantTo('create user'); |
12
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
13
|
|
|
$I->sendPOST('/user', [ |
14
|
|
|
'first' => 'Test', |
15
|
|
|
'last' => 'User', |
16
|
|
|
'email' => '[email protected]', |
17
|
|
|
]); |
18
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
19
|
|
|
$I->seeResponseContainsJson([ |
20
|
|
|
'success' => true, |
21
|
|
|
'data' => [ |
22
|
|
|
'user' => [ |
23
|
|
|
'first' => 'Test', |
24
|
|
|
'last' => 'User', |
25
|
|
|
'email' => '[email protected]', |
26
|
|
|
] |
27
|
|
|
] |
28
|
|
|
]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function addIncompleteUser(ApiTester $I) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$I->wantTo('create user with incomplete data'); |
34
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
35
|
|
|
$I->sendPOST('/user', [ |
36
|
|
|
'last' => 'User', |
37
|
|
|
'email' => '[email protected]', |
38
|
|
|
]); |
39
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
40
|
|
|
$I->seeResponseContainsJson([ |
41
|
|
|
'success' => false, |
42
|
|
|
'data' => [ |
43
|
|
|
'validation' => [ |
44
|
|
|
[ |
45
|
|
|
'field' => 'first', |
46
|
|
|
] |
47
|
|
|
] |
48
|
|
|
] |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function addUserWithWrongEmail(ApiTester $I) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$I->wantTo('create user with wrong email'); |
55
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
56
|
|
|
$I->sendPOST('/user', [ |
57
|
|
|
'first' => 'Test', |
58
|
|
|
'last' => 'User', |
59
|
|
|
'email' => 'wrong email', |
60
|
|
|
]); |
61
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
62
|
|
|
$I->seeResponseContainsJson([ |
63
|
|
|
'success' => false, |
64
|
|
|
'data' => [ |
65
|
|
|
'validation' => [ |
66
|
|
|
[ |
67
|
|
|
'field' => 'email', |
68
|
|
|
] |
69
|
|
|
] |
70
|
|
|
] |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function addUserWithExistingEmail(ApiTester $I) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$I->wantTo('create user with existing email'); |
77
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
78
|
|
|
$I->sendPOST('/user', [ |
79
|
|
|
'first' => 'Test', |
80
|
|
|
'last' => 'User', |
81
|
|
|
'email' => '[email protected]', |
82
|
|
|
]); |
83
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
84
|
|
|
$I->seeResponseContainsJson([ |
85
|
|
|
'success' => false, |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.