[英]How to ignore `static method called as dynamic` inspection in tests only
PHPUnit has all assertions defined as static functions, but you are supposed to call them with object context 1 . PHPUnit将所有断言定义为静态函数,但您应该使用对象上下文1来调用它们。 Apart from if this is a good practice or not, if you want to follow this practice you will get warnings in PhpStorm: static method called as dynamic
除非这是一个好的做法,如果你想遵循这种做法,你将在PhpStorm中收到警告: static method called as dynamic
I like this inspection and do not want to turn it off for all files. 我喜欢这个检查,不想为所有文件关闭它。 I do want to turn it off for phpunit tests, but adding a noinspection
comment to all my tests is annoying and repetitive. 我确实希望将其关闭以进行phpunit测试,但在我的所有测试中添加无noinspection
注释都很烦人且重复。
How can I ignore this in tests, but have this inspection in my normal code? 我如何在测试中忽略这一点,但是在我的普通代码中进行了检查?
I'm using PhpStorm 2016.3 我正在使用PhpStorm 2016.3
1 : see Sebastian's comment on this github issue . 1 :看看塞巴斯蒂安对这个github问题的评论。
A regular user of PHPUnit should use $this-> instead of self:: PHPUnit的普通用户应该使用$ this->而不是self ::
Also, all the examples in the manual use this method. 此外,手册中的所有示例都使用此方法。
To ignore the "static method called as dynamic" errors in your tests, you can define a scope, and then change the inspections for that scope. 要忽略测试中的“静态方法称为动态”错误,可以定义范围,然后更改该范围的检查。
The setting-names etc are for PhpStorm 2016.3. 设置名称等适用于PhpStorm 2016.3。
You can use the default Test
scope, by setting your tests directory as "test sources root". 通过将tests目录设置为“test sources root”,可以使用默认的Test
范围。 You can also create your own scope (see below) 您也可以创建自己的范围(见下文)
Now make your inspection work only for this scope 现在让您的检查仅适用于此范围
If you have created a specific scope for your project with exclusions, you could also select only that scope here. 如果已使用排除项为项目创建了特定范围,则还可以在此处仅选择该范围。
You might need to restart phpstorm or re-run inspections. 您可能需要重新启动phpstorm或重新运行检查。
It looks like so: 它看起来像这样:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.