diff --git a/README.md b/README.md index e13b9097c..2551573cc 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,60 @@ # Exercism PHP Track -![Configlet Status](https://github.com/exercism/php/workflows/Configlet%20CI/badge.svg) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/68242198cd124a3ebcbdc291d0e0eda4)](https://www.codacy.com/app/borgogelli/php?utm_source=github.com&utm_medium=referral&utm_content=borgogelli/php&utm_campaign=Badge_Grade) - Exercism exercises in PHP -## Install Dependencies +Follow these instructions, if you want to contribute to the track. +You must have a BASH shell to run the tooling locally. -### All dependencies +If you only want to solve the exercises, go to the [track docs][track-docs] and choose your installation option there. -```shell -> ./bin/install.sh -``` +## Install Dependencies -### Only tests dependencies +You must have installed `composer` as a global tool as recommended in the [PHP track installation docs][composer-installation-docs]. ```shell -> ./bin/install-phpunit-9.sh +bin/fetch-configlet +composer install ``` -### Only style-check dependencies +You now have all tools required to contribute. -```shell -> ./bin/install-phpcs.sh -``` +## Running Exercism resources management + +`bin/configlet` is a tool to manage exercism resources in this track. +See [Building Exercism docs][configlet-docs]. ## Running Unit Test Suite -### PHPUnit 9 +We use PHPUnit 9.6.x and a shell loop injecting `exemplar.php` as the solution for testing: ```shell -> PHPUNIT_BIN="./bin/phpunit-9.phar" ./bin/test.sh +composer test:run ``` ## Running Style Checker -### PSR-12 rules +We apply PSR-12 rules with minor tweaks and some exceptions: ```shell -> PHPCS_BIN="./bin/phpcs.phar" PHPCS_RULES="./phpcs-php.xml" ./bin/lint.sh +composer lint:check +``` + +To auto-fix the coding styles: + +```shell +composer lint:fix ``` ## Contributing - Read the documentation at [Exercism][docs]. -- Follow the [PSR-12] coding style (PHP uses a slightly [modified] version of [PSR-12]). +- Follow the [PSR-12] coding style (Exercisms PHP track uses a slightly [modified] version of [PSR-12]). - CI is run on all pull requests, it must pass the required checks for merge. +- CI is running all tests on PHP 8.0 to PHP 8.2 -[psr-12]: https://www.php-fig.org/psr/psr-12 +[composer-installation-docs]: https://exercism.org/docs/tracks/php/installation#h-install-composer +[configlet-docs]: https://exercism.org/docs/building/configlet [docs]: https://exercism.org/docs -[@group annotation]: https://phpunit.de/manual/4.1/en/appendixes.annotations.html#appendixes.annotations.group [modified]: phpcs-php.xml +[psr-12]: https://www.php-fig.org/psr/psr-12 +[track-docs]: https://exercism.org/docs/tracks/php/installation diff --git a/bin/install-phpcs.sh b/bin/install-phpcs.sh deleted file mode 100755 index 9ee6fbf35..000000000 --- a/bin/install-phpcs.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -curl -Lo bin/phpcs.phar https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -chmod +x bin/phpcs.phar diff --git a/bin/install-phpunit-9.sh b/bin/install-phpunit-9.sh deleted file mode 100755 index 88452628c..000000000 --- a/bin/install-phpunit-9.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -curl -Lo ./bin/phpunit-9.phar https://phar.phpunit.de/phpunit-9.phar -chmod +x bin/phpunit-9.phar diff --git a/bin/install.sh b/bin/install.sh deleted file mode 100755 index 1507bc580..000000000 --- a/bin/install.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -./bin/install-phpunit-9.sh -./bin/install-phpcs.sh diff --git a/bin/lint.sh b/bin/lint.sh deleted file mode 100755 index ca89e9fdc..000000000 --- a/bin/lint.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env bash - -set -uo pipefail - -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -NC='\033[0m' # No Color - -function main { - has_failures=0 - - all_exercise_dirs=$(find ./exercises -maxdepth 2 -mindepth 2 -type d | sort) - for exercise_dir in $all_exercise_dirs; do - if [[ "${exercise_dir}" == *"hello-world"* ]]; then - continue - fi - - lint "${exercise_dir}" - if [[ $? -ne 0 ]]; then - has_failures=1 - fi - done - - return $has_failures -} - -function lint { - exercise_dir="${1}" - exercise=$(basename "${exercise_dir}") - echo -e "Checking ${YELLOW}${exercise}${NC} against PHP code standards" - - eval "${PHPCS_BIN}" \ - -sp \ - --standard="${PHPCS_RULES}" \ - "${exercise_dir}" -} - -function installed { - cmd=$(command -v "${1}") - - [[ -n "${cmd}" ]] && [[ -f "${cmd}" ]] - return ${?} -} - -function die { - >&2 echo "Fatal: ${@}" - exit 1 -} - -if [[ -z "${PHPCS_BIN:-}" ]]; then - die "Missing PHPCS_BIN environment variable"; -fi - -if [[ -z "${PHPCS_RULES:-}" ]]; then - die "Missing PHPCS_RULES environment variable"; -fi - -if [[ ! -f "${PHPCS_RULES}" ]]; then - die "PHPCS xml ruleset at '${PHPCS_RULES}' does not exist" -fi - -# Check for all required dependencies -deps=(curl "${PHPCS_BIN}") -for dep in "${deps[@]}"; do - installed "${dep}" || die "Missing '${dep}'" -done - -main "$@" - -if [[ $? -ne 0 ]]; then - echo -e "Some checks ${RED}failed${NC}. See log." - exit 1 -fi - -exit diff --git a/composer.json b/composer.json index 020412543..015156591 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,13 @@ }, "require-dev": { "php": "^7.4|^8.0", + "phpunit/phpunit": "^9.6", "slevomat/coding-standard": "^8.5", "squizlabs/php_codesniffer": "^3.6" }, "scripts": { "lint:check": "phpcs --standard=phpcs-php.xml", - "lint:fix": "phpcbf --standard=phpcs-php.xml" + "lint:fix": "phpcbf --standard=phpcs-php.xml", + "tests:run": "PHPUNIT_BIN='phpunit' bin/test.sh" } }