简体   繁体   中英

How to create PHP-UnitTest case for PHP_Codesniffer standards?`

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?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM