PhpStorm phpspec 代码嗅探器忽略测试文件夹

标签 php phpstorm

当我尝试创建它时,我在我的测试类中看到了警告。我不想为测试类创建 PHPDoc 和更多内容,但 PhpStorm 向我显示警告,因为 PhpStorm 无法将测试类标记为排除 phpcs。

我如何运行 phpcs 来验证我的类是否符合编码标准:

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

如何为 PhpStorm 2016.3.2 实现它? 我尝试创建配置:

<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>

并在 PhpStorm 中导入此配置: enter image description here

但是我的测试再次向我显示警告: enter image description here

最佳答案

  1. 设置/首选项 |外观与行为 |范围

去那里创建一个custom Scope这将包括此类不需要的文件/文件夹(最简单的方法 - 导航到那里树中的 Tests 文件夹,然后单击 Include recursively 按钮)。

注意:理论上,如果您将带有测试的文件夹标记为“测试源根目录”(在项目 View 面板中右键单击并选择从 Mark Directory As 子菜单中选择正确的类型;同样可以通过 Settings/Preferences | Directories 完成。

这样您就可以使用内置的“测试”范围。

  1. 保存更改(应用 ... 或使用确定 并再次重新打开设置/首选项屏幕)

  2. 设置/首选项 |编辑|检查

  3. 查找 PHP | PHP 代码嗅探器验证 检查

  4. 为最近创建的范围创建一个新规则。

单击 In All Scopes 按钮(当只定义了 1 个规则时这是一个按钮)并选择该范围。

enter image description here

  1. 现在只需为该范围禁用此检查。

enter image description here

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

关于PhpStorm phpspec 代码嗅探器忽略测试文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42245024/

相关文章:

php - 期待声明?

intellij-idea - 在 PhpStorm 中固定标签有什么作用?

macos - 不要在 vagrant up 命令 PHPStorm 上选择 VagrantFile

css - 如何为 Jetbrains PhpStorm 添加 Compass 语法支持?

phpstorm - 在 PHPStorm 中查找未使用的公共(public)和 protected 方法

php - 如何将 php 和 jqueryMobile 应用程序转换为 apk 文件

PHP - 如何检查变量是否与数据库条目匹配?

javascript - 两个选择选项上的多个更改

php - 在网站上使用Facebook登录并获取用户ID

php - 无法弄清楚PHP中的字符编码