1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the doyo/behat-coverage-extension 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\Event; |
15
|
|
|
|
16
|
|
|
use Doyo\Behat\Coverage\Bridge\Symfony\Event; |
17
|
|
|
|
18
|
|
|
class CoverageEvent extends Event |
19
|
|
|
{ |
20
|
|
|
const BEFORE_START = 'doyo.coverage.start.pre'; |
21
|
|
|
const BEFORE_STOP = 'doyo.coverage.stop.pre'; |
22
|
|
|
const BEFORE_REFRESH = 'doyo.coverage.refresh.pre'; |
23
|
|
|
const START = 'doyo.coverage.start'; |
24
|
|
|
const STOP = 'doyo.coverage.stop'; |
25
|
|
|
const REFRESH = 'doyo.coverage.refresh'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $coverageId; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private $coverage; |
36
|
|
|
|
37
|
9 |
|
public function __construct($coverageId = null) |
38
|
|
|
{ |
39
|
9 |
|
$this->coverageId = $coverageId; |
40
|
9 |
|
$this->coverage = []; |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
public function updateCoverage($coverage) |
44
|
|
|
{ |
45
|
1 |
|
$aggregate = $this->coverage; |
46
|
|
|
|
47
|
1 |
|
foreach ($coverage as $class => $counts) { |
48
|
1 |
|
if (!isset($this->coverage[$class])) { |
49
|
1 |
|
$aggregate[$class] = $counts; |
50
|
1 |
|
continue; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
foreach ($counts as $line => $status) { |
54
|
|
|
$status = !$status ? -1 : ($status > 1 ? 1 : $status); |
55
|
|
|
$aggregate[$class][$line] = $status; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
$this->coverage = $aggregate; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public function setCoverage(array $coverage) |
63
|
|
|
{ |
64
|
1 |
|
$this->coverage = $coverage; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
1 |
|
public function getCoverage() |
71
|
|
|
{ |
72
|
1 |
|
return $this->coverage; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
1 |
|
public function getCoverageId(): string |
79
|
|
|
{ |
80
|
1 |
|
return $this->coverageId; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string|null $coverageId |
85
|
|
|
*/ |
86
|
1 |
|
public function setCoverageId($coverageId=null) |
87
|
|
|
{ |
88
|
1 |
|
$this->coverageId = $coverageId; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|