This is an example implementation of the custom PHP-CS-Fixer rule.
Run composer install
or composer update
.
Run composer fix
to reset the source files and apply the
custom rule.
Run composer test
to check if the custom rule produced the
expected result.
Here's how this whole thing works:
- The command
composer fix
is defined as a composer script inside thecomposer.json
file. It does the following:- Copy (with overwrite) the file from
tests/data/Original.php
tosrc/File.php
. - Execute PHP-CS-Fixer with the
fix
command, using the configuration provided in.php_cs.dist
file.
- Copy (with overwrite) the file from
- PHP-CS-Fixer configuration sets only a single rule to be
used for the run. That rule is a custom fixer, which lives
in
config/
folder. The rule file is modified from another rule -NoUnreachableDefaultArgumentValueFixer
, which is a part of the PHP-CS-Fixer distribution. - PHP-CS-Fixer runs and modifies all file PHP files in the
src/
folder.
For easier testing, PHPUnit is setup in the tests/
folder. It runs
like so:
- The command
composer test
is defined as composer script inside thecomposer.json
file. It simply runs PHPUnit with thetests/
as test location parameter. - Example test file consists of two tests:
- Basic test with a single assertion for the true=true.
- File test, which makes sure that resulting file exists in
the
src/
folder, that expected file exists intests/data
folder, and that the content of these two files is the same.