Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit b9183d7

Browse files
committed
Add tests
1 parent 36258cf commit b9183d7

File tree

12 files changed

+428
-1
lines changed

12 files changed

+428
-1
lines changed

Makefile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# set all to phony
2+
SHELL=bash
3+
4+
.PHONY: *
5+
6+
DOCKER_CGROUP:=$(shell cat /proc/1/cgroup | grep docker | wc -l)
7+
8+
ifneq ("$(wildcard /.dockerenv)","")
9+
IN_DOCKER=TRUE
10+
else ifneq ("$(DOCKER_CGROUP)","0")
11+
IN_DOCKER=TRUE
12+
else
13+
IN_DOCKER=FALSe
14+
endif
15+
16+
ifeq ("$(IN_DOCKER)","TRUE")
17+
DOCKER_RUN=
18+
else
19+
DOCKER_RUN=docker run --rm -it \
20+
-v "`pwd`:`pwd`" \
21+
-w "`pwd`" \
22+
"wyrihaximusnet/php:7.4-nts-alpine3.12-dev"
23+
endif
24+
25+
all: syntax-php cs-fix cs stan psalm unit infection composer-require-checker composer-unused backward-compatibility-check
26+
27+
syntax-php: ## Lint PHP syntax
28+
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor .
29+
30+
cs: ## Check the code for code style issues
31+
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(shell nproc)
32+
33+
cs-fix: ## Fix any automatically fixable code style issues
34+
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc)
35+
36+
stan: ## Run static analysis (PHPStan)
37+
$(DOCKER_RUN) vendor/bin/phpstan analyse src tests --level max --ansi -c phpstan.neon
38+
39+
psalm: ## Run static analysis (Psalm)
40+
$(DOCKER_RUN) vendor/bin/psalm --threads=$(shell nproc) --shepherd --stats
41+
42+
unit: ## Run tests
43+
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml
44+
45+
unit-ci: unit
46+
if [ -f ./build/logs/clover.xml ]; then wget https://scrutinizer-ci.com/ocular.phar && sleep 3 && php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml; fi
47+
48+
infection: ## Run mutation testing
49+
$(DOCKER_RUN) vendor/bin/infection --ansi --min-msi=100 --min-covered-msi=100 --threads=$(shell nproc) --ignore-msi-with-no-mutations
50+
51+
composer-require-checker: ## Ensure we require every package used in this package directly
52+
$(DOCKER_RUN) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=composer-require-checker.json
53+
54+
composer-unused: ## Ensure we don't require any package we don't use in this package directly
55+
$(DOCKER_RUN) composer unused --ansi
56+
57+
backward-compatibility-check: ## Check code for backwards incompatible changes
58+
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check || true
59+
60+
task-list-ci:
61+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | jq --raw-input --slurp -c 'split("\n")| .[0:-1]'
62+
63+
help:
64+
@printf "\033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
65+
@printf " \033[32m%-32s\033[0m %s\n" "all" "Runs everything"
66+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-32s\033[0m %s\n", $$1, $$2}'

composer-require-checker.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"symbol-whitelist" : [
3+
"null", "true", "false",
4+
"static", "self", "parent",
5+
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
6+
"WyriHaximus\\Constants\\Boolean\\FALSE_", "WyriHaximus\\Constants\\Boolean\\TRUE_",
7+
"WyriHaximus\\Constants\\Numeric\\ZERO", "WyriHaximus\\getIn", "WyriHaximus\\Constants\\Numeric\\TWO",
8+
"Composer\\Composer", "Composer\\Config", "Composer\\IO\\IOInterface", "Composer\\Script\\Event",
9+
"Composer\\EventDispatcher\\EventSubscriberInterface", "Composer\\Package\\RootPackageInterface",
10+
"Composer\\Plugin\\PluginInterface", "Composer\\Script\\ScriptEvents", "WyriHaximus\\iteratorOrArrayToArray",
11+
"Safe\\chmod", "Safe\\file_get_contents", "Safe\\file_put_contents", "Safe\\sprintf"
12+
],
13+
"php-core-extensions" : [
14+
"Core",
15+
"date",
16+
"pcre",
17+
"Phar",
18+
"Reflection",
19+
"SPL",
20+
"standard"
21+
],
22+
"scan-files" : []
23+
}

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"php": "^7.4"
1414
},
1515
"require-dev": {
16+
"doctrine/annotations": "^1.11",
1617
"wyrihaximus/test-utilities": "^2.9"
1718
},
1819
"config": {
@@ -21,11 +22,21 @@
2122
},
2223
"sort-packages": true
2324
},
25+
"extra": {
26+
"unused": [
27+
"php"
28+
]
29+
},
2430
"autoload": {
2531
"psr-4": {
2632
"ReactParallel\\ObjectProxy\\Attribute\\": "src/"
2733
}
2834
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"ReactParallel\\Tests\\ObjectProxy\\Attribute\\": "tests/"
38+
}
39+
},
2940
"minimum-stability": "dev",
3041
"prefer-stable": true,
3142
"scripts": {

composer.lock

Lines changed: 156 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infection.json.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"timeout": 120,
3+
"source": {
4+
"directories": [
5+
"src"
6+
]
7+
},
8+
"logs": {
9+
"text": "infection.log"
10+
},
11+
"mutators": {
12+
"@default": true
13+
}
14+
}

phpcs.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="." />
4+
<arg name="extensions" value="php" /> <!-- which extensions to look for -->
5+
<arg name="colors" />
6+
<arg name="cache" value=".phpcs.cache" /> <!-- cache the results and don't commit them -->
7+
<arg value="np" /> <!-- n = ignore warnings, p = show progress -->
8+
9+
<file>src</file>
10+
<file>tests</file>
11+
12+
<exclude-pattern>src/Generated/*</exclude-pattern>
13+
14+
<rule ref="WyriHaximus-OSS" />
15+
</ruleset>

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
includes:
2+
- vendor/wyrihaximus/test-utilities/rules.neon

phpunit.xml.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php" colors="true">
3+
<testsuites>
4+
<testsuite name="Test Suite">
5+
<directory>tests/</directory>
6+
</testsuite>
7+
</testsuites>
8+
<filter>
9+
<whitelist>
10+
<directory suffix=".php">src/</directory>
11+
</whitelist>
12+
</filter>
13+
</phpunit>

0 commit comments

Comments
 (0)