How to I can tune JUnit report from PHPStan for GitLab CI?

116 Views Asked by At

We have a box version of GitLab, where we want to use PHPStan and show test results in CI. For a better user experience, I want to convert the PHPStan JUnit report via sed command. But there are two problems:

  • PHPStan output XML in one line without line break symbols;
  • PHPStan does not add rule name that caused error.

Example of what PHPStan output report now:

<?xml version="1.0" encoding="UTF-8"?><testsuite failures="4" name="phpstan" tests="4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd"><testcase name="src/Client.php:40"><failure type="ERROR" message="Property Lab\EbdkClient\Client::$username is never read, only written." /></testcase><testcase name="src/Client.php:45"><failure type="ERROR" message="Property Lab\EbdkClient\Client::$password is never read, only written." /></testcase><testcase name="src/Client.php:161"><failure type="ERROR" message="Method Lab\EbdkClient\Client::createGetRequest() has parameter $queryParams with no value type specified in iterable type array." /></testcase><testcase name="src/Exception/AccessDenied.php:16"><failure type="ERROR" message="Method Lab\EbdkClient\Exception\AccessDenied::ttt() with return type void returns int but should not return anything." /></testcase></testsuite>

Example of what I would like to see in the report (with break symbols and rule names):

<?xml version="1.0" encoding="UTF-8"?>
<testsuite failures="4" name="phpstan" tests="4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd">
    <testcase name="src/Client.php:40" ruleName="Blah">
        <failure type="ERROR" message="Property Lab\EbdkClient\Client::$username is never read, only written."/>
    </testcase>
    <testcase name="src/Client.php:45" ruleName="Blah">
        <failure type="ERROR" message="Property Lab\EbdkClient\Client::$password is never read, only written."/>
    </testcase>
    <testcase name="src/Client.php:161" ruleName="Blah">
        <failure type="ERROR"
                 message="Method Lab\EbdkClient\Client::createGetRequest() has parameter $queryParams with no value type specified in iterable type array."/>
    </testcase>
    <testcase name="src/Exception/AccessDenied.php:16" ruleName="Blah">
        <failure type="ERROR"
                 message="Method Lab\EbdkClient\Exception\AccessDenied::ttt() with return type void returns int but should not return anything."/>
    </testcase>
</testsuite>

Example of what I would like to see after convert the report:

<?xml version="1.0" encoding="UTF-8"?>
<testsuite failures="4" name="phpstan" tests="4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd">
    <testcase file="src/Client.php:40" name="Blah">
        <failure type="ERROR" message="Property Lab\EbdkClient\Client::$username is never read, only written."/>
    </testcase>
    <testcase file="src/Client.php:45" name="Blah">
        <failure type="ERROR" message="Property Lab\EbdkClient\Client::$password is never read, only written."/>
    </testcase>
    <testcase file="src/Client.php:161" name="Blah">
        <failure type="ERROR"
                 message="Method Lab\EbdkClient\Client::createGetRequest() has parameter $queryParams with no value type specified in iterable type array."/>
    </testcase>
    <testcase file="src/Exception/AccessDenied.php:16" name="Blah">
        <failure type="ERROR"
                 message="Method Lab\EbdkClient\Exception\AccessDenied::ttt() with return type void returns int but should not return anything."/>
    </testcase>
</testsuite>

An example of how you would like to see this in GitLab (just example, with another tests):

enter image description here

0

There are 0 best solutions below