Skip to content

One line @covers annotation don't work #121

@edorian

Description

@edorian

I was made aware of the issue over at http://stackoverflow.com/questions/12620706/phpunit-trying-to-cover-not-existing-method

and the fix in sebastianbergmann/phpunit#328 was not enough it seems or it broke again due to change in codeCoverage.


Repro:

cat FooTest.php

<?php

class FooTest extends PHPUnit_Framework_TestCase {

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

}


class MyClass {

    public static function bar() {}

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

Fix

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);
             }
         }

Not sure this is the nicest fix but it works ;)

I need to write a nice test case for codeCoverage or a integration test for phpunit for this and maybe look for a nicer implementation.

Just opening a ticket so i don't forget

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions