SonarPHP doesn't analyze php-unit tests with dataProvider

“INFO: Analyzing PHPUnit test report: tests/logs/logfile.xml”

Example xml that will show warnings

  • for //testsuite/testsuite/testsuite/testcase
  • but read //testsuite/testsuite/testcase
  • because there is no file attribute on the nested testsuite node
<testsuites>
  <testsuite assertions="3885" errors="0" failures="0" name="classes" skipped="36" tests="1926" time="0.778806">
    <testsuite name="tests\SomeTest" file="/home/.../SomeTest.php" tests="11" assertions="22" errors="0" failures="0" skipped="0" time="0.075715">
      <testcase name="someTest" class="tests\SomeTest" classname="tests.SomeTest" file="/home/.../SomeTest.php" line="17" assertions="3" time="0.032633"/>
      <testsuite name="tests\SomeTest::otherTest" tests="7" assertions="14" errors="0" failures="0" skipped="0" time="0.032672">
        <testcase name="otherTest with data set #0" class="tests\SomeTest" classname="tests.SomeTest" file="/home/.../SomeTest.php" line="87" assertions="2" time="0.004864"/>

Simple python script that you can run on the logfile.xml to patch the file attribute on testsuite nodes (workaround):