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