Passed
Push — master ( 65ca3f...66b084 )
by Radosław
02:04
created

TestCase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5
1
<?php
2
declare(strict_types=1);
3
4
namespace Phln\Build\PhpUnit;
5
6
abstract class TestCase extends \PHPUnit\Framework\TestCase
7
{
8
    /**
9
     * @var string
10
     */
11
    protected $testedFnOverwrite = null;
12
13
    abstract public function getTestedFn(): string;
14
15
    /**
16
     * @param string $testedFnOverwrite
17
     */
18
    public function setTestedFnOverwrite(string $testedFnOverwrite)
19
    {
20
        $this->testedFnOverwrite = $testedFnOverwrite;
21
    }
22
23
    protected function callFn(...$args)
24
    {
25
        $fn = $this->getResolvedFn();
26
27
        if (false === is_callable($fn)) {
28
            $this->markTestSkipped("Function {$fn} is not defined");
29
        }
30
31
        return $fn(...$args);
32
    }
33
34
    public function toString()
35
    {
36
        $class = new \ReflectionClass($this);
37
38
        $buffer = sprintf(
39
            '%s::%s (using fn: %s)',
40
            $class->name,
41
            $this->getName(false),
42
            $this->getResolvedFn()
43
        );
44
45
        return $buffer . $this->getDataSetAsString();
46
    }
47
48
    protected function getResolvedFn(): string
49
    {
50
        return $this->testedFnOverwrite ?? $this->getTestedFn();
51
    }
52
}
53