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

GetConfigsCest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 198
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 198
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A _before() 0 21 2
A getAllConfigurations() 0 29 2
A getSecondPageConfigurations() 0 18 1
A getFilteredConfigurations() 0 18 1
A getSortedConfigurations() 0 18 1
A getNoResultsFilterConfigurations() 0 14 1
A getWrongFilterUsers() 0 14 1
1
<?php
2
3
namespace codecept\configuration;
4
5
use codecept\ApiTester;
6
use Codeception\Util\HttpCode;
7
use SlayerBirden\DataFlowServer\Db\Entities\DbConfiguration;
8
use SlayerBirden\DataFlowServer\Domain\Entities\User;
9
10
class GetConfigsCest
11
{
12
    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...
13
    {
14
        $user = $I->grabEntityFromRepository(User::class, ['id' => 1]);
15
        $I->haveInRepository(DbConfiguration::class, [
16
            'owner' => $user,
17
            'title' => 'sqlite config',
18
            'url' => 'sqlite:///data/db/db.sqlite',
19
        ]);
20
        $I->haveInRepository(DbConfiguration::class, [
21
            'owner' => $user,
22
            'title' => 'mysql config',
23
            'url' => 'mysql://test-user:test-pwd@mysql/test',
24
        ]);
25
        for ($i = 1; $i < 10; $i++) {
26
            $I->haveInRepository(DbConfiguration::class, [
27
                'owner' => $user,
28
                'title' => sprintf('project %d config', $i),
29
                'url' => 'sqlite:///data/db/db.sqlite',
30
            ]);
31
        }
32
    }
33
34
    public function getAllConfigurations(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...
35
    {
36
        $I->wantTo('get all db configurations');
37
        $I->haveHttpHeader('Content-Type', 'application/json');
38
        $I->sendGET('/configs?l=100');
39
        $I->seeResponseCodeIs(HttpCode::OK);
40
        $configs = [
41
            [
42
                'title' => 'sqlite config',
43
            ],
44
            [
45
                'title' => 'mysql config',
46
            ],
47
        ];
48
        $otherConfigs = [];
49
        for ($i = 1; $i < 10; $i++) {
50
            $otherConfigs[] = [
51
                'title' => sprintf('project %d config', $i),
52
            ];
53
        }
54
        $configs = array_merge($configs, $otherConfigs);
55
        $I->seeResponseContainsJson([
56
            'success' => true,
57
            'data' => [
58
                'configurations' => $configs,
59
                'count' => 11,
60
            ]
61
        ]);
62
    }
63
64
    public function getSecondPageConfigurations(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...
65
    {
66
        $I->wantTo('get second page of db configurations');
67
        $I->haveHttpHeader('Content-Type', 'application/json');
68
        $I->sendGET('/configs?p=2');
69
        $I->seeResponseCodeIs(HttpCode::OK);
70
        $I->seeResponseContainsJson([
71
            'success' => true,
72
            'data' => [
73
                'configurations' => [
74
                    [
75
                        'title' => 'project 9 config',
76
                    ],
77
                ],
78
                'count' => 11,
79
            ]
80
        ]);
81
    }
82
83
    public function getFilteredConfigurations(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...
84
    {
85
        $I->wantTo('get configurations filtered by mysql');
86
        $I->haveHttpHeader('Content-Type', 'application/json');
87
        $I->sendGET('/configs?f[title]=mysql');
88
        $I->seeResponseCodeIs(HttpCode::OK);
89
        $I->seeResponseContainsJson([
90
            'success' => true,
91
            'data' => [
92
                'configurations' => [
93
                    [
94
                        'title' => 'mysql config',
95
                    ],
96
                ],
97
                'count' => 1,
98
            ]
99
        ]);
100
    }
101
102
    public function getSortedConfigurations(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...
103
    {
104
        $I->wantTo('get configurations sorted by title asc');
105
        $I->haveHttpHeader('Content-Type', 'application/json');
106
        $I->sendGET('/configs?s[title]=asc');
107
        $I->seeResponseCodeIs(HttpCode::OK);
108
        $I->seeResponseContainsJson([
109
            'success' => true,
110
            'data' => [
111
                'configurations' => [
112
                    [
113
                        'title' => 'mysql config',
114
                    ],
115
                ],
116
                'count' => 11,
117
            ]
118
        ]);
119
    }
120
121
    public function getNoResultsFilterConfigurations(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 configurations with not matching filter');
124
        $I->haveHttpHeader('Content-Type', 'application/json');
125
        $I->sendGET('/configs?f[title]=bla');
126
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
127
        $I->seeResponseContainsJson([
128
            'success' => false,
129
            'data' => [
130
                'configurations' => [],
131
                'count' => 0,
132
            ]
133
        ]);
134
    }
135
136
    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...
137
    {
138
        $I->wantTo('attempt to get configurations with wrong filters');
139
        $I->haveHttpHeader('Content-Type', 'application/json');
140
        $I->sendGET('/configs?f[abracadabra]=30');
141
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
142
        $I->seeResponseContainsJson([
143
            'success' => false,
144
            'data' => [
145
                'configurations' => [],
146
                'count' => 0,
147
            ]
148
        ]);
149
    }
150
}
151