Skip to content

Commit f6a9111

Browse files
eraydbighappyface
authored andcommitted
Add composer scripts for checking / fixing code style (#356)
1 parent 48817e5 commit f6a9111

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ matrix:
2424
before_install:
2525
- if [[ "$WITH_COVERAGE" != "true" && "$TRAVIS_PHP_VERSION" != "hhvm" && "$TRAVIS_PHP_VERSION" != "nightly" && "$TRAVIS_PHP_VERSION" != "7.1" ]]; then phpenv config-rm xdebug.ini; fi
2626
- composer selfupdate
27+
- if [[ "$TRAVIS_PHP_VERSION" = "hhvm" || "$TRAVIS_PHP_VERSION" = "nightly" ]]; then sed -i '/^.*friendsofphp\/php-cs-fixer.*$/d' composer.json; fi
2728

2829
install:
2930
- travis_retry composer install --no-interaction --prefer-dist
3031

3132
script:
3233
- if [[ "$WITH_COVERAGE" == "true" ]]; then ./vendor/bin/phpunit --coverage-text; else composer test; fi
33-
- if [[ "$WITH_PHPCSFIXER" == "true" ]]; then composer require friendsofphp/php-cs-fixer:^2.1 && mkdir -p $HOME/.phpcsfixer && vendor/bin/php-cs-fixer fix --cache-file "$HOME/.phpcsfixer/.php_cs.cache" --dry-run --diff --verbose; fi
34+
- if [[ "$WITH_PHPCSFIXER" == "true" ]]; then mkdir -p $HOME/.phpcsfixer && vendor/bin/php-cs-fixer fix --cache-file "$HOME/.phpcsfixer/.php_cs.cache" --dry-run --diff --verbose; fi

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ will modify your original data.
195195
## Running the tests
196196

197197
```bash
198-
composer test
199-
composer testOnly TestClass
200-
composer testOnly TestClass::testMethod
198+
composer test # run all unit tests
199+
composer testOnly TestClass # run specific unit test class
200+
composer testOnly TestClass::testMethod # run specific unit test method
201+
composer style-check # check code style for errors
202+
composer style-fix # automatically fix code style errors
201203
```

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"require-dev": {
4242
"json-schema/JSON-Schema-Test-Suite": "1.2.0",
4343
"phpunit/phpunit": "^4.8.22",
44+
"friendsofphp/php-cs-fixer": "^2.1",
4445
"phpdocumentor/phpdocumentor": "~2"
4546
},
4647
"autoload": {
@@ -58,6 +59,8 @@
5859
"scripts": {
5960
"test" : "vendor/bin/phpunit",
6061
"testOnly" : "vendor/bin/phpunit --colors --filter",
61-
"coverage" : "vendor/bin/phpunit --coverage-text"
62+
"coverage" : "vendor/bin/phpunit --coverage-text",
63+
"style-check" : "vendor/bin/php-cs-fixer fix --dry-run --verbose --diff",
64+
"style-fix" : "vendor/bin/php-cs-fixer fix --verbose"
6265
}
6366
}

0 commit comments

Comments
 (0)