Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8593699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:03:09+00:00 2026-06-12T00:03:09+00:00

My test case looks like this: class FooTest extends PHPUnit_Framework_TestCase { /** @covers MyClass::bar

  • 0

My test case looks like this:

class FooTest extends PHPUnit_Framework_TestCase {

    /** @covers MyClass::bar */
    function testBar()
    {
        $result = MyClass::bar();
        $this->assertSomething($result);
    }

}

Now, the test itself works perfectly fine but code coverage complains with:

PHP_CodeCoverage_Exception: Trying to @cover not existing method "MyClass::bar *//**".

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:03:09+00:00Added an answer on June 12, 2026 at 12:03 am

    Correction

    The issue was not within PHPUnit its self but withing PHP_CodeCoverage. The parsing logic is somewhat duplicated there and the PHPUnit fix (see below) didn’t help in that case.

    The patch to fix this for 3.6 is:

    diff --git a/PHP/CodeCoverage/Util.php b/PHP/CodeCoverage/Util.php
    index f90220d..54ce44b 100644
    --- a/PHP/CodeCoverage/Util.php
    +++ b/PHP/CodeCoverage/Util.php
    @@ -196,12 +196,12 @@ class PHP_CodeCoverage_Util
             } catch (ReflectionException $e) {
                 return array();
             }
    -        $docComment = $class->getDocComment() . $method->getDocComment();
    +        $docComment = substr($class->getDocComment(), 3, -2) . PHP_EOL . substr($method->getDocComment(), 3, -2);
     
             foreach (self::$templateMethods as $templateMethod) {
                 if ($class->hasMethod($templateMethod)) {
                     $reflector   = $class->getMethod($templateMethod);
    -                $docComment .= $reflector->getDocComment();
    +                $docComment .= substr($reflector->getDocComment(), 3, -2);
                     unset($reflector);
                 }
             }
    

    I’ve opened a ticket for this at https://github.com/sebastianbergmann/php-code-coverage/issues/121.

    Until this fix is released (and chances are that only happens for PHPUnit 3.7) you need to use the three liner.


    Old Answer:

    Old versions of PHPUnit didn’t work with one line annotations.

    PHPUnit tried to find a class/method combination named: "MyClass::bar *//**"

    Using a three line annotation works with all versions

    /** 
     * @covers MyClass::bar 
     */
    

    I fixed this PHPUnit 3.6.4.

    See Issue 328.

    From PHPUnit >= 3.6.4 your code should work just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which looks something like this: public class Test { private
I have a test case that looks like so: public class MyTest { private
I have a Spock test case, in which the setup block looks like this
Hi all I have a piece of code which looks like this: public class
I have a test case: class LoginTestCase(unittest.TestCase): ... I'd like to use it in
I have a class that looks like this public class TestCase { public IEnumerable<string>
I have the following test case: @ContextConfiguration(/spring/test-context.xml) @TransactionConfiguration(transactionManager=txManager) @Transactional() public class MyEntityDaoTestCase extends AbstractJUnit4SpringContextTests
Why doesn't this test case work? <?php // cards with cyrillic inidices and suits
This is a minimal test case of some code that I actually have. It
I currently have a model set up like so: I have a Test class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.