Skip to content

Commit ee26212

Browse files
Slamdunksebastianbergmann
authored andcommitted
Rely only on ExecutableLinesFindingVisitorTest unit test for exec lines; adapt current reports
1 parent 49e73ff commit ee26212

27 files changed

+93
-1445
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
3939
*/
4040
private $executableLinesGroupedByBranch = [];
4141

42+
/**
43+
* @var array<int, bool>
44+
*/
4245
private $unsets = [];
4346

4447
public function __construct(string $source)

tests/TestCase.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,9 +1353,7 @@ protected function getExpectedLineCoverageDataArrayForBankAccount(): array
13531353
],
13541354
13 => [],
13551355
14 => [],
1356-
15 => [],
13571356
16 => [],
1358-
17 => [],
13591357
22 => [
13601358
0 => 'BankAccountTest::testBalanceCannotBecomeNegative2',
13611359
1 => 'BankAccountTest::testDepositWithdrawMoney',
@@ -1385,9 +1383,7 @@ protected function getExpectedLineCoverageDataArrayForBankAccountInReverseOrder(
13851383
],
13861384
13 => [],
13871385
14 => [],
1388-
15 => [],
13891386
16 => [],
1390-
17 => [],
13911387
22 => [
13921388
0 => 'BankAccountTest::testBalanceCannotBecomeNegative2',
13931389
1 => 'BankAccountTest::testDepositWithdrawMoney',

tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/source_with_ignore.php.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,13 @@
170170
<tr class=" d-flex"><td class="col-1 text-right"><a id="33" href="#33">33</a></td><td class="col-11 codeLine"><span class="keyword">interface</span><span class="default">&nbsp;</span><span class="default">Bor</span></td></tr>
171171
<tr class=" d-flex"><td class="col-1 text-right"><a id="34" href="#34">34</a></td><td class="col-11 codeLine"><span class="keyword">{</span></td></tr>
172172
<tr class=" d-flex"><td class="col-1 text-right"><a id="35" href="#35">35</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span class="default">&nbsp;</span><span class="keyword">function</span><span class="default">&nbsp;</span><span class="default">foo</span><span class="keyword">(</span><span class="keyword">)</span><span class="keyword">;</span></td></tr>
173-
<tr class=" d-flex"><td class="col-1 text-right"><a id="36" href="#36">36</a></td><td class="col-11 codeLine"></td></tr>
174-
<tr class=" d-flex"><td class="col-1 text-right"><a id="37" href="#37">37</a></td><td class="col-11 codeLine"><span class="keyword">}</span></td></tr>
173+
<tr class=" d-flex"><td class="col-1 text-right"><a id="36" href="#36">36</a></td><td class="col-11 codeLine"><span class="keyword">}</span></td></tr>
174+
<tr class=" d-flex"><td class="col-1 text-right"><a id="37" href="#37">37</a></td><td class="col-11 codeLine"></td></tr>
175+
<tr class=" d-flex"><td class="col-1 text-right"><a id="38" href="#38">38</a></td><td class="col-11 codeLine"><span class="comment">//&nbsp;@codeCoverageIgnoreStart</span></td></tr>
176+
<tr class=" d-flex"><td class="col-1 text-right"><a id="39" href="#39">39</a></td><td class="col-11 codeLine"><span class="keyword">print</span><span class="default">&nbsp;</span><span class="default">'</span></td></tr>
177+
<tr class=" d-flex"><td class="col-1 text-right"><a id="40" href="#40">40</a></td><td class="col-11 codeLine"><span class="default">Multiline</span></td></tr>
178+
<tr class=" d-flex"><td class="col-1 text-right"><a id="41" href="#41">41</a></td><td class="col-11 codeLine"><span class="default">'</span><span class="keyword">;</span></td></tr>
179+
<tr class=" d-flex"><td class="col-1 text-right"><a id="42" href="#42">42</a></td><td class="col-11 codeLine"><span class="comment">//&nbsp;@codeCoverageIgnoreEnd</span></td></tr>
175180

176181
</tbody>
177182
</table>

tests/_files/Report/HTML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</div>
5151
</td>
5252
<td class="success small"><div align="right">100.00%</div></td>
53-
<td class="success small"><div align="right">5&nbsp;/&nbsp;5</div></td>
53+
<td class="success small"><div align="right">8&nbsp;/&nbsp;8</div></td>
5454
<td class="success big"> <div class="progress">
5555
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
5656
<span class="sr-only">100.00% covered (success)</span>
@@ -79,7 +79,7 @@
7979
</div>
8080
</td>
8181
<td class="success small"><div align="right">100.00%</div></td>
82-
<td class="success small"><div align="right">5&nbsp;/&nbsp;5</div></td>
82+
<td class="success small"><div align="right">8&nbsp;/&nbsp;8</div></td>
8383
<td class="success big"> <div class="progress">
8484
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
8585
<span class="sr-only">100.00% covered (success)</span>
@@ -108,7 +108,7 @@
108108
</div>
109109
</td>
110110
<td class="success small"><div align="right">100.00%</div></td>
111-
<td class="success small"><div align="right">5&nbsp;/&nbsp;5</div></td>
111+
<td class="success small"><div align="right">8&nbsp;/&nbsp;8</div></td>
112112
<td class="success big"> <div class="progress">
113113
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
114114
<span class="sr-only">100.00% covered (success)</span>

tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</div>
5151
</td>
5252
<td class="success small"><div align="right">100.00%</div></td>
53-
<td class="success small"><div align="right">5&nbsp;/&nbsp;5</div></td>
53+
<td class="success small"><div align="right">8&nbsp;/&nbsp;8</div></td>
5454
<td class="success big"> <div class="progress">
5555
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
5656
<span class="sr-only">100.00% covered (success)</span>
@@ -78,7 +78,7 @@
7878
</div>
7979
</td>
8080
<td class="success small"><div align="right">100.00%</div></td>
81-
<td class="success small"><div align="right">5&nbsp;/&nbsp;5</div></td>
81+
<td class="success small"><div align="right">8&nbsp;/&nbsp;8</div></td>
8282
<td class="success big"> <div class="progress">
8383
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
8484
<span class="sr-only">100.00% covered (success)</span>

tests/_files/Report/HTML/PHP81AndUp/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</div>
5151
</td>
5252
<td class="success small"><div align="right">100.00%</div></td>
53-
<td class="success small"><div align="right">5&nbsp;/&nbsp;5</div></td>
53+
<td class="success small"><div align="right">8&nbsp;/&nbsp;8</div></td>
5454
<td class="success big"> <div class="progress">
5555
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
5656
<span class="sr-only">100.00% covered (success)</span>
@@ -79,7 +79,7 @@
7979
</div>
8080
</td>
8181
<td class="success small"><div align="right">100.00%</div></td>
82-
<td class="success small"><div align="right">5&nbsp;/&nbsp;5</div></td>
82+
<td class="success small"><div align="right">8&nbsp;/&nbsp;8</div></td>
8383
<td class="success big"> <div class="progress">
8484
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
8585
<span class="sr-only">100.00% covered (success)</span>
@@ -108,7 +108,7 @@
108108
</div>
109109
</td>
110110
<td class="success small"><div align="right">100.00%</div></td>
111-
<td class="success small"><div align="right">5&nbsp;/&nbsp;5</div></td>
111+
<td class="success small"><div align="right">8&nbsp;/&nbsp;8</div></td>
112112
<td class="success big"> <div class="progress">
113113
<div class="progress-bar bg-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
114114
<span class="sr-only">100.00% covered (success)</span>
@@ -136,11 +136,11 @@
136136
<tr class="covered-by-large-tests popin d-flex"><td data-title="1 test covers line 7" data-content="&lt;ul&gt;&lt;li&gt;ClassWithAnonymousFunction&lt;/li&gt;&lt;/ul&gt;" data-placement="top" data-html="true" class="col-1 text-right"><a id="7" href="#7">7</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="default">$filter</span><span class="default">&nbsp;</span><span class="keyword">=</span><span class="default">&nbsp;</span><span class="keyword">[</span><span class="default">'abc124'</span><span class="keyword">,</span><span class="default">&nbsp;</span><span class="default">'abc123'</span><span class="keyword">,</span><span class="default">&nbsp;</span><span class="default">'123'</span><span class="keyword">]</span><span class="keyword">;</span></td></tr>
137137
<tr class=" d-flex"><td class="col-1 text-right"><a id="8" href="#8">8</a></td><td class="col-11 codeLine"></td></tr>
138138
<tr class="covered-by-large-tests popin d-flex"><td data-title="1 test covers line 9" data-content="&lt;ul&gt;&lt;li&gt;ClassWithAnonymousFunction&lt;/li&gt;&lt;/ul&gt;" data-placement="top" data-html="true" class="col-1 text-right"><a id="9" href="#9">9</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="default">array_walk</span><span class="keyword">(</span></td></tr>
139-
<tr class=" d-flex"><td class="col-1 text-right"><a id="10" href="#10">10</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="default">$filter</span><span class="keyword">,</span></td></tr>
139+
<tr class="covered-by-large-tests popin d-flex"><td data-title="1 test covers line 10" data-content="&lt;ul&gt;&lt;li&gt;ClassWithAnonymousFunction&lt;/li&gt;&lt;/ul&gt;" data-placement="top" data-html="true" class="col-1 text-right"><a id="10" href="#10">10</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="default">$filter</span><span class="keyword">,</span></td></tr>
140140
<tr class="covered-by-large-tests popin d-flex"><td data-title="1 test covers line 11" data-content="&lt;ul&gt;&lt;li&gt;ClassWithAnonymousFunction&lt;/li&gt;&lt;/ul&gt;" data-placement="top" data-html="true" class="col-1 text-right"><a id="11" href="#11">11</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">function</span><span class="default">&nbsp;</span><span class="keyword">(</span><span class="default">&amp;</span><span class="default">$val</span><span class="keyword">,</span><span class="default">&nbsp;</span><span class="default">$key</span><span class="keyword">)</span><span class="default">&nbsp;</span><span class="keyword">{</span></td></tr>
141141
<tr class="covered-by-large-tests popin d-flex"><td data-title="1 test covers line 12" data-content="&lt;ul&gt;&lt;li&gt;ClassWithAnonymousFunction&lt;/li&gt;&lt;/ul&gt;" data-placement="top" data-html="true" class="col-1 text-right"><a id="12" href="#12">12</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="default">$val</span><span class="default">&nbsp;</span><span class="keyword">=</span><span class="default">&nbsp;</span><span class="default">preg_replace</span><span class="keyword">(</span><span class="default">'|[^0-9]|'</span><span class="keyword">,</span><span class="default">&nbsp;</span><span class="default">''</span><span class="keyword">,</span><span class="default">&nbsp;</span><span class="default">$val</span><span class="keyword">)</span><span class="keyword">;</span></td></tr>
142-
<tr class=" d-flex"><td class="col-1 text-right"><a id="13" href="#13">13</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">}</span></td></tr>
143-
<tr class=" d-flex"><td class="col-1 text-right"><a id="14" href="#14">14</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">)</span><span class="keyword">;</span></td></tr>
142+
<tr class="covered-by-large-tests popin d-flex"><td data-title="1 test covers line 13" data-content="&lt;ul&gt;&lt;li&gt;ClassWithAnonymousFunction&lt;/li&gt;&lt;/ul&gt;" data-placement="top" data-html="true" class="col-1 text-right"><a id="13" href="#13">13</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">}</span></td></tr>
143+
<tr class="covered-by-large-tests popin d-flex"><td data-title="1 test covers line 14" data-content="&lt;ul&gt;&lt;li&gt;ClassWithAnonymousFunction&lt;/li&gt;&lt;/ul&gt;" data-placement="top" data-html="true" class="col-1 text-right"><a id="14" href="#14">14</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">)</span><span class="keyword">;</span></td></tr>
144144
<tr class=" d-flex"><td class="col-1 text-right"><a id="15" href="#15">15</a></td><td class="col-11 codeLine"></td></tr>
145145
<tr class=" d-flex"><td class="col-1 text-right"><a id="16" href="#16">16</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;Should&nbsp;be&nbsp;covered</span></td></tr>
146146
<tr class="covered-by-large-tests popin d-flex"><td data-title="1 test covers line 17" data-content="&lt;ul&gt;&lt;li&gt;ClassWithAnonymousFunction&lt;/li&gt;&lt;/ul&gt;" data-placement="top" data-html="true" class="col-1 text-right"><a id="17" href="#17">17</a></td><td class="col-11 codeLine"><span class="default">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="default">$extravar</span><span class="default">&nbsp;</span><span class="keyword">=</span><span class="default">&nbsp;</span><span class="default">true</span><span class="keyword">;</span></td></tr>

tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
</tests>
1111
<directory name="%s">
1212
<totals>
13-
<lines total="38" comments="9" code="29" executable="1" executed="1" percent="100.00"/>
13+
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
1414
<methods count="0" tested="0" percent="0"/>
1515
<functions count="1" tested="1" percent="100.00"/>
1616
<classes count="0" tested="0" percent="0"/>
1717
<traits count="0" tested="0" percent="0"/>
1818
</totals>
1919
<file name="source_with_ignore.php" href="source_with_ignore.php.xml">
2020
<totals>
21-
<lines total="38" comments="9" code="29" executable="1" executed="1" percent="100.00"/>
21+
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
2222
<methods count="0" tested="0" percent="0"/>
2323
<functions count="1" tested="1" percent="100.00"/>
2424
<classes count="0" tested="0" percent="0"/>

tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<phpunit xmlns="https://schema.phpunit.de/coverage/1.0">
33
<file name="source_with_ignore.php" path="%e">
44
<totals>
5-
<lines total="38" comments="9" code="29" executable="1" executed="1" percent="100.00"/>
5+
<lines total="43" comments="11" code="32" executable="1" executed="1" percent="100.00"/>
66
<methods count="0" tested="0" percent="0"/>
77
<functions count="1" tested="1" percent="100.00"/>
88
<classes count="0" tested="0" percent="0"/>
@@ -175,11 +175,29 @@
175175
<token name="T_CLOSE_BRACKET">)</token>
176176
<token name="T_SEMICOLON">;</token>
177177
</line>
178-
<line no="36"/>
179-
<line no="37">
178+
<line no="36">
180179
<token name="T_CLOSE_CURLY">}</token>
181180
</line>
182-
<line no="38"/>
181+
<line no="37"/>
182+
<line no="38">
183+
<token name="T_COMMENT">// @codeCoverageIgnoreStart</token>
184+
</line>
185+
<line no="39">
186+
<token name="T_PRINT">print</token>
187+
<token name="T_WHITESPACE"> </token>
188+
<token name="T_CONSTANT_ENCAPSED_STRING">'</token>
189+
</line>
190+
<line no="40">
191+
<token name="T_CONSTANT_ENCAPSED_STRING">Multiline</token>
192+
</line>
193+
<line no="41">
194+
<token name="T_CONSTANT_ENCAPSED_STRING">'</token>
195+
<token name="T_SEMICOLON">;</token>
196+
</line>
197+
<line no="42">
198+
<token name="T_COMMENT">// @codeCoverageIgnoreEnd</token>
199+
</line>
200+
<line no="43"/>
183201
</source>
184202
</file>
185203
</phpunit>

tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/index.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
</tests>
1111
<directory name="%s">
1212
<totals>
13-
<lines total="20" comments="1" code="19" executable="5" executed="5" percent="100.00"/>
13+
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
1414
<methods count="1" tested="1" percent="100.00"/>
1515
<functions count="0" tested="0" percent="0"/>
1616
<classes count="1" tested="1" percent="100.00"/>
1717
<traits count="0" tested="0" percent="0"/>
1818
</totals>
1919
<file name="source_with_class_and_anonymous_function.php" href="source_with_class_and_anonymous_function.php.xml">
2020
<totals>
21-
<lines total="20" comments="1" code="19" executable="5" executed="5" percent="100.00"/>
21+
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
2222
<methods count="1" tested="1" percent="100.00"/>
2323
<functions count="0" tested="0" percent="0"/>
2424
<classes count="1" tested="1" percent="100.00"/>

tests/_files/Report/XML/PHP80AndBelow/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<phpunit xmlns="https://schema.phpunit.de/coverage/1.0">
33
<file name="source_with_class_and_anonymous_function.php" path="%e">
44
<totals>
5-
<lines total="20" comments="1" code="19" executable="5" executed="5" percent="100.00"/>
5+
<lines total="20" comments="1" code="19" executable="8" executed="8" percent="100.00"/>
66
<methods count="1" tested="1" percent="100.00"/>
77
<functions count="0" tested="0" percent="0"/>
88
<classes count="1" tested="1" percent="100.00"/>
99
<traits count="0" tested="0" percent="0"/>
1010
</totals>
11-
<class name="CoveredClassWithAnonymousFunctionInStaticMethod" start="3" executable="5" executed="5" crap="1">
11+
<class name="CoveredClassWithAnonymousFunctionInStaticMethod" start="3" executable="8" executed="8" crap="1">
1212
<namespace name=""/>
13-
<method name="runAnonymous" signature="runAnonymous()" start="5" end="18" crap="1" executable="5" executed="5" coverage="100"/>
13+
<method name="runAnonymous" signature="runAnonymous()" start="5" end="18" crap="1" executable="8" executed="8" coverage="100"/>
1414
</class>
1515
<coverage>
1616
<line nr="7">
@@ -19,12 +19,21 @@
1919
<line nr="9">
2020
<covered by="ClassWithAnonymousFunction"/>
2121
</line>
22+
<line nr="10">
23+
<covered by="ClassWithAnonymousFunction"/>
24+
</line>
2225
<line nr="11">
2326
<covered by="ClassWithAnonymousFunction"/>
2427
</line>
2528
<line nr="12">
2629
<covered by="ClassWithAnonymousFunction"/>
2730
</line>
31+
<line nr="13">
32+
<covered by="ClassWithAnonymousFunction"/>
33+
</line>
34+
<line nr="14">
35+
<covered by="ClassWithAnonymousFunction"/>
36+
</line>
2837
<line nr="17">
2938
<covered by="ClassWithAnonymousFunction"/>
3039
</line>

0 commit comments

Comments
 (0)