From 09898ccbc87b5e297bcfab4527a3705bd3b4d5a4 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 2 Dec 2023 17:45:25 +0300 Subject: add phpunit code coverage driver --- .../php-code-coverage/src/RawCodeCoverageData.php | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php') diff --git a/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php b/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php index 422742e28..9cb20e731 100644 --- a/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php +++ b/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php @@ -15,8 +15,12 @@ use function array_flip; use function array_intersect; use function array_intersect_key; use function count; +use function explode; +use function file_get_contents; use function in_array; +use function is_file; use function range; +use function trim; use SebastianBergmann\CodeCoverage\Driver\Driver; use SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser; @@ -87,7 +91,7 @@ final class RawCodeCoverageData { $lineCoverage = []; - foreach ($analyser->executableLinesIn($filename) as $line) { + foreach ($analyser->executableLinesIn($filename) as $line => $branch) { $lineCoverage[$line] = Driver::LINE_NOT_EXECUTED; } @@ -137,6 +141,42 @@ final class RawCodeCoverageData ); } + /** + * @param int[] $linesToBranchMap + */ + public function markExecutableLineByBranch(string $filename, array $linesToBranchMap): void + { + if (!isset($this->lineCoverage[$filename])) { + return; + } + + $linesByBranch = []; + + foreach ($linesToBranchMap as $line => $branch) { + $linesByBranch[$branch][] = $line; + } + + foreach ($this->lineCoverage[$filename] as $line => $lineStatus) { + if (!isset($linesToBranchMap[$line])) { + continue; + } + + $branch = $linesToBranchMap[$line]; + + if (!isset($linesByBranch[$branch])) { + continue; + } + + foreach ($linesByBranch[$branch] as $lineInBranch) { + $this->lineCoverage[$filename][$lineInBranch] = $lineStatus; + } + + if (Driver::LINE_EXECUTED === $lineStatus) { + unset($linesByBranch[$branch]); + } + } + } + /** * @param int[] $lines */ -- cgit v1.2.3