Passed
Pull Request — master (#372)
by Wilmer
03:17 queued 44s
created

QueryHelperProviders   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
c 0
b 0
f 0
dl 0
loc 77
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizeSelectProvider() 0 11 1
A filterConditionDataProvider() 0 38 1
A normalizeOrderByProvider() 0 7 1
A tablesNameDataProvider() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Query\Helper;
6
7
use Yiisoft\Db\Expression\Expression;
8
9
final class QueryHelperProviders
10
{
11
    public function filterConditionDataProvider(): array
12
    {
13
        return [
14
            /* like */
15
            [['like', 'name', []], []],
16
            [['not like', 'name', []], []],
17
            [['or like', 'name', []],  []],
18
            [['or not like', 'name', []], []],
19
20
            /* not */
21
            [['not', ''], []],
22
23
            /* and */
24
            [['and', '', ''], []],
25
            [['and', '', 'id=2'], ['and', 'id=2']],
26
            [['and', 'id=1', ''], ['and', 'id=1']],
27
            [['and', 'type=1', ['or', '', 'id=2']], ['and', 'type=1', ['or', 'id=2']]],
28
29
            /* or */
30
            [['or', 'id=1', ''], ['or', 'id=1']],
31
            [['or', 'type=1', ['or', '', 'id=2']], ['or', 'type=1', ['or', 'id=2']]],
32
33
            /* between */
34
            [['between', 'id', 1, null], []],
35
            [['not between', 'id', null, 10], []],
36
37
            /* in */
38
            [['in', 'id', []], []],
39
            [['not in', 'id', []], []],
40
41
            /* simple conditions */
42
            [['=', 'a', ''], []],
43
            [['>', 'a', ''], []],
44
            [['>=', 'a', ''], []],
45
            [['<', 'a', ''], []],
46
            [['<=', 'a', ''], []],
47
            [['<>', 'a', ''], []],
48
            [['!=', 'a', ''], []],
49
        ];
50
    }
51
52
    public function normalizeOrderByProvider(): array
53
    {
54
        return [
55
            ['id', ['id' => 4]],
56
            [['id'], ['id']],
57
            ['name ASC, date DESC', ['name' => 4, 'date' => 3]],
58
            [new Expression('SUBSTR(name, 3, 4) DESC, x ASC'), [new Expression('SUBSTR(name, 3, 4) DESC, x ASC')]],
59
        ];
60
    }
61
62
    public function normalizeSelectProvider(): array
63
    {
64
        return [
65
            ['exists', ['exists' => 'exists']],
66
            ['count(*) > 1', ['count(*) > 1']],
67
            ['name, name, name as X, name as X', ['name' => 'name', 'X' => 'name']],
68
            [
69
                ['email', 'address', 'status' => new Expression('1')],
70
                ['email' => 'email', 'address' => 'address', 'status' => new Expression('1')],
71
            ],
72
            [new Expression('1 as Ab'), [new Expression('1 as Ab')]],
73
        ];
74
    }
75
76
    public function tablesNameDataProvider(): array
77
    {
78
        return [
79
            [['customer'], '', ['{{customer}}' => '{{customer}}']],
80
            [['profile AS "prf"'], '', ['{{prf}}' => '{{profile}}']],
81
            [['mainframe as400'], '', ['{{as400}}' => '{{mainframe}}']],
82
            [
83
                ['x' => new Expression('(SELECT id FROM user)')],
84
                '',
85
                ['{{x}}' => new Expression('(SELECT id FROM user)')],
86
            ],
87
        ];
88
    }
89
}
90