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

FormatRulesTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 7
1
<?php
2
3
use kalanis\kw_rules\Rules;
4
use kalanis\kw_rules\Exceptions\RuleException;
5
6
7
class FormatRulesTest extends CommonTestClass
8
{
9
    /**
10
     * @param string $value
11
     * @param bool $resultBool
12
     * @param bool $resultNum
13
     * @param bool $resultStr
14
     * @throws RuleException
15
     * @dataProvider compareFormatProvider
16
     */
17
    public function testFormatBool($value, bool $resultBool, bool $resultNum, bool $resultStr): void
18
    {
19
        $data = new Rules\IsBool();
20
        $this->assertInstanceOf(Rules\ARule::class, $data);
21
        if (!$resultBool) $this->expectException(RuleException::class);
22
        $data->validate(MockEntry::init('foo', $value));
23
    }
24
25
    /**
26
     * @param string $value
27
     * @param bool $resultBool
28
     * @param bool $resultNum
29
     * @param bool $resultStr
30
     * @throws RuleException
31
     * @dataProvider compareFormatProvider
32
     */
33
    public function testFormatNumeric($value, bool $resultBool, bool $resultNum, bool $resultStr): void
34
    {
35
        $data = new Rules\IsNumeric();
36
        $this->assertInstanceOf(Rules\ARule::class, $data);
37
        if (!$resultNum) $this->expectException(RuleException::class);
38
        $data->validate(MockEntry::init('foo', $value));
39
    }
40
41
    /**
42
     * @param string $value
43
     * @param bool $resultBool
44
     * @param bool $resultNum
45
     * @param bool $resultStr
46
     * @throws RuleException
47
     * @dataProvider compareFormatProvider
48
     */
49
    public function testFormatString($value, bool $resultBool, bool $resultNum, bool $resultStr): void
50
    {
51
        $data = new Rules\IsString();
52
        $this->assertInstanceOf(Rules\ARule::class, $data);
53
        if (!$resultStr) $this->expectException(RuleException::class);
54
        $data->validate(MockEntry::init('foo', $value));
55
    }
56
57
    public function compareFormatProvider(): array
58
    {
59
        return [
60
            [false,           true,  false, false],
61
            [123,             false, true,  false],
62
            ['abc',           false, false, true],
63
            [new \stdClass(), false, false, false],
64
        ];
65
    }
66
}
67