-
Notifications
You must be signed in to change notification settings - Fork 10
Unit tests
PHP_CodeSniffer offers a way to create Unit tests for self created sniffs. We has created unit tests for our sniffs as well. They can be found in the Tests folder. During development it might be useful to execute this Unit tests. Here is a small guide how to do this with our custom sniffs.
Clone the repository which contains all of our custom sniffs, the TYPO3SniffPool:
$ git clone https://github.com/typo3-ci/TYPO3SniffPool.git
Switch to the cloned repository and install all dependencies with composer:
$ cd TYPO3SniffPool
$ COMPOSER_PROCESS_TIMEOUT=2000 composer install --prefer-source --dev
We have to --prefer-source (and clone from github), because we need all Unit tests from PHP_CodeSniffer. The tests are not provided in the dist variant at Packagist. Further more we have to get all --dev dependencies, because we need PHPUnit.
If we got all sources we have to link our development version as a standard into the PHP_CodeSniffer:
$ mkdir ./vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/TYPO3SniffPool
$ ln -s ../../../../../../ruleset.xml ./vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/TYPO3SniffPool/ruleset.xml
$ ln -s ../../../../../../Sniffs ./vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/TYPO3SniffPool/Sniffs
$ ln -s ../../../../../../Tests ./vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/TYPO3SniffPool/Tests
And finally we can execute the unit tests:
$ ./vendor/bin/phpunit -v ./vendor/squizlabs/php_codesniffer/tests/AllTests.php
Next to manual executing this unit tests, they are executed automatically if something changes via TravisCI. The configuration on how this works is available in our .travis.yml