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\CodeCoverage; |
15
|
|
|
|
16
|
|
|
use SebastianBergmann\CodeCoverage\CodeCoverage; |
17
|
|
|
use SebastianBergmann\CodeCoverage\Driver\Driver; |
18
|
|
|
use SebastianBergmann\CodeCoverage\Filter; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Provide bridge to PHP Code Coverage. |
22
|
|
|
*/ |
23
|
|
|
class Processor implements ProcessorInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var CodeCoverage |
27
|
|
|
*/ |
28
|
|
|
private $codeCoverage; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var TestCase[] |
32
|
|
|
*/ |
33
|
|
|
private $testCases = []; |
34
|
|
|
|
35
|
|
|
private $completed = false; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Driver |
39
|
|
|
*/ |
40
|
|
|
private $driver; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Filter |
44
|
|
|
*/ |
45
|
|
|
private $filter; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
private $coverageOptions; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var TestCase |
54
|
|
|
*/ |
55
|
|
|
private $currentTestCase; |
56
|
|
|
|
57
|
|
|
public function __construct($driver = null, $filter = null) |
58
|
|
|
{ |
59
|
|
|
$this->driver = $driver; |
60
|
|
|
$this->filter = $filter; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setCurrentTestCase(TestCase $testCase) |
64
|
|
|
{ |
65
|
|
|
$this->currentTestCase = $testCase; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getCurrentTestCase() |
69
|
|
|
{ |
70
|
|
|
return $this->currentTestCase; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function setCodeCoverageOptions(array $options) |
74
|
|
|
{ |
75
|
|
|
$this->coverageOptions = $options; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getCodeCoverageOptions() |
79
|
|
|
{ |
80
|
|
|
return $this->coverageOptions; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getCodeCoverageFilter() |
84
|
|
|
{ |
85
|
|
|
return $this->filter; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function start(TestCase $testCase, $clear = false) |
89
|
|
|
{ |
90
|
|
|
$this->setCurrentTestCase($testCase); |
91
|
|
|
$this->addTestCase($testCase); |
92
|
|
|
$this->getCodeCoverage()->start($testCase->getName(), $clear); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function stop(bool $append = true, $linesToBeCovered = [], array $linesToBeUsed = [], bool $ignoreForceCoversAnnotation = false): array |
96
|
|
|
{ |
97
|
|
|
return $this->getCodeCoverage()->stop($append, $linesToBeCovered, $linesToBeUsed, $ignoreForceCoversAnnotation); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function merge($processor) |
101
|
|
|
{ |
102
|
|
|
$codeCoverage = $processor; |
103
|
|
|
if ($processor instanceof self) { |
104
|
|
|
$codeCoverage = $processor->getCodeCoverage(); |
105
|
|
|
} |
106
|
|
|
$this->getCodeCoverage()->merge($codeCoverage); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function clear() |
110
|
|
|
{ |
111
|
|
|
$this->getCodeCoverage()->clear(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function setCodeCoverage(CodeCoverage $codeCoverage) |
115
|
|
|
{ |
116
|
|
|
$this->codeCoverage = $codeCoverage; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return CodeCoverage |
121
|
|
|
*/ |
122
|
|
|
public function getCodeCoverage() |
123
|
|
|
{ |
124
|
|
|
if (null === $this->codeCoverage) { |
125
|
|
|
$this->codeCoverage = new CodeCoverage($this->driver, $this->filter); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $this->codeCoverage; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function addTestCase(TestCase $testCase) |
132
|
|
|
{ |
133
|
|
|
$this->testCases[$testCase->getName()] = $testCase; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function complete() |
137
|
|
|
{ |
138
|
|
|
$coverage = $this->getCodeCoverage(); |
139
|
|
|
$testCases = $this->testCases; |
140
|
|
|
$tests = $coverage->getTests(); |
141
|
|
|
|
142
|
|
|
foreach ($testCases as $testCase) { |
143
|
|
|
$name = $testCase->getName(); |
144
|
|
|
$tests[$name]['status'] = $testCase->getResult(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$coverage->setTests($tests); |
148
|
|
|
$this->completed = true; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|