Skip to content

Commit

Permalink
Added php-cs-fixer coding standards validation to Travis CI (#14100)
Browse files Browse the repository at this point in the history
* php-cs-fixer: PSR2 rule.

* php-cs-fixer: PSR2 rule - fix views.

* Travis setup refactoring.

* Add php-cs-fixer to travis cs tests.

* Fix tests on hhvm-3.12

* improve travis config

* composer update

* revert composer update

* improve travis config

* Fix CS.

* Extract config to separate classes.

* Extract config to separate classes.

* Add file header.

* Force short array syntax.

* binary_operator_spaces fixer

* Fix broken tests

* cast_spaces fixer

* concat_space fixer

* dir_constant fixer

* ereg_to_preg fixer

* function_typehint_space fixer

* hash_to_slash_comment fixer

* is_null fixer

* linebreak_after_opening_tag fixer

* lowercase_cast fixer

* magic_constant_casing fixer

* modernize_types_casting fixer

* native_function_casing fixer

* new_with_braces fixer

* no_alias_functions fixer

* no_blank_lines_after_class_opening fixer

* no_blank_lines_after_phpdoc fixer

* no_empty_comment fixer

* no_empty_phpdoc fixer

* no_empty_statement fixer

* no_extra_consecutive_blank_lines fixer

* no_leading_import_slash fixer

* no_leading_namespace_whitespace fixer

* no_mixed_echo_print fixer

* no_multiline_whitespace_around_double_arrow fixer

* no_multiline_whitespace_before_semicolons fixer

* no_php4_constructor fixer

* no_short_bool_cast fixer

* no_singleline_whitespace_before_semicolons fixer

* no_spaces_around_offset fixer

* no_trailing_comma_in_list_call fixer

* no_trailing_comma_in_singleline_array fixer

* no_unneeded_control_parentheses fixer

* no_unused_imports fixer

* no_useless_return fixer

* no_whitespace_before_comma_in_array fixer

* no_whitespace_in_blank_line fixer

* not_operator_with_successor_space fixer

* object_operator_without_whitespace fixer

* ordered_imports fixer

* php_unit_construct fixer

* php_unit_dedicate_assert fixer

* php_unit_fqcn_annotation fixer

* phpdoc_indent fixer

* phpdoc_no_access fixer

* phpdoc_no_empty_return fixer

* phpdoc_no_package fixer

* phpdoc_no_useless_inheritdoc fixer

* Fix broken tests

* phpdoc_return_self_reference fixer

* phpdoc_single_line_var_spacing fixer

* phpdoc_single_line_var_spacing fixer

* phpdoc_to_comment fixer

* phpdoc_trim fixer

* phpdoc_var_without_name fixer

* psr4 fixer

* self_accessor fixer

* short_scalar_cast fixer

* single_blank_line_before_namespace fixer

* single_quote fixer

* standardize_not_equals fixer

* ternary_operator_spaces fixer

* trailing_comma_in_multiline_array fixer

* trim_array_spaces fixer

* protected_to_private fixer

* unary_operator_spaces fixer

* whitespace_after_comma_in_array fixer

* `parent::setRules()` -> `$this->setRules()`

* blank_line_after_opening_tag fixer

* Update finder config.

* Revert changes for YiiRequirementChecker.

* Fix array formatting.

* Add missing import.

* Fix CS for new code merged from master.

* Fix some indentation issues.
  • Loading branch information
rob006 authored and samdark committed Jun 12, 2017
1 parent ab68caa commit ba0ab40
Show file tree
Hide file tree
Showing 504 changed files with 5,790 additions and 2,890 deletions.
29 changes: 29 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

if (!class_exists('yii\cs\YiisoftConfig', true)) {
// @todo change error message
fwrite(STDERR, "Your php-cs-version is outdated: please upgrade it.\n");
die(16);
}

return yii\cs\YiisoftConfig::create()
->setCacheFile(__DIR__ . '/tests/runtime/php_cs.cache')
->mergeRules([
'braces' => [
'allow_single_line_closure' => true,
],
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('docs')
->exclude('apps')
->exclude('extensions')
// requirement checker should work even on PHP 4.3, so it needs special treatment
->exclude('framework/requirements')
->notPath('framework/classes.php')
->notPath('framework/helpers/mimeTypes.php')
->notPath('framework/views/messageConfig.php')
// temporary disable messages processing - conflicts with header fixer
->exclude('framework/messages')
);
187 changes: 119 additions & 68 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,54 @@ sudo: false

language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- nightly
env:
global:
- DEFAULT_COMPOSER_FLAGS="--prefer-dist --no-interaction --no-progress --optimize-autoloader"
- TASK_TESTS_PHP=1
- TASK_TESTS_JS=0
- TASK_TESTS_CS=0
- TASK_TESTS_COVERAGE=0


services:
- memcached
- mysql
- postgresql

# cache vendor dirs
cache:
directories:
- vendor
- $HOME/.composer/cache
- $HOME/.npm

# try running against postgres 9.3
addons:
postgresql: "9.3"
code_climate:
repo_token: 2935307212620b0e2228ab67eadd92c9f5501ddb60549d0d86007a354d56915b

matrix:
fast_finish: true
include:
# test coding standards
- php: 7.1
env: TASK_TESTS_PHP=0 TASK_TESTS_CS=1
# overwrite services used for PHP tests
services:

# run tests coverage on PHP 7.1
- php: 7.1
env: TASK_TESTS_COVERAGE=1

- php: 7.0

- php: 5.6

- php: 5.5

- php: 5.4

# Test against HHVM 3.12 LTS version by using trusty
- php: hhvm-3.12
sudo: true
Expand All @@ -49,6 +86,7 @@ matrix:
- mysql-client-5.6
services:
- mysql

# test against the latest HHVM version by using a newer image
- php: hhvm
sudo: true
Expand All @@ -66,98 +104,111 @@ matrix:
services:
- mysql
- postgresql

- php: nightly

# have a separate branch for javascript tests
- language: node_js
node_js: 6
env: TASK_TESTS_PHP=0 TASK_TESTS_JS=1
dist: trusty
# overwrite php related settings
php:
# overwrite services used for PHP tests
services:
addons:
install:
- travis_retry npm install
# disable xdebug for performance in composer
- phpenv config-rm xdebug.ini || echo "xdebug is not installed"
- travis_retry composer self-update && composer --version
- travis_retry composer install --prefer-dist --no-interaction
before_script:
- node --version
- npm --version
- php --version
- composer --version
script: npm test
after_script:

allow_failures:
- php: nightly

install:
- |
if [[ $TASK_TESTS_COVERAGE != 1 && $TRAVIS_PHP_VERSION != hhv* ]]; then
# disable xdebug for performance reasons when code coverage is not needed. note: xdebug on hhvm is disabled by default
phpenv config-rm xdebug.ini || echo "xdebug is not installed"
fi
services:
- memcached
- mysql
- postgresql

# cache vendor dirs
cache:
directories:
- vendor
- $HOME/.composer/cache
- $HOME/.npm
# install composer dependencies
- travis_retry composer self-update
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- |
if [[ $TRAVIS_PHP_VERSION == "hhvm-3.12" ]]; then
# remove php-cs-fixer from composer dependencies on hhvm-3.12 - php-cs-fixer requires at least hhvm-3.18
composer remove friendsofphp/php-cs-fixer --dev
fi
- travis_retry composer install $DEFAULT_COMPOSER_FLAGS

# try running against postgres 9.3
addons:
postgresql: "9.3"
code_climate:
repo_token: 2935307212620b0e2228ab67eadd92c9f5501ddb60549d0d86007a354d56915b
# setup PHP extension
- |
if [ $TASK_TESTS_PHP == 1 ]; then
tests/data/travis/apc-setup.sh
tests/data/travis/memcache-setup.sh
tests/data/travis/imagick-setup.sh
fi
install:
# setup JS test
- |
if [[ $TRAVIS_PHP_VERSION != '7.1' && $TRAVIS_PHP_VERSION != hhv* ]]; then
# disable xdebug for performance reasons when code coverage is not needed. note: xdebug on hhvm is disabled by default
phpenv config-rm xdebug.ini || echo "xdebug is not installed"
if [ $TASK_TESTS_JS == 1 ]; then
travis_retry npm install
fi
- travis_retry composer self-update && composer --version
- export PATH="$HOME/.composer/vendor/bin:$PATH"
# core framework:
- travis_retry composer install --prefer-dist --no-interaction
- tests/data/travis/apc-setup.sh
- tests/data/travis/memcache-setup.sh
- tests/data/travis/imagick-setup.sh
before_script:
# Disable the HHVM JIT for faster Unit Testing
- if [[ $TRAVIS_PHP_VERSION = hhv* ]]; then echo 'hhvm.jit = 0' >> /etc/hhvm/php.ini; fi

# show some versions and env information
- php -r "echo INTL_ICU_VERSION . \"\n\";"
- php -r "echo INTL_ICU_DATA_VERSION . \"\n\";"
- mysql --version
- psql --version
- php --version
- composer --version
- |
if [ $TASK_TESTS_PHP == 1 ]; then
php -r "echo INTL_ICU_VERSION . \"\n\";"
php -r "echo INTL_ICU_DATA_VERSION . \"\n\";"
psql --version
mysql --version
fi
- |
if [ $TASK_TESTS_JS == 1 ]; then
node --version
npm --version
fi
# initialize databases
- travis_retry mysql -e 'CREATE DATABASE `yiitest`;';
- mysql -e "CREATE USER 'travis'@'localhost' IDENTIFIED WITH mysql_native_password;";
- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'localhost' WITH GRANT OPTION;";
- psql -U postgres -c 'CREATE DATABASE yiitest;';
- |
if [ $TASK_TESTS_PHP == 1 ]; then
travis_retry mysql -e 'CREATE DATABASE `yiitest`;';
mysql -e "CREATE USER 'travis'@'localhost' IDENTIFIED WITH mysql_native_password;";
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'localhost' WITH GRANT OPTION;";
psql -U postgres -c 'CREATE DATABASE yiitest;';
fi
# enable code coverage on PHP 7.1, only one PHP version needs to generate coverage data
# enable code coverage
- |
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
if [ $TASK_TESTS_COVERAGE == 1 ]; then
PHPUNIT_FLAGS="--coverage-clover=coverage.clover"
fi
script:
# ensure no files contain UTF-8 byte order mark
- if ! grep -rlI $'\xEF\xBB\xBF' framework/ ; then echo "no utf8 BOM found"; else echo "found utf8 BOM in some files. See above."; exit 1; fi
# validate composer.json
- composer validate --no-check-lock
- cd framework && composer validate --no-check-lock && cd ..
# run PHPUnit
- vendor/bin/phpunit --verbose $PHPUNIT_FLAGS --exclude-group mssql,oci,wincache,xcache,zenddata,cubrid
# test coding standards
- |
if [ $TASK_TESTS_CS == 1 ]; then
composer validate --no-check-lock
cd framework && composer validate --no-check-lock && cd ..
vendor/bin/php-cs-fixer --diff --dry-run -v fix
fi
# PHP tests
- |
if [ $TASK_TESTS_PHP == 1 ]; then
vendor/bin/phpunit --verbose $PHPUNIT_FLAGS --exclude-group mssql,oci,wincache,xcache,zenddata,cubrid
fi
# JS tests
- |
if [ $TASK_TESTS_JS == 1 ]; then
npm test
fi
after_script:
- |
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
if [ $TASK_TESTS_COVERAGE == 1 ]; then
travis_retry wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
fi
Loading

0 comments on commit ba0ab40

Please sign in to comment.