如何为 PHP_Codesniffer 标准创建 PHP-UnitTest 案例?

发布于 2024-11-16 18:08:00 字数 1229 浏览 3 评论 0原文

我创建了自己的代码嗅探器规则标准。它们工作正常。现在我想使用 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 location
Standards/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等你爱我 2024-11-23 18:08:00

您的文件是否位于顶级 testsCodeSniffer 目录中?请注意,您要扩展的抽象测试用例位于 tests 中,

C:\Program Files\PHP\PEAR\PHP\tests\Standards\AbstractSniffUnitTest.php

但尝试包含来自 CodeSniffer 的文件:

C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc

尝试将两个文件移动到另一个目录。

Are your files in the top-level tests or CodeSniffer directory? Note that the abstract test case you're extending is in tests

C:\Program Files\PHP\PEAR\PHP\tests\Standards\AbstractSniffUnitTest.php

but is trying to include the file from CodeSniffer:

C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc

Try moving your two files to the other directory.

九命猫 2024-11-23 18:08:00

我在 i i nc 附近看到一个空格 - 确保这是否是拼写错误并更正它,它应该可以工作。除此之外我没有看到任何问题。

改变:

C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.i nc

C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc

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:

C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.i nc

To

C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc

爱已欠费 2024-11-23 18:08:00

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文