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

Do not error out on invalid @covers tag #1760

Closed
JeroenDeDauw opened this issue Jun 23, 2015 · 3 comments
Closed

Do not error out on invalid @covers tag #1760

JeroenDeDauw opened this issue Jun 23, 2015 · 3 comments

Comments

@JeroenDeDauw
Copy link
Sponsor Contributor

In my projects I have a ci command that runs PHPUnit and some other stuff. This is also what TravisCI runs. The only difference is that TravisCI also runs code coverage generation (via PHPUnit) afterwards. This means the TravisCI build can fail due to a typo in an @Covers tag, which will only show up when running coverage generation.

One fix is to execute phpunit --coverage-text=/dev/null. That will then fail as desired if a @Covers tag got messed up. That however slows the command down significantly. On one project from ~850ms to ~18s.

Is there a way to have PHPUnit not error out during coverage report generating when a @Covers tag is wrong? If not, consider this a feature request.

Currently using PHPUnit 4.7.3, though I've been running into this for years.

@orlangur
Copy link

Some phpunit --coverage-null which just runs fast looks like a dirty hack.

Why not simply fix such problem on an earlier stage so that invalid class/method will never appear in repository? Just check this in hook or static test.

@sebastianbergmann
Copy link
Owner

That would defeat the purpose of the feature, sorry.

I agree with what was said in #1760 (comment) that code with invalid annotations must not exist to begin with by the time PHPUnit runs the tests. I already explained in #1758 (comment) that this would be the job of a separate tool.

JeroenDeDauw added a commit to wmde/WikibaseDataModel that referenced this issue Aug 7, 2015
This is to detect incorrect @Covers tags before the code gets to ScutinizerCI. We are already doing this at https://github.com/wmde/WikibaseDataModelServices/blob/master/composer.json

A better approach would be nice though, considering this slows down the execution of the test command by doing a lot of not needed work. Apparently this is not going to come from the PHPUnit side though, as per sebastianbergmann/phpunit#1760
thiemowmde pushed a commit to wmde/WikibaseDataModel that referenced this issue Jan 11, 2016
This is to detect incorrect @Covers tags before the code gets to ScutinizerCI. We are already doing this at https://github.com/wmde/WikibaseDataModelServices/blob/master/composer.json

A better approach would be nice though, considering this slows down the execution of the test command by doing a lot of not needed work. Apparently this is not going to come from the PHPUnit side though, as per sebastianbergmann/phpunit#1760
@theofidry
Copy link
Contributor

@sebastianbergmann I see that you already answered regarding verifying the @cover(s) annotations. While I agree with what you said, there still an issue: if I have a wrong @covers annotation, my test just fail with 'Trying to @cover or @use not existing class or interface ">my class name>".'. The issue being that it does not display a failure message and on my Travis CI, the test is still marked as passed, even if the whole test suite has been interrupted. Could this be changed?

In case it's a bug, I'm using PHPUnit 5.2.3 on PHP 5.6.18 with Xdebug 2.3.3. My PHPUnit config is:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
         bootstrap="bootstrap/autoload.php"
         colors="true"
         forceCoversAnnotation="true">

    <testsuites>
        <testsuite name="App tests">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">src/</directory>
        </whitelist>
    </filter>
</phpunit>

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

4 participants