Fix sonarCloud reports output
This commit is contained in:
parent
d4832b2ca4
commit
fcf6a860f8
7
.github/workflows/php.yml
vendored
7
.github/workflows/php.yml
vendored
@ -43,7 +43,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'pull_request'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v1
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@master
|
||||
with:
|
||||
@ -60,9 +60,8 @@ jobs:
|
||||
- name: Run test suite
|
||||
run: composer run-script test -- --coverage-clover=coverage.clover --log-junit=test-report.xml
|
||||
|
||||
# https://community.sonarsource.com/t/code-coverage-doesnt-work-with-github-action/16747/5
|
||||
- name: fix code coverage paths
|
||||
run: sed -i 's/\/home\/runner\/work\/daux.io\/daux.io\//\/github\/workspace\//g' coverage.clover
|
||||
- name: Fix reports
|
||||
run: scripts/fix_reports.sh
|
||||
|
||||
- name: SonarCloud Scan
|
||||
uses: SonarSource/sonarcloud-github-action@v1.1
|
||||
|
@ -47,6 +47,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "build/phpunit",
|
||||
"test:coverage-html": "build/phpunit --coverage-html=build/coverage",
|
||||
"lint": "build/php-cs-fixer fix --config=.php_cs --dry-run -v",
|
||||
"lint:fix": "build/php-cs-fixer fix --config=.php_cs"
|
||||
}
|
||||
|
52
scripts/fix_report.php
Normal file
52
scripts/fix_report.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
$report = file_get_contents(dirname(__DIR__) . "/test-report.xml");
|
||||
|
||||
$doc = new DOMDocument($report);
|
||||
$doc->loadXML($report);
|
||||
|
||||
function hasDataSetTestCase(DomNode $node) {
|
||||
foreach ($node->childNodes as $child) {
|
||||
if ($child->nodeName === "testcase" && strpos($child->attributes->getNamedItem("name")->textContent, "with data set #" ) !== false) {
|
||||
return $child;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function drillDownTestSuite(DomDocument $document, DomNode $node) {
|
||||
if ($dataset = hasDataSetTestCase($node)) {
|
||||
$childAttributes = $dataset->attributes;
|
||||
$nodeAttributes= $node->attributes;
|
||||
|
||||
$case = $document->createElement('testcase');
|
||||
$case->setAttribute('name', $childAttributes->getNamedItem('name')->textContent);
|
||||
$case->setAttribute('class', $childAttributes->getNamedItem('class')->textContent);
|
||||
$case->setAttribute('classname', $childAttributes->getNamedItem('classname')->textContent);
|
||||
$case->setAttribute('file', $childAttributes->getNamedItem('file')->textContent);
|
||||
$case->setAttribute('line', $childAttributes->getNamedItem('line')->textContent);
|
||||
$case->setAttribute('assertions', $nodeAttributes->getNamedItem('assertions')->textContent);
|
||||
$case->setAttribute('time', $nodeAttributes->getNamedItem('time')->textContent);
|
||||
|
||||
$node->parentNode->replaceChild($case, $node);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @var DomNode $child */
|
||||
for ($i=0; $i< $node->childNodes->length; $i++) {
|
||||
$child = $node->childNodes->item($i);
|
||||
if ($child->localName === "testsuite") {
|
||||
if (drillDownTestSuite($document, $child)) {
|
||||
$i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
drillDownTestSuite($doc, $doc->firstChild);
|
||||
|
||||
file_put_contents(dirname(__DIR__) . "/test-report.xml", $doc->saveXML());
|
||||
echo "Done\n";
|
7
scripts/fix_reports.sh
Executable file
7
scripts/fix_reports.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# https://community.sonarsource.com/t/code-coverage-doesnt-work-with-github-action/16747/5
|
||||
echo "fix code coverage paths"
|
||||
sed -i 's/\/home\/runner\/work\/daux.io\/daux.io\//\/github\/workspace\//g' coverage.clover
|
||||
|
||||
php scripts/fix_report.php
|
Loading…
Reference in New Issue
Block a user