Tests, code quality and code style

Workflow

Every time changes are introduced into the library, Github Actions run the tests.

GitHub Actions uses a PHP quality tool, GrumPHP, to orchestrate all these tasks at each commit on the local machine, but also in GitHub actions.

This facilitate the job of the contributors, the command to run locally for the tests is the same as the one that are triggered on the continuous integration.

The GrumPHP configuration is provided by the package drupol/php-conventions which configure a set of default tasks tailored for PHP projects.

To run all the tests tasks locally, do

./vendor/bin/grumphp run

Here’s an example of output that shows all the tasks that are setup in GrumPHP and that will check your code

$ ./vendor/bin/grumphp run
GrumPHP is sniffing your code!
Running task  1/13: license... ✔
Running task  2/13: composer_require_checker... ✔
Running task  3/13: composer... ✔
Running task  4/13: composer_normalize... ✔
Running task  5/13: yamllint... ✔
Running task  6/13: jsonlint... ✔
Running task  7/13: phplint... ✔
Running task  8/13: twigcs... ✔
Running task  9/13: phpcsfixer... ✔
Running task 10/13: psalm... ✔
Running task 11/13: phpstan... ✔
Running task 12/13: phpunit... ✔
Running task 13/13: infection... ✔

Static analysis tests

Static analysis tests are achieved by running PHPStan and PSalm in the directory tests/static-analysis.

To run the static-analysis tests only, do:

./vendor/bin/grumphp run --tasks=phpstan,psalm

Unit tests

Tests are written with PHPUnit and you can find the coverage percentage on a badge on the README file.

PHPInfection is also triggered used to ensure that your code is properly tested.

To run the unit tests only, do:

./vendor/bin/grumphp run --tasks=phpunit,infection

Code style

The PHP code style in use is based on PSR-12 plus a set of custom rules, the rules are defined in the package drupol/phpcsfixer-configs-php.

To run the code style tests only, do:

./vendor/bin/grumphp run --tasks=phpcsfixer

The check other files, we use Prettier. To run Prettier across the whole project, do:

nix run nixpkgs#nodePackages.prettier --impure -- --write .

Documentation

The project’s documentation is built with Sphinx. To run a local documentation server and check if your changes are fine, do:

sphinx-autobuild ./docs build/docs