1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Api\Inspector\Test; |
6
|
|
|
|
7
|
|
|
use Codeception\Event\FailEvent; |
8
|
|
|
use Codeception\Event\PrintResultEvent; |
9
|
|
|
use Codeception\Event\TestEvent; |
10
|
|
|
use Codeception\Events; |
11
|
|
|
use Codeception\Extension; |
12
|
|
|
use Codeception\Test\Descriptor; |
13
|
|
|
|
14
|
|
|
final class CodeceptionJSONReporter extends Extension |
15
|
|
|
{ |
16
|
|
|
protected array $config = [ |
17
|
|
|
'output-path' => __DIR__, |
18
|
|
|
]; |
19
|
|
|
private array $data = []; |
20
|
|
|
public const FILENAME = 'codeception-report.json'; |
21
|
|
|
|
22
|
|
|
public function _initialize(): void |
23
|
|
|
{ |
24
|
|
|
$this->_reconfigure(['settings' => ['silent' => true]]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public static array $events = [ |
28
|
|
|
Events::TEST_SUCCESS => 'success', |
29
|
|
|
Events::TEST_FAIL => 'fail', |
30
|
|
|
Events::TEST_ERROR => 'error', |
31
|
|
|
Events::RESULT_PRINT_AFTER => 'all', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
public function success(TestEvent $event): void |
35
|
|
|
{ |
36
|
|
|
$this->data[] = [ |
37
|
|
|
'file' => $this->getTestFilename($event), |
38
|
|
|
'test' => $this->getTestName($event), |
39
|
|
|
'status' => 'ok', |
40
|
|
|
'stacktrace' => [], |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function fail(FailEvent $event): void |
45
|
|
|
{ |
46
|
|
|
$this->data[] = [ |
47
|
|
|
'file' => $this->getTestFilename($event), |
48
|
|
|
'test' => $this->getTestName($event), |
49
|
|
|
'status' => 'fail', |
50
|
|
|
'stacktrace' => $event->getFail()->getTrace(), |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function error(FailEvent $event): void |
55
|
|
|
{ |
56
|
|
|
$this->data[] = [ |
57
|
|
|
'file' => $this->getTestFilename($event), |
58
|
|
|
'test' => $this->getTestName($event), |
59
|
|
|
'status' => 'error', |
60
|
|
|
'stacktrace' => $event->getFail()->getTrace(), |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function all(PrintResultEvent $event): void |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
file_put_contents($this->config['output-path'] . DIRECTORY_SEPARATOR . self::FILENAME, json_encode($this->data)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function getTestName(TestEvent $event): string |
70
|
|
|
{ |
71
|
|
|
return Descriptor::getTestFullName($event->getTest()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function getTestFilename(TestEvent $event): string |
75
|
|
|
{ |
76
|
|
|
return Descriptor::getTestFileName($event->getTest()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.