1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Phln\Build\PhpUnit\Listener; |
5
|
|
|
|
6
|
|
|
use Exception; |
7
|
|
|
use Phln\Build\PhpUnit\TestCase; |
8
|
|
|
use PHPUnit\Framework\AssertionFailedError; |
9
|
|
|
use PHPUnit\Framework\Test; |
10
|
|
|
use PHPUnit\Framework\TestListener; |
11
|
|
|
use PHPUnit\Framework\TestSuite; |
12
|
|
|
use PHPUnit\Framework\Warning; |
13
|
|
|
|
14
|
|
|
class TestBundleListener implements TestListener |
15
|
|
|
{ |
16
|
|
|
public function addError(Test $test, Exception $e, $time) |
17
|
|
|
{ |
18
|
|
|
// void |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function addFailure(Test $test, AssertionFailedError $e, $time) |
22
|
|
|
{ |
23
|
|
|
// void |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function addIncompleteTest(Test $test, Exception $e, $time) |
27
|
|
|
{ |
28
|
|
|
// void |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function addRiskyTest(Test $test, Exception $e, $time) |
32
|
|
|
{ |
33
|
|
|
// void |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function addSkippedTest(Test $test, Exception $e, $time) |
37
|
|
|
{ |
38
|
|
|
// void |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function addWarning(Test $test, Warning $e, $time) |
42
|
|
|
{ |
43
|
|
|
// void |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Makes clone of all test cases extending Phln\Build\PhpUnit\TestCase |
48
|
|
|
* and adds them to the test suite. |
49
|
|
|
* |
50
|
|
|
* Clonned test cases are set to use static methods from Phln bundle. |
51
|
|
|
* |
52
|
|
|
* @param TestSuite $suite |
53
|
|
|
*/ |
54
|
|
|
public function startTestSuite(TestSuite $suite) |
55
|
|
|
{ |
56
|
|
|
$tests = array_filter( |
57
|
|
|
$suite->tests(), |
58
|
|
|
function ($testCase) { |
59
|
|
|
return $testCase instanceof TestCase; |
60
|
|
|
} |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
foreach ($tests as $testCase) { |
64
|
|
|
/** @var TestCase $testCase */ |
65
|
|
|
$clone = clone $testCase; |
66
|
|
|
$clone->setTestedFnOverwrite($this->fnToBundleMethod($testCase->getTestedFn())); |
67
|
|
|
|
68
|
|
|
$suite->addTest($clone); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function fnToBundleMethod(string $fnName): string |
73
|
|
|
{ |
74
|
|
|
$name = class_basename($fnName); |
75
|
|
|
return "\phln\Phln::{$name}"; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function endTestSuite(TestSuite $suite) |
79
|
|
|
{ |
80
|
|
|
// void |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function startTest(Test $test) |
84
|
|
|
{ |
85
|
|
|
// void |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function endTest(Test $test, $time) |
89
|
|
|
{ |
90
|
|
|
// void |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|