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

CallbackRulesTest::callbackProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 9.9666
1
<?php
2
3
use kalanis\kw_rules\Rules;
4
use kalanis\kw_rules\Exceptions\RuleException;
5
6
7
class CallbackRulesTest extends CommonTestClass
8
{
9
    /**
10
     * @param mixed $expectedCall
11
     * @param mixed $checkValue
12
     * @param bool $gotResult
13
     * @param bool $pass
14
     * @throws RuleException
15
     * @dataProvider callbackProvider
16
     */
17
    public function testCallback($expectedCall, $checkValue, bool $gotResult, bool $pass): void
18
    {
19
        $data = new Rules\ProcessCallback();
20
        $this->assertInstanceOf(Rules\ARule::class, $data);
21
        if (!$gotResult) $this->expectException(RuleException::class);
22
        $data->setAgainstValue($expectedCall);
23
        if ($gotResult) {
24
            $mock = MockEntry::init('foo', $checkValue);
25
            if (!$pass) $this->expectException(RuleException::class);
26
            $data->validate($mock);
27
        }
28
    }
29
30
    public function callbackProvider(): array
31
    {
32
        return [
33
            [false, false, false, false],
34
            ['', '', false, false],
35
            [123, '', false, false],
36
            ['asdf', '', false, false],
37
            ['CallbackRulesTest::callMeStatic', null, true, false],
38
            ['CallbackRulesTest::callMeStatic', 1, true, true ],
39
            [[$this, 'callMeDynamic'], null, true, false],
40
            [[$this, 'callMeDynamic'], 1, true, true],
41
        ];
42
    }
43
44
    public static function callMeStatic($param): bool
45
    {
46
        return !empty($param);
47
    }
48
49
    public function callMeDynamic($param): bool
50
    {
51
        return !empty($param);
52
    }
53
}
54