radepal / Symfony2-coding-standard

Symfony2-coding-standard
1 stars 1 forks source link

Not working @covers sniff for PHPUnit tests #4

Open karolhor opened 9 years ago

karolhor commented 9 years ago

After updating Symfony2 standard to PHPCS 2.x searching for @covers tag stopped working.

Example class:

<?php
namespace Foo;

/**
 * Class BestClassEverTest
 */
class BestClassEverTest extends \PHPUnit_Framework_TestCase
{

    /**
     * @param string $foo
     */
    public function testImportantMethod($foo, $bar)
    {
        $this->assertTrue(true);
    }
}

PHPCS 1.5.6 + Symfony2 (86297e573408eab1fbedf1231b3d0cc8864a8417) result:

--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
 11 | ERROR   | Doc comment for "$bar" missing
 13 | WARNING | Missing test @covers tag
--------------------------------------------------------------------------------
UPGRADE TO PHP_CODESNIFFER 2.0 TO FIX ERRORS AUTOMATICALLY
--------------------------------------------------------------------------------

PHPCS 2.3.2 + Symfony2 (50249b9c3653c34a5af623cfb5d44910fe93cb5c - current master)

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 10 | ERROR | Doc comment for parameter "$bar" missing
----------------------------------------------------------------------

Time: 23ms; Memory: 3.25Mb

This is coused by T_DOC_COMMENT. In 2.x PhpDocBlock has new tokens (they are more detailed).

T_DOC_COMMENT_OPEN_TAG
T_DOC_COMMENT_STAR
T_DOC_COMMENT_TAG
T_DOC_COMMENT_STRING
T_DOC_COMMENT_WHITESPACE
T_DOC_COMMENT_CLOSE_TAG

So mentioned above token should be replaced with T_DOC_COMMENT_CLOSE_TAG.

karolhor commented 9 years ago

This should be fixed with class refactor mentioned in #5

Maybe it's good time to implement a way for dealing with our company RFC for class coverage to respect @covers on test methods (BC) or only @covers on class PhpDocBlock

/**
 * Test example
 * @covers Foo/Bar/BazClass
 */
class BazClassTest extends \PHPUnit_Framework_TestCase
{
}