Passed
Push — master ( e6a12d...210e25 )
by Petr
08:06
created

BasicFactoryTest::inputsProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 52
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 57
rs 9.0472

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use kalanis\kw_rules\Exceptions\RuleException;
4
use kalanis\kw_rules\Interfaces\IRules;
5
use kalanis\kw_rules\Rules;
6
7
8
class BasicFactoryTest extends CommonTestClass
9
{
10
    /**
11
     * @throws RuleException
12
     */
13
    public function testFactory(): void
14
    {
15
        $factory = new Rules\Factory();
16
        $data = $factory->getRule(IRules::SATISFIES_CALLBACK); // known to factory
17
        $this->assertInstanceOf(Rules\ARule::class, $data);
18
        $this->expectException(RuleException::class);
19
        $factory->getRule(IRules::IMAGE_MAX_DIMENSION); // not set in factory
20
    }
21
22
    /**
23
     * @param string $rule
24
     * @param bool $gotResult
25
     * @throws RuleException
26
     * @dataProvider inputsProvider
27
     */
28
    public function testFactoryAvailability(string $rule, bool $gotResult): void
29
    {
30
        $factory = new Rules\Factory();
31
        if (!$gotResult) $this->expectException(RuleException::class);
32
        $data = $factory->getRule($rule);
33
        if ($data) $this->assertInstanceOf(Rules\ARule::class, $data);
34
    }
35
36
    public function inputsProvider(): array
37
    {
38
        return [
39
            [IRules::MATCH_ALL, true],
40
            [IRules::MATCH_ANY, true],
41
            [IRules::MATCH_ENTRY, true],
42
            [IRules::ALWAYS, true],
43
            [IRules::EQUALS, true],
44
            [IRules::NOT_EQUALS, true],
45
            [IRules::IN_ARRAY, true],
46
            [IRules::NOT_IN_ARRAY, true],
47
            [IRules::IS_GREATER_THAN, true],
48
            [IRules::IS_LOWER_THAN, true],
49
            [IRules::IS_GREATER_THAN_EQUALS, true],
50
            [IRules::IS_LOWER_THAN_EQUALS, true],
51
            [IRules::IS_NUMERIC, true],
52
            [IRules::IS_STRING, true],
53
            [IRules::IS_BOOL, true],
54
            [IRules::MATCHES_PATTERN, true],
55
            [IRules::LENGTH_MIN, true],
56
            [IRules::LENGTH_MAX, true],
57
            [IRules::LENGTH_EQUALS, true],
58
            [IRules::IN_RANGE, true],
59
            [IRules::IN_RANGE_EQUALS, true],
60
            [IRules::NOT_IN_RANGE, true],
61
            [IRules::NOT_IN_RANGE_EQUALS, true],
62
            [IRules::IS_FILLED, true],
63
            [IRules::IS_NOT_EMPTY, true],
64
            [IRules::IS_EMPTY, true],
65
            [IRules::SATISFIES_CALLBACK, true],
66
            [IRules::IS_EMAIL, true],
67
            [IRules::IS_DOMAIN, true],
68
            [IRules::URL_EXISTS, true],
69
            [IRules::IS_ACTIVE_DOMAIN, true],
70
            [IRules::IS_JSON_STRING, true],
71
72
            [IRules::FILE_EXISTS, false],
73
            [IRules::FILE_SENT, false],
74
            [IRules::FILE_RECEIVED, false],
75
            [IRules::FILE_MAX_SIZE, false],
76
            [IRules::FILE_MIMETYPE_IN_LIST, false],
77
            [IRules::FILE_MIMETYPE_EQUALS, false],
78
            [IRules::IS_IMAGE, false],
79
            [IRules::IMAGE_DIMENSION_EQUALS, false],
80
            [IRules::IMAGE_DIMENSION_IN_LIST, false],
81
            [IRules::IMAGE_MAX_DIMENSION, false],
82
            [IRules::IMAGE_MIN_DIMENSION, false],
83
84
            [IRules::IS_POST_CODE, false],
85
            [IRules::IS_TELEPHONE, false],
86
            [IRules::IS_EU_VAT, false],
87
            [IRules::IS_DATE, true],
88
            [IRules::IS_DATE_REGEX, true],
89
90
            [IRules::SAFE_EQUALS_BASIC, true],
91
            [IRules::SAFE_EQUALS_FUNC, true],
92
            [IRules::SAFE_EQUALS_PASS, true],
93
        ];
94
    }
95
}
96