Skip to content

Commit ba0ab40

Browse files
rob006samdark
authored andcommitted
Added php-cs-fixer coding standards validation to Travis CI (#14100)
* 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.
1 parent ab68caa commit ba0ab40

File tree

504 files changed

+5790
-2890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

504 files changed

+5790
-2890
lines changed

.php_cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
if (!class_exists('yii\cs\YiisoftConfig', true)) {
4+
// @todo change error message
5+
fwrite(STDERR, "Your php-cs-version is outdated: please upgrade it.\n");
6+
die(16);
7+
}
8+
9+
return yii\cs\YiisoftConfig::create()
10+
->setCacheFile(__DIR__ . '/tests/runtime/php_cs.cache')
11+
->mergeRules([
12+
'braces' => [
13+
'allow_single_line_closure' => true,
14+
],
15+
])
16+
->setFinder(
17+
PhpCsFixer\Finder::create()
18+
->in(__DIR__)
19+
->exclude('docs')
20+
->exclude('apps')
21+
->exclude('extensions')
22+
// requirement checker should work even on PHP 4.3, so it needs special treatment
23+
->exclude('framework/requirements')
24+
->notPath('framework/classes.php')
25+
->notPath('framework/helpers/mimeTypes.php')
26+
->notPath('framework/views/messageConfig.php')
27+
// temporary disable messages processing - conflicts with header fixer
28+
->exclude('framework/messages')
29+
);

.travis.yml

+119-68
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,54 @@ sudo: false
2323

2424
language: php
2525

26-
php:
27-
- 5.4
28-
- 5.5
29-
- 5.6
30-
- 7.0
31-
- 7.1
32-
- nightly
26+
env:
27+
global:
28+
- DEFAULT_COMPOSER_FLAGS="--prefer-dist --no-interaction --no-progress --optimize-autoloader"
29+
- TASK_TESTS_PHP=1
30+
- TASK_TESTS_JS=0
31+
- TASK_TESTS_CS=0
32+
- TASK_TESTS_COVERAGE=0
33+
34+
35+
services:
36+
- memcached
37+
- mysql
38+
- postgresql
39+
40+
# cache vendor dirs
41+
cache:
42+
directories:
43+
- vendor
44+
- $HOME/.composer/cache
45+
- $HOME/.npm
46+
47+
# try running against postgres 9.3
48+
addons:
49+
postgresql: "9.3"
50+
code_climate:
51+
repo_token: 2935307212620b0e2228ab67eadd92c9f5501ddb60549d0d86007a354d56915b
3352

3453
matrix:
3554
fast_finish: true
3655
include:
56+
# test coding standards
57+
- php: 7.1
58+
env: TASK_TESTS_PHP=0 TASK_TESTS_CS=1
59+
# overwrite services used for PHP tests
60+
services:
61+
62+
# run tests coverage on PHP 7.1
63+
- php: 7.1
64+
env: TASK_TESTS_COVERAGE=1
65+
66+
- php: 7.0
67+
68+
- php: 5.6
69+
70+
- php: 5.5
71+
72+
- php: 5.4
73+
3774
# Test against HHVM 3.12 LTS version by using trusty
3875
- php: hhvm-3.12
3976
sudo: true
@@ -49,6 +86,7 @@ matrix:
4986
- mysql-client-5.6
5087
services:
5188
- mysql
89+
5290
# test against the latest HHVM version by using a newer image
5391
- php: hhvm
5492
sudo: true
@@ -66,98 +104,111 @@ matrix:
66104
services:
67105
- mysql
68106
- postgresql
107+
108+
- php: nightly
109+
69110
# have a separate branch for javascript tests
70111
- language: node_js
71112
node_js: 6
113+
env: TASK_TESTS_PHP=0 TASK_TESTS_JS=1
72114
dist: trusty
73-
# overwrite php related settings
74-
php:
115+
# overwrite services used for PHP tests
75116
services:
76-
addons:
77-
install:
78-
- travis_retry npm install
79-
# disable xdebug for performance in composer
80-
- phpenv config-rm xdebug.ini || echo "xdebug is not installed"
81-
- travis_retry composer self-update && composer --version
82-
- travis_retry composer install --prefer-dist --no-interaction
83-
before_script:
84-
- node --version
85-
- npm --version
86-
- php --version
87-
- composer --version
88-
script: npm test
89-
after_script:
90117

91118
allow_failures:
92119
- php: nightly
93120

121+
install:
122+
- |
123+
if [[ $TASK_TESTS_COVERAGE != 1 && $TRAVIS_PHP_VERSION != hhv* ]]; then
124+
# disable xdebug for performance reasons when code coverage is not needed. note: xdebug on hhvm is disabled by default
125+
phpenv config-rm xdebug.ini || echo "xdebug is not installed"
126+
fi
94127
95-
services:
96-
- memcached
97-
- mysql
98-
- postgresql
99-
100-
# cache vendor dirs
101-
cache:
102-
directories:
103-
- vendor
104-
- $HOME/.composer/cache
105-
- $HOME/.npm
128+
# install composer dependencies
129+
- travis_retry composer self-update
130+
- export PATH="$HOME/.composer/vendor/bin:$PATH"
131+
- |
132+
if [[ $TRAVIS_PHP_VERSION == "hhvm-3.12" ]]; then
133+
# remove php-cs-fixer from composer dependencies on hhvm-3.12 - php-cs-fixer requires at least hhvm-3.18
134+
composer remove friendsofphp/php-cs-fixer --dev
135+
fi
136+
- travis_retry composer install $DEFAULT_COMPOSER_FLAGS
106137

107-
# try running against postgres 9.3
108-
addons:
109-
postgresql: "9.3"
110-
code_climate:
111-
repo_token: 2935307212620b0e2228ab67eadd92c9f5501ddb60549d0d86007a354d56915b
138+
# setup PHP extension
139+
- |
140+
if [ $TASK_TESTS_PHP == 1 ]; then
141+
tests/data/travis/apc-setup.sh
142+
tests/data/travis/memcache-setup.sh
143+
tests/data/travis/imagick-setup.sh
144+
fi
112145
113-
install:
146+
# setup JS test
114147
- |
115-
if [[ $TRAVIS_PHP_VERSION != '7.1' && $TRAVIS_PHP_VERSION != hhv* ]]; then
116-
# disable xdebug for performance reasons when code coverage is not needed. note: xdebug on hhvm is disabled by default
117-
phpenv config-rm xdebug.ini || echo "xdebug is not installed"
148+
if [ $TASK_TESTS_JS == 1 ]; then
149+
travis_retry npm install
118150
fi
119-
- travis_retry composer self-update && composer --version
120-
- export PATH="$HOME/.composer/vendor/bin:$PATH"
121-
# core framework:
122-
- travis_retry composer install --prefer-dist --no-interaction
123-
- tests/data/travis/apc-setup.sh
124-
- tests/data/travis/memcache-setup.sh
125-
- tests/data/travis/imagick-setup.sh
126151
127152
before_script:
128153
# Disable the HHVM JIT for faster Unit Testing
129154
- if [[ $TRAVIS_PHP_VERSION = hhv* ]]; then echo 'hhvm.jit = 0' >> /etc/hhvm/php.ini; fi
155+
130156
# show some versions and env information
131-
- php -r "echo INTL_ICU_VERSION . \"\n\";"
132-
- php -r "echo INTL_ICU_DATA_VERSION . \"\n\";"
133-
- mysql --version
134-
- psql --version
157+
- php --version
158+
- composer --version
159+
- |
160+
if [ $TASK_TESTS_PHP == 1 ]; then
161+
php -r "echo INTL_ICU_VERSION . \"\n\";"
162+
php -r "echo INTL_ICU_DATA_VERSION . \"\n\";"
163+
psql --version
164+
mysql --version
165+
fi
166+
- |
167+
if [ $TASK_TESTS_JS == 1 ]; then
168+
node --version
169+
npm --version
170+
fi
135171
136172
# initialize databases
137-
- travis_retry mysql -e 'CREATE DATABASE `yiitest`;';
138-
- mysql -e "CREATE USER 'travis'@'localhost' IDENTIFIED WITH mysql_native_password;";
139-
- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'localhost' WITH GRANT OPTION;";
140-
- psql -U postgres -c 'CREATE DATABASE yiitest;';
173+
- |
174+
if [ $TASK_TESTS_PHP == 1 ]; then
175+
travis_retry mysql -e 'CREATE DATABASE `yiitest`;';
176+
mysql -e "CREATE USER 'travis'@'localhost' IDENTIFIED WITH mysql_native_password;";
177+
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'localhost' WITH GRANT OPTION;";
178+
psql -U postgres -c 'CREATE DATABASE yiitest;';
179+
fi
141180
142-
# enable code coverage on PHP 7.1, only one PHP version needs to generate coverage data
181+
# enable code coverage
143182
- |
144-
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
183+
if [ $TASK_TESTS_COVERAGE == 1 ]; then
145184
PHPUNIT_FLAGS="--coverage-clover=coverage.clover"
146185
fi
147186
148187
149188
script:
150-
# ensure no files contain UTF-8 byte order mark
151-
- 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
152-
# validate composer.json
153-
- composer validate --no-check-lock
154-
- cd framework && composer validate --no-check-lock && cd ..
155-
# run PHPUnit
156-
- vendor/bin/phpunit --verbose $PHPUNIT_FLAGS --exclude-group mssql,oci,wincache,xcache,zenddata,cubrid
189+
# test coding standards
190+
- |
191+
if [ $TASK_TESTS_CS == 1 ]; then
192+
composer validate --no-check-lock
193+
cd framework && composer validate --no-check-lock && cd ..
194+
vendor/bin/php-cs-fixer --diff --dry-run -v fix
195+
fi
196+
197+
# PHP tests
198+
- |
199+
if [ $TASK_TESTS_PHP == 1 ]; then
200+
vendor/bin/phpunit --verbose $PHPUNIT_FLAGS --exclude-group mssql,oci,wincache,xcache,zenddata,cubrid
201+
fi
202+
203+
# JS tests
204+
- |
205+
if [ $TASK_TESTS_JS == 1 ]; then
206+
npm test
207+
fi
157208
158209
after_script:
159210
- |
160-
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
211+
if [ $TASK_TESTS_COVERAGE == 1 ]; then
161212
travis_retry wget https://scrutinizer-ci.com/ocular.phar
162213
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
163214
fi

0 commit comments

Comments
 (0)