Skip to content

Commit e9a72da

Browse files
Slamdunksebastianbergmann
authored andcommitted
Tests different features only for related supported by PHP versions
1 parent ee26212 commit e9a72da

File tree

4 files changed

+65
-43
lines changed

4 files changed

+65
-43
lines changed

tests/_files/source_for_branched_exec_lines.php

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -239,37 +239,6 @@ public function withSwitch()
239239
++$var; // +1
240240
endswitch;
241241
}
242-
public function withMatch()
243-
{
244-
$var = 1; // +1
245-
$var2 = match ($var) { // +1
246-
0 => ++$var, // 0
247-
1 => ++$var, // 0
248-
default => ++$var, // 0
249-
}; // 0
250-
$var2 // +1
251-
= // 0
252-
match // 0
253-
( // 0
254-
$var // 0
255-
) // 0
256-
{ // 0
257-
0 // 0
258-
=> // 0
259-
++$var // 0
260-
, // 0
261-
1, // 0
262-
2 // 0
263-
=> // 0
264-
++$var // 0
265-
, // 0
266-
default // 0
267-
=> // 0
268-
++$var // 0
269-
, // 0
270-
} // 0
271-
; // 0
272-
}
273242
public function withReturn()
274243
{
275244
$var = 1; // +1
@@ -415,8 +384,6 @@ public function withCall()
415384
) // 0
416385
; // 0
417386
++$var; // +1
418-
$ymd = $date?->format('Ymd'); // +1
419-
++$var; // +1
420387
$date = \DateTime::createFromImmutable($date); // +1
421388
$date // +1
422389
= // 0
@@ -485,17 +452,10 @@ public function myMethod()
485452
} // -3
486453
; // 0
487454
}
488-
public function withArrowFn()
489-
{
490-
$y = 1; // +4
491-
$fn1 = fn($x) => $x + $y; // +1
492-
$fn1 = fn($x) => // +1
493-
$x + $y; // +1
494-
}
495455
public function withComments()
496456
{
497457
/** @var int $var */
498-
$var = 1; // +1
458+
$var = 1; // +4
499459
/** @var int $var */
500460
$var = 2; // +1
501461
// C3
@@ -567,7 +527,7 @@ final class MyFinalClass extends MyAbstractClass
567527
public const STRUCT = [
568528
'foo' => 'bar',
569529
];
570-
private readonly string $var;
530+
private string $var;
571531
public function myMethod(): void
572532
{
573533
} // +4
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
// Arrow functions
4+
$fn1 = fn($x) => $x + $y; // +1
5+
$fn1 = fn($x) => // +1
6+
$x + $y; // +1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
// Match
4+
$var = 1; // +1
5+
$var2 = match ($var) { // +1
6+
0 => ++$var, // 0
7+
1 => ++$var, // 0
8+
default => ++$var, // 0
9+
}; // 0
10+
$var2 // +1
11+
= // 0
12+
match // 0
13+
( // 0
14+
$var // 0
15+
) // 0
16+
{ // 0
17+
0 // 0
18+
=> // 0
19+
++$var // 0
20+
, // 0
21+
1, // 0
22+
2 // 0
23+
=> // 0
24+
++$var // 0
25+
, // 0
26+
default // 0
27+
=> // 0
28+
++$var // 0
29+
, // 0
30+
} // 0
31+
; // 0
32+
33+
// Nullsafe Operator
34+
$ymd = $date?->format('Ymd'); // +1
35+
++$var; // +1

tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,28 @@ final class ExecutableLinesFindingVisitorTest extends TestCase
2424
{
2525
public function testExecutableLinesAreGroupedByBranch(): void
2626
{
27-
$source = file_get_contents(TEST_FILES_PATH . 'source_for_branched_exec_lines.php');
27+
$this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines.php');
28+
}
29+
30+
/**
31+
* @requires PHP 7.4
32+
*/
33+
public function testExecutableLinesAreGroupedByBranchPhp74(): void
34+
{
35+
$this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php74.php');
36+
}
37+
38+
/**
39+
* @requires PHP 8
40+
*/
41+
public function testExecutableLinesAreGroupedByBranchPhp80(): void
42+
{
43+
$this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php80.php');
44+
}
45+
46+
private function doTestSelfDescribingAsset(string $filename): void
47+
{
48+
$source = file_get_contents($filename);
2849
$parser = (new ParserFactory)->create(
2950
ParserFactory::PREFER_PHP7,
3051
new Lexer

0 commit comments

Comments
 (0)