Search code examples
phpphpstorm

PhpStorm phpspec code sniffer ignore test folder


I see warnings in my test classes when I try create it. I don't want create PHPDoc and more for tests classes, but PhpStorm shows me warnings, because PhpStorm cannot marked tests classes as exclude for phpcs.

How I run my phpcs for validate my classes for coding standards:

php bin/phpcs ./src -p --encoding=utf-8 --extensions=php --ignore=Tests --standard=./vendor/escapestudios/symfony2-coding-standard/Symfony2

How implement it for PhpStorm 2016.3.2? I try create configuration:

<target name="phpcs-ci"
        description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
    <exec executable="phpcs" output="/dev/null">
        <arg value="--encoding=utf-8" />
        <arg value="--extensions=php" />
        <arg value="--ignore=Tests" />
        <arg value="--standard=./vendor/escapestudios/symfony2-coding-standard/Symfony2" />
        <arg path="${basedir}" />
    </exec>
</target>

And import this configuration in PhpStorm: enter image description here

But my tests show me warnings again: enter image description here


Solution

    1. Settings/Preferences | Appearance & Behaviour | Scopes

    Go there and create a custom Scope that would include such unwanted files/folders (the simplest way -- navigate to your Tests folder in the tree there and click on Include recursively button).

    NOTE: In theory this step can be skipped if you mark your folders with tests as "Test Source Roots" (right-click in the Project View panel and choose the right type from Mark Directory As submenu; the same can be done via Settings/Preferences | Directories).

    This way you could use the built-in "Tests" scope.

    1. Save changes (either Apply ... or use OK and re-open Settings/Preferences screen again)

    2. Settings/Preferences | Editor | Inspections

    3. Find PHP | PHP Code Sniffer validation inspection

    4. Create a new rule for that recently created Scope.

    Click on In All Scopes button (it's a button when only 1 rule is defined) and choose that scope.

    enter image description here

    1. Now just disable this inspection for that scope.

    enter image description here

    https://www.jetbrains.com/help/phpstorm/2016.3/changing-the-order-of-scopes.html