Completed
Push — master ( 3eb757...3bc7c8 )
by Oleg
03:46
created

GetUsersCest::getFilteredUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
rs 9.536
cc 1
nc 1
nop 1
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)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

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.

Loading history...
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)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

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.

Loading history...
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)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

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.

Loading history...
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)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

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.

Loading history...
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)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

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.

Loading history...
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)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

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.

Loading history...
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)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

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.

Loading history...
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