Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 441
Gaurav Avatar asked Jun 22 '11 10:06

Gaurav


1 Answers

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.

like image 113
David Harkness Avatar answered Nov 08 '22 01:11

David Harkness