3

私のテストケースは次のようになります。

class FooTest extends PHPUnit_Framework_TestCase {

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

}

現在、テスト自体は完全に正常に機能しますが、コードカバレッジは次のように文句を言います。

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

何か案は?

4

2 に答える 2

4

もう1つの理由(私の場合はこれが理由でした)は、名前空間を含む完全なクラス名を使用していないことです。

// Should be like
@covers \Vendor\Module\MyClass::doSomething
于 2014-09-01T05:03:30.537 に答える
3

修正

問題はPHPUnit自体ではなく、PHP_CodeCoverageにありました。そこでは解析ロジックが多少重複しており、PHPUnitの修正(以下を参照)はその場合には役に立ちませんでした。

3.6でこれを修正するパッチは次のとおりです。

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

でこのチケットを開きましたhttps://github.com/sebastianbergmann/php-code-coverage/issues/121

この修正がリリースされるまで(そして、PHPUnit 3.7でのみ発生する可能性があります)、3つのライナーを使用する必要があります。


古い答え:

古いバージョンのPHPUnitは、1行のアノテーションでは機能しませんでした。

PHPUnitは、次の名前のクラス/メソッドの組み合わせを見つけようとしました。"MyClass::bar *//**"

3行の注釈を使用すると、すべてのバージョンで機能します

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

これを修正しましPHPUnit 3.6.4た。

を参照してくださいIssue 328

あなたのコードからPHPUnit >= 3.6.4はうまくいくはずです。

于 2012-09-27T17:11:55.413 に答える