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