WordPress-Coding-Standards/.travis.yml
jrfnl f672e18007 Travis/PHPCS: check WPCS own code for PHP cross-version compatibility
As the code in WPCS itself should be compatible with PHP 5.3 - nightly, why not let the PHPCompatibility standard check this for us ?

Composer:
* Adds `require-dev` section to `composer.json`.
* Adds install path for PHPCompatibility to the default script.
    This is only run when WPCS is installed from the root, so only relevant for devs, so adding PHPCompatibility there can be considered "safe".
    Note: PHPCS will complain if it is run with this installed path if PHPCompatibility is not installed, i.e. if Composer was run from root with `--no-dev`.

Travis:
* Switches over the Travis script to use Composer to install the dependencies.
    - As the bootstraps are already coded to pick up PHPCS when installed in the `vendor` directory, no need for the `PHPCS_DIR` variable anymore.
    - As the `phpcs` executable will always be in the `vendor/bin/` directory, no need for the `PHPCS_BIN` variable anymore.
    - `--(update-)no-dev` is used as for the unit test runs, we don't need PHPCompatibility for those.
    - For PHPCS 2.x installing with `--prefer-source` is needed as otherwise the unit tests base files we need are not included in the install.
    - `--no-scripts` is used as the script in the `composer.json` file presumes PHPCompatibility, while for most builds it will not be available.
    - For the non-sniff runs, the `installed_paths` command is run. For the sniff-run, a` composer install` (with `dev`) is run which will let the `post-install-cmd` run this for us.
* Adjusted the `PHP_BRANCH` environment variable values to be usable by Composer.
* Excludes the `vendor` directory from the PHP lint check in the Travis script.

WPCS own ruleset:
* Adds the PHPCompatibility standard, set the `testVersion` and exclude errors for PHP native constants which are back-filled by PHPCS.

Includes one `phpcs:ignore` for a correctly used function which is not always available.
2018-07-05 20:49:40 +02:00

112 lines
5.9 KiB
YAML

sudo: false
dist: trusty
cache:
apt: true
language:
- php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- nightly
env:
# `master` is now 3.x.
- PHPCS_BRANCH="dev-master" LINT=1
# Lowest supported release in the 3.x series with which WPCS is compatible (and which can run the unit tests).
- PHPCS_BRANCH="3.1.0"
# Lowest tagged release in the 2.x series with which WPCS is compatible.
- PHPCS_BRANCH="2.9.0"
matrix:
fast_finish: true
include:
# Run PHPCS against WPCS. I just picked to run it against 7.2.
- php: 7.2
env: PHPCS_BRANCH="dev-master" SNIFF=1
addons:
apt:
packages:
- libxml2-utils
# Test PHP 5.3 only against PHPCS 2.x as PHPCS 3.x has a minimum requirement of PHP 5.4.
- php: 5.3
env: PHPCS_BRANCH="2.9.*" LINT=1
dist: precise
# Test PHP 5.3 with short_open_tags set to On (is Off by default)
- php: 5.3
env: PHPCS_BRANCH="2.9.0" SHORT_OPEN_TAGS=true
dist: precise
allow_failures:
# Allow failures for unstable builds.
- php: nightly
before_install:
# Speed up build time by disabling Xdebug.
# https://johnblackbourn.com/reducing-travis-ci-build-times-for-wordpress-projects/
# https://twitter.com/kelunik/status/954242454676475904
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'
- export XMLLINT_INDENT=" "
- export PHPUNIT_DIR=/tmp/phpunit
- |
if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then
# --prefer-source is needed to ensure that the PHPCS unit test suite is available in PHPCS 2.9.
composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --prefer-source --update-no-dev --no-suggest --no-scripts
else
composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts
fi
- |
if [[ "$SNIFF" == "1" ]]; then
composer install --dev --no-suggest
# The post-install-cmd script takes care of the installed_paths.
else
# The above require already does the install.
$(pwd)/vendor/bin/phpcs --config-set installed_paths $(pwd)
fi
# Download PHPUnit 5.x for builds on PHP 7 and nightly as the PHPCS
# test suite is currently not compatible with PHPUnit 6.x.
# Fixed at a very specific PHPUnit version.
- if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-5.7.17.phar && chmod +x $PHPUNIT_DIR/phpunit-5.7.17.phar; fi
# Selectively adjust the ini values for the build image to test ini value dependent sniff features.
- if [[ "$SHORT_OPEN_TAGS" == "true" ]]; then echo "short_open_tag = On" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
script:
# Lint the PHP files against parse errors.
- if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi
# Run the unit tests.
- if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --filter WordPress $(pwd)/Test/AllTests.php; fi
- if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi
- if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress $(pwd)/Test/AllTests.php; fi
- if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi
# Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files.
# This is not an exhaustive test, but should give an early indication for typical fixer conflicts.
# For the first run, the exit code will be 1 (= all fixable errors fixed).
# `travis_retry` should then kick in to run the fixer again which should now return 0 (= no fixable errors found).
# All error codes for the PHPCBF: https://github.com/squizlabs/PHP_CodeSniffer/issues/1270#issuecomment-272768413
- if [[ "$SNIFF" == "1" ]]; then travis_retry $(pwd)/vendor/bin/phpcbf -p ./WordPress/Tests/ --standard=WordPress --extensions=inc --exclude=Generic.PHP.Syntax --report=summary; fi
# WordPress Coding Standards.
# @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
# @link http://pear.php.net/package/PHP_CodeSniffer/
- if [[ "$SNIFF" == "1" ]]; then $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi
# Validate the xml files.
# @link http://xmlsoft.org/xmllint.html
- if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./*/ruleset.xml; fi
- if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./phpcs.xml.dist.sample; fi
# Check the code-style consistency of the xml files.
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml"); fi
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml"); fi
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml"); fi
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml"); fi
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-VIP/ruleset.xml <(xmllint --format "./WordPress-VIP/ruleset.xml"); fi
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample"); fi
# Validate the composer.json file.
# @link https://getcomposer.org/doc/03-cli.md#validate
- if [[ "$LINT" == "1" ]]; then composer validate --no-check-all --strict; fi