如何为 PHP_Codesniffer 标准创建 PHP-UnitTest 案例?
我创建了自己的代码嗅探器规则标准。它们工作正常。现在我想使用 PHP UnitTest 测试 codeniffer 规则。 PhpCodesniffer 已经有了 PHPUnit 测试用例的框架。
因此,我使用它扩展了他们的 AbstractSniffUnitTest
和单元测试类 Standards/TestRules/Tests/Function/FunctionUnitTest.php
和要测试的脚本保存在 Standards/TestRules/Tests/Function/FunctionUnitTest.inc
中。
但是当我要通过命令 phpunit PEAR\PHP\tests\AllTests.php
运行脚本时,它给出以下错误。
PHPUnit 3.5.14 by Sebastian Bergmann.
......................................F
Time: 6 seconds, Memory: 10.00Mb
There was 1 failure:
1) TestRules_Tests_Function_FunctionUnitTest::getErrorList
An unexpected exception has been caught: Source file C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc does not exist
C:\Program Files\PHP\PEAR\PHP\tests\Standards\AbstractSniffUnitTest.php:138
C:\Program Files\PHP\PEAR\PHP\tests\TestSuite.php:48
FAILURES!
Tests: 39, Assertions: 146, Failures: 1.
Warning: Deprecated PHPUnit features are being used 2 times!
Use --verbose for more information.
它给出错误文件 FunctionUnitTest.inc
在给定位置找不到。我已授予文件夹完全权限并验证路径和文件位置,但它给出了相同的错误。我也在linux机器上测试过它,但它给出了同样的错误。
是我的代码问题还是codesniffer单元测试框架问题?
I have created my own codesniffer rules standards.They are working fine. Now I want to test codesniffer rules using PHP UnitTest. PhpCodesniffer has already have their framework for PHPUnit test case.
So using that I have extended their AbstractSniffUnitTest
and unit test class at locationStandards/TestRules/Tests/Function/FunctionUnitTest.php
and script on which is to be tested kept in Standards/TestRules/Tests/Function/FunctionUnitTest.inc
.
But when I am going to run the script by command phpunit PEAR\PHP\tests\AllTests.php
, it gives following error.
PHPUnit 3.5.14 by Sebastian Bergmann.
......................................F
Time: 6 seconds, Memory: 10.00Mb
There was 1 failure:
1) TestRules_Tests_Function_FunctionUnitTest::getErrorList
An unexpected exception has been caught: Source file C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc does not exist
C:\Program Files\PHP\PEAR\PHP\tests\Standards\AbstractSniffUnitTest.php:138
C:\Program Files\PHP\PEAR\PHP\tests\TestSuite.php:48
FAILURES!
Tests: 39, Assertions: 146, Failures: 1.
Warning: Deprecated PHPUnit features are being used 2 times!
Use --verbose for more information.
It gives error file FunctionUnitTest.inc
not found at given location. I have given full permission to folder also verify the path and file location, but it gives same error. I have tested it on linux machine also, but it gives same error.
Is it a my code issue or codesniffer unittest framework issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的文件是否位于顶级
tests
或CodeSniffer
目录中?请注意,您要扩展的抽象测试用例位于tests
中,但尝试包含来自
CodeSniffer
的文件:尝试将两个文件移动到另一个目录。
Are your files in the top-level
tests
orCodeSniffer
directory? Note that the abstract test case you're extending is intests
but is trying to include the file from
CodeSniffer
:Try moving your two files to the other directory.
我在 i
i nc
附近看到一个空格 - 确保这是否是拼写错误并更正它,它应该可以工作。除此之外我没有看到任何问题。改变:
到
I see a space near i
i nc
- make sure if that is mis-typo and correct it, it should work. Other than this I don't see any problem.Change:
To
Windows 上似乎有路径问题。我在Linux上测试了测试用例,效果很好。当我检查实际代码时,似乎有从测试用例文件到嗅探文件的文件映射。但在window上,文件映射后,文件路径包含forward和reward的混合。向后斜线。但是codeniffer 不会允许这样做。因此,它返回“文件未找到错误”。测试用例在 Linux 上执行良好。
It seems that it has path issue on windows. I tested the test cases on Linux, it works fine. When I checked the actual code, it seems that on there is file mapping from test case file to sniff file. But on window, after file being mapped , the file path contains mixing of forward & backward slahes.But codesniffer not going to allow this. Because of that it is returning that “file is not found error”. Test cases are executing fine on Linux.