2727 # Lowest supported release in the 3.x series with which WPCS is compatible.
2828 - PHPCS_BRANCH="3.3.1"
2929
30- matrix :
30+ # Define the stages used.
31+ # For non-PRs, only the sniff, ruleset and quicktest stages are run.
32+ # For pull requests and merges, the full script is run (skipping quicktest).
33+ # Note: for pull requests, "develop" should be the base branch name.
34+ # See: https://docs.travis-ci.com/user/conditions-v1
35+ stages :
36+ - name : sniff
37+ - name : rulesets
38+ - name : quicktest
39+ if : type = push AND branch NOT IN (master, develop)
40+ - name : test
41+ if : branch IN (master, develop)
42+
43+ jobs :
3144 fast_finish : true
3245 include :
33- # Run PHPCS against WPCS. I just picked to run it against 7.2.
34- - php : 7.2
35- env : PHPCS_BRANCH="dev-master" SNIFF=1
46+ # ### SNIFF STAGE ####
47+ - stage : sniff
48+ php : 7.3
49+ env : PHPCS_BRANCH="dev-master"
3650 addons :
3751 apt :
3852 packages :
3953 - libxml2-utils
54+ script :
55+ # WordPress Coding Standards.
56+ # @link https://github.com/WordPress/WordPress-Coding-Standards
57+ # @link http://pear.php.net/package/PHP_CodeSniffer/
58+ - $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1
59+
60+ # Validate the xml files.
61+ # @link http://xmlsoft.org/xmllint.html
62+ # For the build to properly error when validating against a scheme, these each have to be in their own condition.
63+ - xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml
64+ - xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample
65+
66+ # Check the code-style consistency of the xml files.
67+ - diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml")
68+ - diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml")
69+ - diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml")
70+ - diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml")
71+ - diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample")
72+
73+ # ### RULESET STAGE ####
74+ # Make sure the rulesets don't throw unexpected errors or warnings.
75+ # This check needs to be run against a high PHP version to prevent triggering the syntax error check.
76+ # It also needs to be run against all PHPCS versions WPCS is tested against.
77+ - stage : rulesets
78+ php : 7.3
79+ env : PHPCS_BRANCH="dev-master"
80+ script :
81+ - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Core
82+ - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Docs
83+ - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Extra
84+ - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress
85+
86+ # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files.
87+ # This is not an exhaustive test, but should give an early indication for typical fixer conflicts.
88+ # For the first run, the exit code will be 1 (= all fixable errors fixed).
89+ # `travis_retry` should then kick in to run the fixer again which should now return 0 (= no fixable errors found).
90+ # All error codes for the PHPCBF: https://github.com/squizlabs/PHP_CodeSniffer/issues/1270#issuecomment-272768413
91+ - travis_retry $(pwd)/vendor/bin/phpcbf -pq ./WordPress/Tests/ --standard=WordPress --extensions=inc --exclude=Generic.PHP.Syntax --report=summary
92+
93+ - stage : rulesets
94+ php : 7.3
95+ env : PHPCS_BRANCH="3.3.1"
96+ script :
97+ - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Core
98+ - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Docs
99+ - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Extra
100+ - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress
101+
102+ # ### QUICK TEST STAGE ####
103+ # This is a much quicker test which only runs the unit tests and linting against the low/high
104+ # supported PHP/PHPCS combinations.
105+ - stage : quicktest
106+ php : 7.3
107+ env : PHPCS_BRANCH="dev-master" LINT=1
108+ - php : 7.3
109+ env : PHPCS_BRANCH="3.3.1"
110+ - php : 5.4
111+ env : PHPCS_BRANCH="dev-master" LINT=1
112+ - php : 5.4
113+ env : PHPCS_BRANCH="3.3.1"
40114
41115 allow_failures :
42116 # Allow failures for unstable builds.
@@ -47,11 +121,19 @@ before_install:
47121 # https://johnblackbourn.com/reducing-travis-ci-build-times-for-wordpress-projects/
48122 # https://twitter.com/kelunik/status/954242454676475904
49123 - phpenv config-rm xdebug.ini || echo 'No xdebug config.'
124+
125+ # On stable PHPCS versions, allow for PHP deprecation notices.
126+ # Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
127+ - |
128+ if [[ "$TRAVIS_BUILD_STAGE_NAME" != "Sniff" && $PHPCS_BRANCH != "dev-master" ]]; then
129+ echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
130+ fi
131+
50132 - export XMLLINT_INDENT=" "
51133 - export PHPUNIT_DIR=/tmp/phpunit
52134 - composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts
53135 - |
54- if [[ "$SNIFF " == "1 " ]]; then
136+ if [[ "$TRAVIS_BUILD_STAGE_NAME " == "Sniff " ]]; then
55137 composer install --dev --no-suggest
56138 # The `dev` required DealerDirect Composer plugin takes care of the installed_paths.
57139 else
@@ -63,42 +145,17 @@ before_install:
63145 - if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-7.phar && chmod +x $PHPUNIT_DIR/phpunit-7.phar; fi
64146
65147script :
66- # Lint the PHP files against parse errors.
67- - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi
68- # Run the unit tests.
69- - |
70- if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then
71- php $PHPUNIT_DIR/phpunit-7.phar --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php
72- else
73- phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php
74- fi
75- # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files.
76- # This is not an exhaustive test, but should give an early indication for typical fixer conflicts.
77- # For the first run, the exit code will be 1 (= all fixable errors fixed).
78- # `travis_retry` should then kick in to run the fixer again which should now return 0 (= no fixable errors found).
79- # All error codes for the PHPCBF: https://github.com/squizlabs/PHP_CodeSniffer/issues/1270#issuecomment-272768413
80- - if [[ "$SNIFF" == "1" ]]; then travis_retry $(pwd)/vendor/bin/phpcbf -p ./WordPress/Tests/ --standard=WordPress --extensions=inc --exclude=Generic.PHP.Syntax --report=summary; fi
81- # Make sure the rulesets don't thrown unexpected errors or warnings.
82- # This check needs to be run against a high PHP version to prevent triggering the syntax error check.
83- # It also needs to be run against all PHPCS versions WPCS is tested against.
84- - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Core; fi
85- - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Docs; fi
86- - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Extra; fi
87- - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress; fi
88- # WordPress Coding Standards.
89- # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
90- # @link http://pear.php.net/package/PHP_CodeSniffer/
91- - if [[ "$SNIFF" == "1" ]]; then $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi
92- # Validate the xml files.
93- # @link http://xmlsoft.org/xmllint.html
94- - if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml; fi
95- - if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample; fi
96- # Check the code-style consistency of the xml files.
97- - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml"); fi
98- - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml"); fi
99- - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml"); fi
100- - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml"); fi
101- - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample"); fi
102- # Validate the composer.json file.
103- # @link https://getcomposer.org/doc/03-cli.md#validate
104- - if [[ "$LINT" == "1" ]]; then composer validate --no-check-all --strict; fi
148+ # Lint the PHP files against parse errors.
149+ - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi
150+
151+ # Validate the composer.json file.
152+ # @link https://getcomposer.org/doc/03-cli.md#validate
153+ - if [[ "$LINT" == "1" ]]; then composer validate --no-check-all --strict; fi
154+
155+ # Run the unit tests.
156+ - |
157+ if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then
158+ php $PHPUNIT_DIR/phpunit-7.phar --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php
159+ else
160+ phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php
161+ fi
0 commit comments