How to create PHP-UnitTest for PHP_Codesniffer standards? `

I created my own rule rule codes. They work fine. Now I want to test the codes using PHP UnitTest. PhpCodesniffer already has its own framework for the PHPUnit test case.

Thus, using this, I extended the AbstractSniffUnitTest class and unit test at the location Standards/TestRules/Tests/Function/FunctionUnitTest.php and the script, which should be tested in Standards/TestRules/Tests/Function/FunctionUnitTest.inc .

But when I am going to run the script with the phpunit PEAR\PHP\tests\AllTests.php , it gives the 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 an error file FunctionUnitTest.inc not found in the specified location. I gave full permission to the folder, also checking the path and location of the file, but it gives the same error. I also tested it on a linux machine, but it gives the same error.

Is this a problem of my code or a problem with unittest framework code?

+6
source share
3 answers

I see a space near i i nc - make sure this is a typo and correct it, it should work. Other than this, I do not see any problems.

Edit:

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

+1
source

Are your files in a top-level directory tests or CodeSniffer ? Note that the abstract test case you are distributing is in tests

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

but trying to include the file from CodeSniffer :

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

Try moving the two files to a different directory.

+1
source

It looks like he has a window permissions issue. I tested test cases on Linux, it works great. When I checked the actual code, it seems that there is a mapping of the files from the test file file to the sniff file. But in the window, after matching the file, the file path contains a mixture of forward and backward slahes. But the codes do not allow this. Because of this, it returns that "the file was not found as an error." Test cases run fine on Linux.

0
source

Source: https://habr.com/ru/post/891101/


All Articles