|
1 |
| -<?php |
| 1 | +<?php // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols |
2 | 2 |
|
3 |
| -namespace mheap\GithubActionsReporter; |
4 |
| - |
5 |
| -use PHPUnit\Framework\TestResult; |
6 |
| -use PHPUnit\Framework\TestFailure; |
7 |
| -use PHPUnit\TextUI\ResultPrinter; |
8 |
| - |
9 |
| -class Printer extends ResultPrinter |
10 |
| -{ |
11 |
| - protected $currentType = null; |
12 |
| - |
13 |
| - protected function printHeader(TestResult $result): void |
14 |
| - { |
15 |
| - } |
16 |
| - |
17 |
| - protected function writeProgress(string $progress): void |
18 |
| - { |
19 |
| - } |
20 |
| - |
21 |
| - protected function printFooter(TestResult $result): void |
22 |
| - { |
23 |
| - } |
24 |
| - |
25 |
| - protected function printDefects(array $defects, string $type): void |
26 |
| - { |
27 |
| - $this->currentType = $type; |
28 |
| - |
29 |
| - foreach ($defects as $i => $defect) { |
30 |
| - $this->printDefect($defect, $i); |
31 |
| - } |
32 |
| - } |
| 3 | +// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses |
33 | 4 |
|
34 |
| - protected function printDefectHeader(TestFailure $defect, int $count): void |
35 |
| - { |
36 |
| - } |
37 |
| - |
38 |
| - protected function printDefectTrace(TestFailure $defect): void |
39 |
| - { |
40 |
| - $e = $defect->thrownException(); |
41 |
| - |
42 |
| - $errorLines = array_filter( |
43 |
| - explode("\n", (string)$e), |
44 |
| - function ($l) { |
45 |
| - return $l; |
46 |
| - } |
47 |
| - ); |
48 |
| - |
49 |
| - $error = end($errorLines); |
50 |
| - $lineIndex = strrpos($error, ":"); |
51 |
| - $path = substr($error, 0, $lineIndex); |
52 |
| - $line = substr($error, $lineIndex + 1); |
53 |
| - |
54 |
| - list($reflectedPath, $reflectedLine) = $this->getReflectionFromTest( |
55 |
| - $defect->getTestName() |
56 |
| - ); |
57 |
| - |
58 |
| - if($path !== $reflectedPath) { |
59 |
| - $path = $reflectedPath; |
60 |
| - $line = $reflectedLine; |
61 |
| - } |
| 5 | +namespace mheap\GithubActionsReporter; |
62 | 6 |
|
63 |
| - $message = explode("\n", $defect->getExceptionAsString()); |
64 |
| - $message = implode('%0A', $message); |
| 7 | +use PHPUnit\Runner\Version; |
| 8 | +use PHPUnit_TextUI_ResultPrinter; |
65 | 9 |
|
66 |
| - $type = $this->getCurrentType(); |
67 |
| - $file = "file={$this->relativePath($path)}"; |
68 |
| - $line = "line={$line}"; |
69 |
| - $this->write("::{$type} $file,$line::{$message}\n"); |
70 |
| - } |
| 10 | +$low = version_compare(Version::series(), '8.0', '>='); |
| 11 | +$high = version_compare(Version::series(), '8.99.99', '<='); |
71 | 12 |
|
72 |
| - protected function getCurrentType() |
| 13 | +if ($low && $high) { |
| 14 | + class Printer extends Printer8 |
73 | 15 | {
|
74 |
| - if (in_array($this->currentType, ['error', 'failure'])) { |
75 |
| - return 'error'; |
76 |
| - } |
77 |
| - |
78 |
| - return 'warning'; |
79 | 16 | }
|
| 17 | +} |
80 | 18 |
|
81 |
| - protected function relativePath(string $path) |
82 |
| - { |
83 |
| - $relative = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path); |
84 |
| - // Translate \ in to / for Windows |
85 |
| - $relative = str_replace('\\', '/', $relative); |
86 |
| - return $relative; |
87 |
| - } |
| 19 | +$low = version_compare(Version::series(), '9.0', '>='); |
| 20 | +$high = true; // version_compare(Version::series(),'8.99.99','<='); |
88 | 21 |
|
89 |
| - protected function getReflectionFromTest(string $name) |
| 22 | +if ($low && $high) { |
| 23 | + class Printer extends Printer9 |
90 | 24 | {
|
91 |
| - list($klass, $method) = explode('::', $name); |
92 |
| - $c = new \ReflectionClass($klass); |
93 |
| - $m = $c->getMethod($method); |
94 |
| - |
95 |
| - return [$m->getFileName(), $m->getStartLine()]; |
96 | 25 | }
|
97 | 26 | }
|
0 commit comments