Completed
Push — master ( 630401...3eb757 )
by Oleg
02:43
created

GetUsersCest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 128
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A _before() 0 11 2
A getAllUsers() 0 20 2
A getSecondPageUsers() 0 18 1
A getFilteredUsers() 0 24 1
A getSortedUsers() 0 18 1
A getNoResultsFilterUsers() 0 14 1
A getWrongFilterUsers() 0 14 1
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)
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...
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)
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...
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)
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
            '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)
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...
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)
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...
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)
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...
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)
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...
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