Exercism exercises in PHP
Follow these instructions to contribute to the PHP track. To solve the exercises, head to the PHP track and check the documentation.
This repo includes a dev container that provides PHP 8.4, composer, jq and all other dependencies out of the box.
Open the repo in VS Code (or GitHub Codespaces) and select "Reopen in Container".
For a non-devcontainer setup, see .devcontainer/ for exact setup.
In particular the required dependencies are: bash, jq, php8.4, composer, ext-gmp, ext-ds (v1.x), ext-intl.
Install composer dependencies with:
~/> composer install
contribution/> composer installbin/configlet is the official tool for managing Exercism language track repositories.
The tests are run with PHPUnit. Execute the following command to run the tests:
~/> composer tests:run # Runs whole test suite
~/> composer tests:run -- <slug> # Runs tests for <slug> (e.g. book-store)
~/> composer tests:run -- "b*" # Runs tests for <slug> starting with `b`bin/configlet fmt checks Exercism's ressources files (json).
composer lint:check checks PHP files using a slightly modified version of PSR-12.
Autofix (for both Exercism and PHP files) is provided with composer format:fix.
composer ci invokes the above checks: code style, tests.
- Read the documentation at Exercism.
- Follow the PSR-12 coding style (Exercism's PHP track uses a slightly modified version of PSR-12).
- Run
composer cito run CI checks locally before pushing. - CI runs on all pull requests, it must pass the required checks for merge.
- CI runs all tests on PHP 8.2 to PHP 8.4 for Linux, Windows and MacOS.
- Contribution tools are available.
Adding a new exercise involves multiple steps
Use bin/configlet create --practice-exercise <slug> to create the exercism resources required.
This provides you with the directories and files in exercises/practice/<slug>.
Look into tests.toml for which test cases not to implement / generate and mark them with include = false.
Once the directory structure is created either:
- Use
php contribution/main.php exercism:test:bootstrap <slug>to init a test file with tests bodies to implement. - Create a
<ExerciseSlug>Test.php.twigfile and runphp contribution/main.php exercism:test:generate <slug>to render the corresponding<ExerciseSlug>Test.phpfile.
A .meta/example.php file is also necessary in order to validate that the implementation is correct / achievable.
Run bin/order-exercises.sh when you set the exercise difficulty to a sensible value to order the exercises on the website accordingly.
Ensures that the test suite runs and that the files are properly formatted.