6

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?

David Harkness
  • 35,992
  • 10
  • 112
  • 134
Gaurav
  • 83
  • 1
  • 8

3 Answers3

1

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.

David Harkness
  • 35,992
  • 10
  • 112
  • 134
  • Directory Structure is as Follows -Codesniffer --Standard ---TestRules ----Sniff/Function/FunctionSniff.php ----Tests/Function/FunctionUnitTest.php /-FunctionUnitTest.inc -tests --Standards /AbstarctSniffUnitTest.php /AllSniffs.php Is there any worng with directory structure? I have followed the same convention as PHP-Codesniffer UnitTest. Any Pointer? – Gaurav Jun 23 '11 at 09:42
  • If you followed the pattern laid out by CodeSniffer's own tests, I would expect it to work. I would start by opening the class that is trying to include your file and see where it expects the file to be. Time to roll up your sleeves and get your hands dirty. :) – David Harkness Jun 23 '11 at 17:21
0

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

Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66
  • I reformatted the question for the poster, and there was no space in `inc`. It was a line ending that the browser turns into a space. I suspect it was caused by selecting the text in the console. – David Harkness Jun 22 '11 at 16:59
  • @David I hope so, but I am wondering what could cause this problem, since both the files are in the same location & `TestRules/Tests/Function/FunctionUnitTest.php` is getting processed if that is the case, then it should pick-up the file `TestRules/Tests/Function/FunctionUnitTest.inc`. – Rakesh Sankar Jun 23 '11 at 03:25
  • Thanks all of you for comments. Actual file location is C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc I am also wondering why this problem occur as folder has full read/write permissions. – Gaurav Jun 23 '11 at 06:49
  • @User810130 why don't you use `xdebug` and see how to flow is going & where/how it is trying to add `.inc` file? – Rakesh Sankar Jun 23 '11 at 06:58
0

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.

Gaurav
  • 83
  • 1
  • 8