|
| 1 | +SHELL = /bin/sh |
| 2 | + |
| 3 | +DOCKER ?= $(shell which docker) |
| 4 | +VOLUME := /srv |
| 5 | +IMAGE ?= graze/php-alpine:test |
| 6 | +DOCKER_RUN := ${DOCKER} run --rm -t -v $$(pwd):${VOLUME} -w ${VOLUME} ${IMAGE} |
| 7 | + |
| 8 | +PREFER_LOWEST ?= |
| 9 | + |
| 10 | +.PHONY: build build-update composer-% clean help run |
| 11 | +.PHONY: lint lint-fix |
| 12 | +.PHONY: test test-unit test-lowest test-matrix test-coverage test-coverage-html test-coverage-clover |
| 13 | + |
| 14 | +.SILENT: help |
| 15 | + |
| 16 | +# Building |
| 17 | + |
| 18 | +build: ## Download the dependencies then build the image :rocket:. |
| 19 | + make 'composer-install --prefer-dist --optimize-autoloader' |
| 20 | + |
| 21 | +build-update: ## Update all dependencies |
| 22 | + make 'composer-update --prefer-dist --optimize-autoloader ${PREFER_LOWEST}' |
| 23 | + |
| 24 | +composer-%: ## Run a composer command, `make "composer-<command> [...]"`. |
| 25 | + ${DOCKER} run -t --rm \ |
| 26 | + -v $$(pwd):/app \ |
| 27 | + -v ~/.composer:/tmp \ |
| 28 | + composer --ansi --no-interaction $* $(filter-out $@,$(MAKECMDGOALS)) |
| 29 | + |
| 30 | +# Testing |
| 31 | + |
| 32 | +test: ## Run the unit and integration testsuites. |
| 33 | +test: lint test-unit |
| 34 | + |
| 35 | +lint: ## Run phpcs against the code. |
| 36 | + ${DOCKER_RUN} vendor/bin/phpcs -p --warning-severity=0 src/ tests/ |
| 37 | + |
| 38 | +lint-fix: ## Run phpcsf and fix possible lint errors. |
| 39 | + ${DOCKER_RUN} vendor/bin/phpcbf -p src/ tests/ |
| 40 | + |
| 41 | +test-unit: ## Run the unit testsuite. |
| 42 | + ${DOCKER_RUN} vendor/bin/phpunit --testsuite unit |
| 43 | + |
| 44 | +test-lowest: ## Test using the lowest possible versions of the dependencies |
| 45 | +test-lowest: PREFER_LOWEST=--prefer-lowest --prefer-stable |
| 46 | +test-lowest: build-update test |
| 47 | + |
| 48 | +test-matrix: ## Run the unit tests against multiple targets. |
| 49 | + ${MAKE} IMAGE="php:5.6-alpine" test |
| 50 | + ${MAKE} IMAGE="php:7.0-alpine" test |
| 51 | + ${MAKE} IMAGE="php:7.1-alpine" test |
| 52 | + ${MAKE} IMAGE="hhvm/hhvm:latest" test |
| 53 | + |
| 54 | +test-matrix-lowest: ## Run the unit tests against |
| 55 | + ${MAKE} build-update PREFER_LOWEST='--prefer-lowest --prefer-stable' |
| 56 | + ${MAKE} test-matrix |
| 57 | + ${MAKE} build-update |
| 58 | + |
| 59 | +test-coverage: ## Run all tests and output coverage to the console. |
| 60 | + ${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-text |
| 61 | + |
| 62 | +test-coverage-html: ## Run all tests and output coverage to html. |
| 63 | + ${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-html=./tests/report/html |
| 64 | + |
| 65 | +test-coverage-clover: ## Run all tests and output clover coverage to file. |
| 66 | + ${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-clover=./tests/report/coverage.clover |
| 67 | + |
| 68 | +# Help |
| 69 | + |
| 70 | +help: ## Show this help message. |
| 71 | + echo "usage: make [target] ..." |
| 72 | + echo "" |
| 73 | + echo "targets:" |
| 74 | + egrep '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#' |
0 commit comments