From c95d26ea96dd309b5290a4d0c85c43f85791b280 Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Sat, 8 Jul 2023 06:30:18 +1200 Subject: [PATCH] chore(dev): Makefile to run project commands more easily Let's make it easy to run `phpcs`, `phpcbf`, `phpunit` ... Refs #104 maybe? --- .gitlab-ci.yml | 8 ++++++++ CHANGELOG.md | 1 + Makefile | 21 +++++++++++++++++++++ README.md | 27 ++++++++++++++++++--------- 4 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 Makefile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6940cda..4b32fe1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,6 +54,14 @@ Changelog: echo -e "⚠️\e[93m (or an explanatory comment in MR if it's not CHANGELOG-worthy)" exit 1 +Makefile: + image: registry.gitlab.com/behat-chrome/docker-chrome-headless + stage: lint + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + script: + - make --dry-run test_make + GrumPHP: image: composer stage: lint diff --git a/CHANGELOG.md b/CHANGELOG.md index 540c4dd..6ce4767 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog ## Unreleased * Error handling for invalid form values (#140) * Introduce code coverage in CI (!154, !160) +* Add `make` commands for development tasks (!159) ## 2.9.2 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..236a850 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +.PHONY: container install phpcbf phpcs test test_make + +docker_run=docker run --rm -t -v .:/code -e DOCROOT=/code/vendor/mink/driver-testsuite/web-fixtures registry.gitlab.com/behat-chrome/docker-chrome-headless + +# This is used to validate the makefile by calling each command with `-n`. +test_make: container install phpcs phpcbf test + +container: + $(docker_run) bash + +install: + $(docker_run) composer install --no-interaction + +phpcbf: install + $(docker_run) vendor/bin/phpcbf + +phpcs: install + $(docker_run) vendor/bin/phpcs + +test: install + $(docker_run) bash -c "sleep 3 && vendor/bin/phpunit" diff --git a/README.md b/README.md index ec83fd2..a81fe9a 100644 --- a/README.md +++ b/README.md @@ -45,22 +45,31 @@ Contributions are welcome! Use the [issue queue and merge requests to propose ch ## Tests -To run tests locally: +The project has test coverage, which you can execute using the commands below. -```bash -cd chrome-mink-driver -docker run --rm -it -v $(pwd):/code -e DOCROOT=/code/vendor/mink/driver-testsuite/web-fixtures registry.gitlab.com/behat-chrome/docker-chrome-headless bash -``` +Test execution requires a webserver configured to serve fixtures from [minkphp/driver-testsuite](https://github.com/minkphp/driver-testsuite/), which is provided by a docker image from the related [behat-chrome/docker-chrome-headless](https://gitlab.com/behat-chrome/docker-chrome-headless/) project. Tests executed are both [tests specific to this driver](https://gitlab.com/behat-chrome/chrome-mink-driver/-/tree/main/tests) and the more comprehensive test suite from [mink/driver-testsuite](https://github.com/minkphp/driver-testsuite/), which is the common testsuite to ensure consistency across Mink driver implementations. -Then in the shell: +### Using `make` -```bash +| command | purpose | +|--|--| +| `make install` | Install dependencies with `composer` | +| `make test` | Run tests with `phpunit` | +| `make phpcbf` | Tidy code using `phpcbf` | +| `make phpcs` | Check coding standards with `phpcs` | + +### Without `make` + +To perform these tasks without `make`, you can execute the same commands as above in a container. To run the tests using `phpunit`: +```text +docker run --rm -it -v .:/code -e DOCROOT=/code/vendor/mink/driver-testsuite/web-fixtures registry.gitlab.com/behat-chrome/docker-chrome-headless bash +``` +then, in the container shell: +```text composer install vendor/bin/phpunit ``` -This will execute both [tests specific to this driver](https://gitlab.com/behat-chrome/chrome-mink-driver/-/tree/main/tests) and the more comprehensive test suite from [mink/driver-testsuite](https://github.com/minkphp/driver-testsuite/), which is the common testsuite to ensure consistency across Mink driver implementations. - ## Versioning & releases - Releases are distributed through Packagist at https://packagist.org/packages/dmore/chrome-mink-driver