|
17 | 17 | use PhpParser\ParserFactory; |
18 | 18 | use PHPUnit\Framework\Attributes\CoversClass; |
19 | 19 | use PHPUnit\Framework\Attributes\RequiresPhp; |
| 20 | +use PHPUnit\Framework\Attributes\Ticket; |
20 | 21 | use PHPUnit\Framework\TestCase; |
21 | 22 |
|
22 | 23 | #[CoversClass(ExecutableLinesFindingVisitor::class)] |
23 | 24 | final class ExecutableLinesFindingVisitorTest extends TestCase |
24 | 25 | { |
25 | 26 | public function testExecutableLinesAreGroupedByBranch(): void |
26 | 27 | { |
27 | | - $this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines.php'); |
| 28 | + $this->doTestSelfDescribingAssert(TEST_FILES_PATH . 'source_for_branched_exec_lines.php'); |
28 | 29 | } |
29 | 30 |
|
30 | 31 | #[RequiresPhp('>=8.1')] |
31 | 32 | public function testExecutableLinesAreGroupedByBranchPhp81(): void |
32 | 33 | { |
33 | | - $this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php81.php'); |
| 34 | + $this->doTestSelfDescribingAssert(TEST_FILES_PATH . 'source_for_branched_exec_lines_php81.php'); |
34 | 35 | } |
35 | 36 |
|
36 | 37 | #[RequiresPhp('>=8.2')] |
37 | 38 | public function testExecutableLinesAreGroupedByBranchPhp82(): void |
38 | 39 | { |
39 | | - $this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php82.php'); |
| 40 | + $this->doTestSelfDescribingAssert(TEST_FILES_PATH . 'source_for_branched_exec_lines_php82.php'); |
40 | 41 | } |
41 | 42 |
|
42 | | - private function doTestSelfDescribingAsset(string $filename): void |
| 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 | + |
| 69 | + private function doTestSelfDescribingAssert(string $filename): void |
43 | 70 | { |
44 | 71 | $source = file_get_contents($filename); |
45 | 72 | $parser = (new ParserFactory)->createForHostVersion(); |
|
0 commit comments