Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit Enricher: classnode is always null #332

Closed
Codewolf opened this issue May 2, 2018 · 7 comments
Closed

PHPUnit Enricher: classnode is always null #332

Codewolf opened this issue May 2, 2018 · 7 comments

Comments

@Codewolf
Copy link

Codewolf commented May 2, 2018

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:

  • I am using the phpunit xml format, not clover
@theseer
Copy link
Owner

theseer commented May 2, 2018

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

@Codewolf
Copy link
Author

Codewolf commented May 2, 2018

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
Copy link
Author

Codewolf commented May 4, 2018

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

@theseer
Copy link
Owner

theseer commented May 6, 2018

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
Copy link
Author

Codewolf commented May 6, 2018

@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 theseer closed this as completed in 6e8d871 May 6, 2018
@theseer
Copy link
Owner

theseer commented May 6, 2018

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

@Codewolf
Copy link
Author

Codewolf commented May 6, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants