Snippets to quickly stand up PHPUnit Tests, PHPMD, and php-cs-fixer for local development + CI/CD in a Laravel project.
This is basically a copy-paste dump for files and snippets.
- Make sure you've installed the latest stable versions of the 3 composer packages listed in
composer.json - Add the
scriptssection contents to your existingscriptsincomposer.json - Copy paste the following files into your repo at root level and adjust / tweak as needed:
.php_cs.distphpmd.xmlphpunit.xml
Feel free to copy paste the contents of README_SAMPLE.md Following are said contents in readable form.
You can quickly run all of the same tests Gitlab CI runs using composer ci.
You can run the project's PHPUnit test suite using composer test.
You can generate a code coverage report using composer coverage.
You can run composer cs-fix to fix code style issues, or simply composer cs for a dry run.
You can sniff out code smells using PHP Mess Detector by running composer phpmd.
For unit test coverage (I've only tested this in Gitlab), use composer test-ci to generate code coverage metrics for the test stage. Use the cs-fixer and phpmd commands as outlined above.