theseer / phpdox

Documentation generator for PHP Code using standard technology (SRC, DOCBLOCK, XML and XSLT)
http://phpdox.de
Other
600 stars 121 forks source link

PHPUnit Enricher: classnode is always null #332

Closed Codewolf closed 6 years ago

Codewolf commented 6 years ago

Issue:

Code coverage seems to scan the coverage folder and adds the coverage section to the generated document but always reports the coverage as 0%.

Research:

Looking through the phpdox code and debugging each run; $classnode in TheSeer\phpDox\Generator\Enricher\PHPUnit:153 always seems to be null (code comment is "this class seems to be newer than the last phpunit run") when phpdox is run on a folder using a phpdox xml config file.

Notes:

theseer commented 6 years ago

This may be a problem with path mappings. Can you provide me with a simple example to reproduce this?

Codewolf commented 6 years ago

Folder structure

${basedir} ->src/ ->build/ -->coverage/ --->html/ --->xml/ -->test-reports/(this contains phploc etc. xml output) ->tests/ phpdox.xml

phpdox.xml (non-phpunit sections removed)

<?xml version="1.0" encoding="utf-8" ?>
<phpdox xmlns="http://xml.phpdox.net/config" silent="false">
    <bootstrap/>
    <project name="xxx" source="${basedir}/src" workdir="${basedir}/build/phpdox/xml">
        <collector publiconly="false" backend="parser" encoding="auto">
            <include mask="*.php"/>
            <inheritance resolve="true">
            </inheritance>
        </collector>
        <generator output="${basedir}/build/phpdox">
            <enrich base="${basedir}/build">
                <source type="phpunit">
                    <coverage path="./coverage/xml"/>
                </source>
            </enrich>
            <build engine="html" enabled="true" output="html">
                <template dir="${phpDox.home}/templates/html"/>
                <file extension="xhtml"/>
            </build>
        </generator>
    </project>
</phpdox>

Sanitized PHPUnit output (with source removed, please let me know if you need this)

<?xml version="1.0"?>
<phpunit xmlns="http://schema.phpunit.de/coverage/1.0">
  <file name="ExampleFile.php" path="/Space">
    <totals>
      <lines total="80" comments="17" code="63" executable="30" executed="30" percent="100.00"/>
      <methods count="2" tested="2" percent="100.00"/>
      <functions count="0" tested="0" percent="0"/>
      <classes count="1" tested="1" percent="100.00"/>
      <traits count="0" tested="0" percent="0"/>
    </totals>
    <class name="Name\Space\ExampleFile" start="21" executable="30" executed="30" crap="5">
      <package full="Name" name="Name" sub="" category=""/>
      <namespace name="Name\Console"/>
      <method name="method1" signature="method1(): void" start="27" end="34" crap="1" executable="5" executed="5" coverage="100"/>
      <method name="method2" signature="method2(Interface $interface1, Interface $interface2)" start="43" end="79" crap="4" executable="25" executed="25" coverage="100"/>
    </class>
    <coverage>
      <line nr="30">
        <covered by="Tests\Unit\Space\Test1::test"/>
      </line>
      <line nr="47">
        <covered by="Tests\Unit\Space\Test2::test"/>
        <covered by="Tests\Unit\Console\Test1::Test"/>
      </line>
    </coverage>
  </file>
</phpunit>

note: original file names/classes and paths replaced, but the structure has not changed

Codewolf commented 6 years ago

@theseer Did you have any luck reproducing this or would more information help?

theseer commented 6 years ago

Yes, I found the reason.

The coverage xml seems to have changed: <class name="Name\Space\ExampleFile" ...

The current implementation of the PHPUnit Enricher expects the name to be only the name without a namespace. I have to investigate when (and why?) that changed as I'm not aware of any changes in phpunit's code coverage output.

Bear with me :)

Codewolf commented 6 years ago

@theseer No problem at all, i did try to look into the xpath section of your code when debugging, but i couldnt seem to hit the bit where it actually does the query so hit a bit of a brick wall.

theseer commented 6 years ago

Can you verify if the patch fixes it for you as well?

Codewolf commented 6 years ago

Took a little bit for me to boot up the laptop, but i can confirm that the patch fixed it :) :+1: Thankyou :+1: