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