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