-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
71 lines (62 loc) · 2.16 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
########################################################
# Constants
########################################################
# Console Colors
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM=20
# PHPUnit and Infection
INFECTION_DATA_DIR := infection
DEPENDENCY_DIR := ./vendor
VENDOR_BIN_PATH := $(DEPENDENCY_DIR)/bin
PHPUNIT_EXEC := $(VENDOR_BIN_PATH)/phpunit
INFECTION_EXEC := $(VENDOR_BIN_PATH)/infection
COMPOSER_INSTALL := composer install
########################################################
# Automatic Help Generator
########################################################
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
########################################################
# Commands
########################################################
.PHONY: install file_test dir_tests all_tests coverage infection
## install all the dependencies
install:
@$(COMPOSER_INSTALL)
## run a specific test file ==> format: file=path/to/file
method_test:
@$(PHPUNIT_EXEC) --filter $(method) --no-coverage $(file)
## run a specific test file ==> format: file=path/to/file
file_test:
@$(PHPUNIT_EXEC) --no-coverage $(file)
## run all tests inside a directory ==> format: dir=path/to/directory
dir_tests:
@$(PHPUNIT_EXEC) --no-coverage $(dir)
## run all tests
all_tests:
@$(PHPUNIT_EXEC) --no-coverage
## generate test coverage (required for infection)
coverage:
@$(PHPUNIT_EXEC)
## run infection to see how quality the tests are
infection:
@[ -d $(INFECTION_DATA_DIR) ] || $(PHPUNIT_EXEC)
@composer require --dev infection/infection
@$(INFECTION_EXEC) --coverage=$(INFECTION_DATA_DIR)
@composer remove --dev infection/infection