chr0n1x / php_codesniffer_tests
A test lib that can easily be required & used in custom PHP_CodeSniffer rulesets
Installs: 15 828
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 1 464
Open Issues: 0
pkg:composer/chr0n1x/php_codesniffer_tests
Requires
- php: >=5.1.2
- ext-tokenizer: *
- phpunit/phpunit: >=3.7
- squizlabs/php_codesniffer: ~2.0
Suggests
- phpunit/php-timer: dev-master
This package is not auto-updated.
Last update: 2025-10-21 09:46:12 UTC
README
Fork of squizlabs/PHP_CodeSniffer, but just the AbstractSniffUnitTest class. Why?
- I didn't want to lose any git commit history for this particular file!
- Now in your composer.jsonyou can just
"require": {
    "chr0n1x/php_codesniffer_tests": "1.0.0"
}
and automatically have access to AbstractSniffUnitTest in your unit tests when you require(__DIR__.'/vendor/autoload.php');
- allows you to use phpunit xml configuration files and test locally, right in your own standards repo
- Easy CI integration. Just composer install && ${RUN_SUITE}
- hopefully encourages people to write tests for their PHP_CodeSniffer sniffs!
Differences between this class and the one included with PHP_CodeSniffer:
- The runTests()method is public and marked as a PHPUnit test (ie:@test). It also runs per sniff automatically, as in only one sniff will be tested with it's corresponding.incfile. Makes sense, right?
- TEST_PATH(required)- Because this package is installable via composerit's conceptually better to define somewhere, somehow, where your tests are located. Also, it's a bit less nebulous.
 
- Because this package is installable via 
- STANDARD_PATH(optional)- This is specifically for standards that you have not yet officially installed in your instance of phpcs. If this const is not defined, the class will use the original method - parse the test class name & assume that everything is in thephpcshome dir
 
- This is specifically for standards that you have not yet officially installed in your instance of 
- TEST_EXT(optional)- The original suite required all your tests to be {$SNIFF_NAME}UnitTest.php. Setting this constant allows you to override theUnitTestportion completely, giving you some flexibility when organizing your tests.
 
- The original suite required all your tests to be 
All of these constants can just be defined in a bootstrap script that requires the composer bootstrap. eg:
<?php
require_once( __DIR__ . '/../vendor/autoload.php' );
define( 'TEST_PATH', __DIR__ . '/Awesomeness' );
define( 'STANDARD_PATH', __DIR__ . '/../Awesomeness' );
define( 'TEST_EXT', 'SniffTest.php' );
And, depending on how you run your tests, require this bootstrap script in either your Suite script or phpunit.xml.dist