Total Complexity | 5 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
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 | } |
||
53 |