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