Skip to content

Commit

Permalink
Add test for #967
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 29, 2024
1 parent 2096eca commit 9b0a889
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/_files/source_match_expression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
final class MatchExpr
{
public int $result;

public function __construct(int $value)
{
$this->result = match ($value) {
0 => 4,
1 => 5,
2 => 6,
3 => 7,
default => 8,
};
}
}
27 changes: 27 additions & 0 deletions tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;

use PHPUnit\Framework\Attributes\Ticket;
use function explode;
use function file_get_contents;
use function preg_match;
Expand Down Expand Up @@ -39,6 +40,32 @@ public function testExecutableLinesAreGroupedByBranchPhp82(): void
$this->doTestSelfDescribingAssert(TEST_FILES_PATH . 'source_for_branched_exec_lines_php82.php');
}

#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/967')]
public function testMatchArmsAreProcessedCorrectly(): void
{
$source = file_get_contents(__DIR__ . '/../../_files/source_match_expression.php');
$parser = (new ParserFactory)->createForHostVersion();
$nodes = $parser->parse($source);
$executableLinesFindingVisitor = new ExecutableLinesFindingVisitor($source);

$traverser = new NodeTraverser;
$traverser->addVisitor($executableLinesFindingVisitor);
$traverser->traverse($nodes);

$this->assertSame(
[
8 => 2,
9 => 3,
10 => 4,
11 => 5,
12 => 6,
13 => 7,
14 => 2,
],
$executableLinesFindingVisitor->executableLinesGroupedByBranch(),
);
}

private function doTestSelfDescribingAssert(string $filename): void
{
$source = file_get_contents($filename);
Expand Down

0 comments on commit 9b0a889

Please sign in to comment.