0

I have had the error: Generating code coverage report in Clover XML format ... Fatal error: Cannot redeclare preprocessGrammar() (previously declared in /app/vendor/nikic/php-parser/grammar/phpyLang.php:22) in /app/vendor/nikic/php-parser/grammar/phpyLang.php on line 22

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         cacheResultFile=".phpunit.cache/test-results">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">.</directory>
        </include>
        <report>
            <clover outputFile="phpunit.coverage.xml"/>
        </report>
    </coverage>

    <logging>
        <junit outputFile="phpunit.report.xml"/>
    </logging>
</phpunit>

I had this error only when I used test coverage.

1 Answer 1

1

My mistake was here:

<include>
    <directory suffix=".php">.</directory>
</include>

I wanted to cover all the files, they were in src and in the root directory of the project.

In the root directory were tests and they were included for the test coverage. It made a recursive call.

For solving this problem I set concrete directory (src) and files (.php-cs-fixer.). I have used this directives:

<include>
    <directory suffix=".php">src</directory>
    <directory prefix=".php-cs-fixer.">.</directory>
</include>

I also could use <file>, but I had several files and using directory for me more useful. https://phpunit.readthedocs.io/en/9.5/configuration.html#the-file-element

The <exclude> directive didn't for me.

My finally configuration.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         cacheResultFile=".phpunit.cache/test-results">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">src</directory>
            <directory prefix=".php-cs-fixer.">.</directory>
        </include>
        <report>
            <clover outputFile="phpunit.coverage.xml"/>
        </report>
    </coverage>

    <logging>
        <junit outputFile="phpunit.report.xml"/>
    </logging>
</phpunit>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.