File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+ final class MatchExpr
3+ {
4+ public int $ result ;
5+
6+ public function __construct (int $ value )
7+ {
8+ $ this ->result = match ($ value ) {
9+ 0 => 4 ,
10+ 1 => 5 ,
11+ 2 => 6 ,
12+ 3 => 7 ,
13+ default => 8 ,
14+ };
15+ }
16+ }
Original file line number Diff line number Diff line change 99 */
1010namespace SebastianBergmann \CodeCoverage \StaticAnalysis ;
1111
12+ use PHPUnit \Framework \Attributes \Ticket ;
1213use function explode ;
1314use function file_get_contents ;
1415use function preg_match ;
@@ -39,6 +40,32 @@ public function testExecutableLinesAreGroupedByBranchPhp82(): void
3940 $ this ->doTestSelfDescribingAssert (TEST_FILES_PATH . 'source_for_branched_exec_lines_php82.php ' );
4041 }
4142
43+ #[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/967 ' )]
44+ public function testMatchArmsAreProcessedCorrectly (): void
45+ {
46+ $ source = file_get_contents (__DIR__ . '/../../_files/source_match_expression.php ' );
47+ $ parser = (new ParserFactory )->createForHostVersion ();
48+ $ nodes = $ parser ->parse ($ source );
49+ $ executableLinesFindingVisitor = new ExecutableLinesFindingVisitor ($ source );
50+
51+ $ traverser = new NodeTraverser ;
52+ $ traverser ->addVisitor ($ executableLinesFindingVisitor );
53+ $ traverser ->traverse ($ nodes );
54+
55+ $ this ->assertSame (
56+ [
57+ 8 => 2 ,
58+ 9 => 3 ,
59+ 10 => 4 ,
60+ 11 => 5 ,
61+ 12 => 6 ,
62+ 13 => 7 ,
63+ 14 => 2 ,
64+ ],
65+ $ executableLinesFindingVisitor ->executableLinesGroupedByBranch (),
66+ );
67+ }
68+
4269 private function doTestSelfDescribingAssert (string $ filename ): void
4370 {
4471 $ source = file_get_contents ($ filename );
You can’t perform that action at this time.
0 commit comments