1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the doyo/behat-code-coverage project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Doyo\Behat\Coverage\Bridge; |
15
|
|
|
|
16
|
|
|
use Doyo\Behat\Coverage\Event\ReportEvent; |
17
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
18
|
|
|
|
19
|
|
|
class Report implements EventSubscriberInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var object |
23
|
|
|
*/ |
24
|
|
|
private $reportProcessor; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $name; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $target; |
35
|
|
|
|
36
|
5 |
|
public static function getSubscribedEvents() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
5 |
|
ReportEvent::PROCESS => 'onReportProcess', |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return object |
45
|
|
|
*/ |
46
|
1 |
|
public function getReportProcessor() |
47
|
|
|
{ |
48
|
1 |
|
return $this->reportProcessor; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param object $reportProcessor |
53
|
|
|
* |
54
|
|
|
* @return Report |
55
|
|
|
*/ |
56
|
7 |
|
public function setReportProcessor($reportProcessor) |
57
|
|
|
{ |
58
|
7 |
|
$this->reportProcessor = $reportProcessor; |
59
|
|
|
|
60
|
7 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
1 |
|
public function getName() |
67
|
|
|
{ |
68
|
1 |
|
return $this->name; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $name |
73
|
|
|
* |
74
|
|
|
* @return Report |
75
|
|
|
*/ |
76
|
6 |
|
public function setName($name) |
77
|
|
|
{ |
78
|
6 |
|
$this->name = $name; |
79
|
|
|
|
80
|
6 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
1 |
|
public function getTarget() |
87
|
|
|
{ |
88
|
1 |
|
return $this->target; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $target |
93
|
|
|
* |
94
|
|
|
* @return Report |
95
|
|
|
*/ |
96
|
6 |
|
public function setTarget($target) |
97
|
|
|
{ |
98
|
6 |
|
$this->target = $target; |
99
|
|
|
|
100
|
6 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
5 |
|
public function onReportProcess(ReportEvent $event) |
104
|
|
|
{ |
105
|
5 |
|
$coverage = $event->getProcessor()->getCodeCoverage(); |
106
|
5 |
|
$io = $event->getConsoleIO(); |
107
|
|
|
|
108
|
|
|
try { |
109
|
5 |
|
$this->reportProcessor->process($coverage, $this->target, $this->name); |
110
|
4 |
|
$io->text( |
111
|
4 |
|
sprintf( |
112
|
4 |
|
'<info><comment>%s</comment> processed to: <comment>%s</comment></info>', |
113
|
4 |
|
$this->name, |
114
|
4 |
|
$this->target |
115
|
|
|
)); |
116
|
1 |
|
} catch (\Exception $e) { |
117
|
1 |
|
$message = sprintf( |
118
|
1 |
|
"failed to generate %s report. with Processor message:\n%s", |
119
|
1 |
|
$this->name, |
120
|
1 |
|
$e->getMessage() |
121
|
|
|
); |
122
|
1 |
|
$io->error($message); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|