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 GetUsersCest |
10
|
|
|
{ |
11
|
|
|
public function _before(ApiTester $I) |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
foreach (range(2, 11) as $i) { |
14
|
|
|
$I->haveInRepository(User::class, [ |
15
|
|
|
'id' => $i, |
16
|
|
|
'first' => 'Tester' . $i, |
17
|
|
|
'last' => 'Tester' . $i, |
18
|
|
|
'email' => 'test' . $i . '@example.com', |
19
|
|
|
]); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getAllUsers(ApiTester $I) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$I->wantTo('get all users'); |
26
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
27
|
|
|
$I->sendGET('/users?l=100'); |
28
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
29
|
|
|
$usersJson = []; |
30
|
|
|
foreach (range(2, 11) as $i) { |
31
|
|
|
$usersJson[] = [ |
32
|
|
|
'email' => 'test' . $i . '@example.com', |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
$I->seeResponseContainsJson([ |
36
|
|
|
'success' => true, |
37
|
|
|
'data' => [ |
38
|
|
|
'users' => $usersJson, |
39
|
|
|
'count' => 11, |
40
|
|
|
] |
41
|
|
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getSecondPageUsers(ApiTester $I) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$I->wantTo('get second page of users'); |
47
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
48
|
|
|
$I->sendGET('/users?p=2'); |
49
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
50
|
|
|
$I->seeResponseContainsJson([ |
51
|
|
|
'success' => true, |
52
|
|
|
'data' => [ |
53
|
|
|
'users' => [ |
54
|
|
|
[ |
55
|
|
|
'email' => '[email protected]', |
56
|
|
|
], |
57
|
|
|
], |
58
|
|
|
'count' => 11, |
59
|
|
|
] |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getFilteredUsers(ApiTester $I) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$I->wantTo('get users filtered by test1'); |
66
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
67
|
|
|
$I->sendGET('/users?f[email]=test1'); |
68
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
69
|
|
|
$I->seeResponseContainsJson([ |
70
|
|
|
'success' => true, |
71
|
|
|
'data' => [ |
72
|
|
|
'users' => [ |
73
|
|
|
[ |
74
|
|
|
'email' => '[email protected]', |
75
|
|
|
], |
76
|
|
|
[ |
77
|
|
|
'email' => '[email protected]', |
78
|
|
|
], |
79
|
|
|
[ |
80
|
|
|
'email' => '[email protected]', |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
'count' => 3, |
84
|
|
|
] |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getSortedUsers(ApiTester $I) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
$I->wantTo('get users sorted by id desc'); |
91
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
92
|
|
|
$I->sendGET('/users?s[id]=desc'); |
93
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
94
|
|
|
$I->seeResponseContainsJson([ |
95
|
|
|
'success' => true, |
96
|
|
|
'data' => [ |
97
|
|
|
'users' => [ |
98
|
|
|
[ |
99
|
|
|
'email' => '[email protected]', |
100
|
|
|
], |
101
|
|
|
], |
102
|
|
|
'count' => 11, |
103
|
|
|
] |
104
|
|
|
]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getNoResultsFilterUsers(ApiTester $I) |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
$I->wantTo('attempt to get users with no resulsts filters'); |
110
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
111
|
|
|
$I->sendGET('/users?f[email]=bla'); |
112
|
|
|
$I->seeResponseCodeIs(HttpCode::NOT_FOUND); |
113
|
|
|
$I->seeResponseContainsJson([ |
114
|
|
|
'success' => false, |
115
|
|
|
'data' => [ |
116
|
|
|
'users' => [], |
117
|
|
|
'count' => 0, |
118
|
|
|
] |
119
|
|
|
]); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getWrongFilterUsers(ApiTester $I) |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
$I->wantTo('attempt to get users with wrong filters'); |
125
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
126
|
|
|
$I->sendGET('/users?f[age]=30'); |
127
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
128
|
|
|
$I->seeResponseContainsJson([ |
129
|
|
|
'success' => false, |
130
|
|
|
'data' => [ |
131
|
|
|
'users' => [], |
132
|
|
|
'count' => 0, |
133
|
|
|
] |
134
|
|
|
]); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
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.