|
| 1 | +--TEST-- |
| 2 | +Test for bug #1674: Inconsistent Path & Branch Coverage Reported |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +require __DIR__ . '/../utils.inc'; |
| 6 | +?> |
| 7 | +--INI-- |
| 8 | +xdebug.mode=coverage |
| 9 | +--FILE-- |
| 10 | +<?php |
| 11 | +declare(strict_types=1); |
| 12 | + |
| 13 | +require __DIR__ . '/../utils.inc'; |
| 14 | + |
| 15 | +use Xdebug\SampleClass; |
| 16 | +use Xdebug\SampleStaticClass; |
| 17 | + |
| 18 | +\xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE | XDEBUG_CC_BRANCH_CHECK); |
| 19 | +require_once __DIR__ . '/bug01674-SampleStaticClass.inc'; |
| 20 | +require_once __DIR__ . '/bug01674-SampleClass.inc'; |
| 21 | +\xdebug_stop_code_coverage(true); |
| 22 | + |
| 23 | +$resultPrinter = static function (array $results, int $run) { |
| 24 | + foreach ($results as $file => $result) { |
| 25 | + if (\strpos($file, 'bug01674-SampleStaticClass.inc') === false && \strpos($file, 'bug01674-SampleClass.inc') === false) { |
| 26 | + continue; |
| 27 | + } |
| 28 | + |
| 29 | + $expected = 9; |
| 30 | + if (\strpos($file, 'SampleClass.php')) { |
| 31 | + $expected = 5; |
| 32 | + } |
| 33 | + |
| 34 | + \printf( |
| 35 | + "Run %2d: Found %d functions in file %s, expected %d\n", |
| 36 | + $run, |
| 37 | + \count($result['functions']), |
| 38 | + $file, |
| 39 | + $expected |
| 40 | + ); |
| 41 | + $functions = array_keys($result['functions']); |
| 42 | + sort($functions); |
| 43 | + \print_r($functions); |
| 44 | + } |
| 45 | + |
| 46 | + print PHP_EOL; |
| 47 | +}; |
| 48 | + |
| 49 | +\xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE | XDEBUG_CC_BRANCH_CHECK); |
| 50 | +$object1 = new SampleClass(); |
| 51 | +assert(SampleStaticClass::getField0() === '0'); |
| 52 | +assert(SampleStaticClass::getField1() === '1'); |
| 53 | +assert(SampleStaticClass::getField2() === '2'); |
| 54 | +assert($object1->getField0NonStatic() === '0'); |
| 55 | +assert($object1->getField1NonStatic() === '1'); |
| 56 | +assert($object1->getField2NonStatic() === '2'); |
| 57 | +$results = \xdebug_get_code_coverage(); |
| 58 | +$resultPrinter(x_sort($results), 0); |
| 59 | +\xdebug_stop_code_coverage(true); |
| 60 | + |
| 61 | +\xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE | XDEBUG_CC_BRANCH_CHECK); |
| 62 | +assert(SampleStaticClass::getField1() === '1'); |
| 63 | +assert($object1->getField1NonStatic() === '1'); |
| 64 | +$results = \xdebug_get_code_coverage(); |
| 65 | +$resultPrinter(x_sort($results), 1); |
| 66 | +\xdebug_stop_code_coverage(true); |
| 67 | +?> |
| 68 | +--EXPECTF-- |
| 69 | +Run 0: Found 5 functions in file %sbug01674-SampleClass.inc, expected 9 |
| 70 | +Array |
| 71 | +( |
| 72 | + [0] => Xdebug\SampleClass->getField0NonStatic |
| 73 | + [1] => Xdebug\SampleClass->getField1NonStatic |
| 74 | + [2] => Xdebug\SampleClass->getField2NonStatic |
| 75 | + [3] => Xdebug\SampleClass->getField3NonStatic |
| 76 | + [4] => {main} |
| 77 | +) |
| 78 | +Run 0: Found 9 functions in file %sbug01674-SampleStaticClass.inc, expected 9 |
| 79 | +Array |
| 80 | +( |
| 81 | + [0] => Xdebug\SampleStaticClass->getField0 |
| 82 | + [1] => Xdebug\SampleStaticClass->getField0NonStatic |
| 83 | + [2] => Xdebug\SampleStaticClass->getField1 |
| 84 | + [3] => Xdebug\SampleStaticClass->getField1NonStatic |
| 85 | + [4] => Xdebug\SampleStaticClass->getField2 |
| 86 | + [5] => Xdebug\SampleStaticClass->getField2NonStatic |
| 87 | + [6] => Xdebug\SampleStaticClass->getField3 |
| 88 | + [7] => Xdebug\SampleStaticClass->getField3NonStatic |
| 89 | + [8] => {main} |
| 90 | +) |
| 91 | + |
| 92 | +Run 1: Found 5 functions in file %sbug01674-SampleClass.inc, expected 9 |
| 93 | +Array |
| 94 | +( |
| 95 | + [0] => Xdebug\SampleClass->getField0NonStatic |
| 96 | + [1] => Xdebug\SampleClass->getField1NonStatic |
| 97 | + [2] => Xdebug\SampleClass->getField2NonStatic |
| 98 | + [3] => Xdebug\SampleClass->getField3NonStatic |
| 99 | + [4] => {main} |
| 100 | +) |
| 101 | +Run 1: Found 9 functions in file %sbug01674-SampleStaticClass.inc, expected 9 |
| 102 | +Array |
| 103 | +( |
| 104 | + [0] => Xdebug\SampleStaticClass->getField0 |
| 105 | + [1] => Xdebug\SampleStaticClass->getField0NonStatic |
| 106 | + [2] => Xdebug\SampleStaticClass->getField1 |
| 107 | + [3] => Xdebug\SampleStaticClass->getField1NonStatic |
| 108 | + [4] => Xdebug\SampleStaticClass->getField2 |
| 109 | + [5] => Xdebug\SampleStaticClass->getField2NonStatic |
| 110 | + [6] => Xdebug\SampleStaticClass->getField3 |
| 111 | + [7] => Xdebug\SampleStaticClass->getField3NonStatic |
| 112 | + [8] => {main} |
| 113 | +) |
0 commit comments