GetUsersCest::getAllUsers()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
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
            'data' => [
37
                'users' => $usersJson,
38
                'count' => 11,
39
            ]
40
        ]);
41
    }
42
43
    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...
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
            'data' => [
51
                'users' => [
52
                    [
53
                        'email' => '[email protected]',
54
                    ],
55
                ],
56
                'count' => 11,
57
            ]
58
        ]);
59
    }
60
61
    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...
62
    {
63
        $I->wantTo('get users filtered by test1');
64
        $I->haveHttpHeader('Content-Type', 'application/json');
65
        $I->sendGET('/users?f[email]=test1');
66
        $I->seeResponseCodeIs(HttpCode::OK);
67
        $I->seeResponseContainsJson([
68
            'data' => [
69
                'users' => [
70
                    [
71
                        'email' => '[email protected]',
72
                    ],
73
                    [
74
                        'email' => '[email protected]',
75
                    ],
76
                    [
77
                        'email' => '[email protected]',
78
                    ],
79
                ],
80
                'count' => 3,
81
            ]
82
        ]);
83
    }
84
85
    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...
86
    {
87
        $I->wantTo('get users sorted by id desc');
88
        $I->haveHttpHeader('Content-Type', 'application/json');
89
        $I->sendGET('/users?s[id]=desc');
90
        $I->seeResponseCodeIs(HttpCode::OK);
91
        $I->seeResponseContainsJson([
92
            'data' => [
93
                'users' => [
94
                    [
95
                        'email' => '[email protected]',
96
                    ],
97
                ],
98
                'count' => 11,
99
            ]
100
        ]);
101
    }
102
103
    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...
104
    {
105
        $I->wantTo('attempt to get users with no resulsts filters');
106
        $I->haveHttpHeader('Content-Type', 'application/json');
107
        $I->sendGET('/users?f[email]=bla');
108
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
109
        $I->seeResponseContainsJson([
110
            'data' => [
111
                'users' => [],
112
                'count' => 0,
113
            ]
114
        ]);
115
    }
116
117
    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...
118
    {
119
        $I->wantTo('attempt to get users with wrong filters');
120
        $I->haveHttpHeader('Content-Type', 'application/json');
121
        $I->sendGET('/users?f[age]=30');
122
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
123
        $I->seeResponseContainsJson([
124
            'data' => [
125
                'users' => [],
126
                'count' => 0,
127
            ]
128
        ]);
129
    }
130
}
131