Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit fda2afc

Browse files
committed
Changed testing/CI procedure to use a Makefile
Only unittests and coding standards are enforced.
1 parent 226a5e0 commit fda2afc

File tree

6 files changed

+254
-1
lines changed

6 files changed

+254
-1
lines changed

.phan/config.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Phan\Issue;
4+
5+
return [
6+
'target_php_version' => '7.1',
7+
'backward_compatibility_checks' => false,
8+
'exclude_analysis_directory_list' => [
9+
'vendor/',
10+
],
11+
'plugins' => [
12+
'AlwaysReturnPlugin',
13+
'DollarDollarPlugin',
14+
'DuplicateArrayKeyPlugin',
15+
'PregRegexCheckerPlugin',
16+
'PrintfCheckerPlugin',
17+
'UnreachableCodePlugin',
18+
],
19+
'directory_list' => [
20+
'src/',
21+
],
22+
'suppress_issue_types' => [
23+
'PhanParamTooManyInternal',
24+
],
25+
];

.php_cs.dist

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
$header = <<<'EOF'
4+
Copyright 2018 Henrique Borba and contributors
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
EOF;
18+
19+
$existingConventions = [
20+
'phpdoc_no_package' => false,
21+
'phpdoc_separation' => false,
22+
'phpdoc_summary' => false,
23+
'phpdoc_align' => false,
24+
'phpdoc_scalar' => false,
25+
'phpdoc_no_empty_return' => false,
26+
'phpdoc_annotation_without_dot' => false,
27+
'phpdoc_no_alias_tag' => false,
28+
'phpdoc_order' => false,
29+
'ordered_imports' => false,
30+
];
31+
32+
$finder = \PhpCsFixer\Finder::create()
33+
->in('src')
34+
->in('tests')
35+
->exclude('build')
36+
;
37+
38+
return PhpCsFixer\Config::create()
39+
->setRiskyAllowed(true)
40+
->setRules([
41+
'@Symfony' => true,
42+
'array_syntax' => ['syntax' => 'short'],
43+
//'declare_strict_types' => true,
44+
'explicit_indirect_variable' => true,
45+
'no_superfluous_elseif' => true,
46+
'no_unreachable_default_argument_value' => true,
47+
'no_useless_else' => true,
48+
'no_useless_return' => true,
49+
'ordered_class_elements' => false,
50+
'non_printable_character' => true,
51+
'ordered_imports' => true,
52+
'phpdoc_add_missing_param_annotation' => true,
53+
'phpdoc_order' => true,
54+
'visibility_required' => true,
55+
'header_comment' => ['header' => $header, 'separate' => 'bottom', 'location' => 'after_open'],
56+
'ternary_to_null_coalescing' => true,
57+
'yoda_style' => null,
58+
59+
] + $existingConventions)
60+
->setFinder($finder)
61+
;

.phpstan.neon

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
excludes_analyse:
3+
- %currentWorkingDirectory%/tests/Broken.php

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cache:
2121
apt: true
2222

2323
install:
24+
- pecl install ast
2425
- curl -s http://getcomposer.org/installer | php
2526
- php composer.phar install --no-interaction --ignore-platform-reqs
2627

@@ -35,4 +36,4 @@ before_script:
3536

3637
script:
3738
- cd $TRAVIS_BUILD_DIR
38-
- vendor/bin/phpunit
39+
- make ci --keep-going COMPOSER='/bin/sh -c composer'

Makefile

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
.PHONY: ci test prerequisites
2+
3+
# Use any most recent PHP version
4+
PHP=$(shell which php7.2 || which php7.1 || which php)
5+
6+
# Default parallelism
7+
JOBS=$(shell nproc)
8+
9+
# Default silencer if installed
10+
SILENT= # disabled $(shell which chronic)
11+
12+
# PHP CS Fixer
13+
PHP_CS_FIXER=build/php-cs-fixer-v2.phar
14+
PHP_CS_FIXER_ARGS=--cache-file=build/cache/.php_cs.cache --verbose
15+
16+
# PHPUnit
17+
PHPUNIT=vendor/bin/phpunit
18+
PHPUNIT_ARGS=--coverage-xml=coverage/coverage-xml --log-junit=coverage/phpunit.junit.xml
19+
20+
# Phan
21+
PHAN=build/phan.phar
22+
PHAN_ARGS=-j $(JOBS) --allow-polyfill-parser
23+
PHAN_PHP_VERSION=7.1
24+
export PHAN_DISABLE_XDEBUG_WARN=1
25+
26+
# PHPStan
27+
PHPSTAN=build/phpstan.phar
28+
PHPSTAN_ARGS=analyse src tests --level=2 -c .phpstan.neon
29+
30+
# Composer
31+
COMPOSER=$(PHP) $(shell which composer)
32+
33+
# Infection
34+
INFECTION=build/infection.phar
35+
MIN_MSI=70
36+
MIN_COVERED_MSI=80
37+
INFECTION_ARGS=--min-msi=$(MIN_MSI) --min-covered-msi=$(MIN_COVERED_MSI) --threads=$(JOBS) --coverage=coverage
38+
39+
all: test
40+
41+
##############################################################
42+
# Continuous Integration #
43+
##############################################################
44+
45+
ci: SILENT=
46+
ci: prerequisites ci-phpunit ci-analyze
47+
$(SILENT) $(COMPOSER) validate --strict || true
48+
49+
ci-phpunit: ci-cs
50+
$(SILENT) $(PHP) $(PHPUNIT) $(PHPUNIT_ARGS)
51+
$(SILENT) $(PHP) $(INFECTION) $(INFECTION_ARGS) --quiet
52+
53+
ci-analyze: ci-cs
54+
$(SILENT) $(PHP) $(PHPSTAN) $(PHPSTAN_ARGS) --no-progress || true
55+
$(SILENT) $(PHP) $(PHAN) $(PHAN_ARGS) || true
56+
57+
ci-cs: prerequisites
58+
$(SILENT) $(PHP) $(PHP_CS_FIXER) $(PHP_CS_FIXER_ARGS) --dry-run --stop-on-violation fix
59+
60+
##############################################################
61+
# Development Workflow #
62+
##############################################################
63+
64+
test: phpunit analyze
65+
$(SILENT) $(COMPOSER) validate --strict || true
66+
67+
test-prerequisites: prerequisites composer.lock
68+
69+
phpunit: cs
70+
$(SILENT) $(PHP) $(PHPUNIT) $(PHPUNIT_ARGS) --verbose
71+
$(SILENT) $(PHP) $(INFECTION) $(INFECTION_ARGS) --log-verbosity=2 --show-mutations
72+
73+
analyze: cs
74+
$(SILENT) $(PHP) $(PHPSTAN) $(PHPSTAN_ARGS) || true
75+
$(SILENT) $(PHP) $(PHAN) $(PHAN_ARGS) --color || true
76+
77+
cs: test-prerequisites
78+
$(SILENT) $(PHP) $(PHP_CS_FIXER) $(PHP_CS_FIXER_ARGS) --diff fix
79+
80+
##############################################################
81+
# Prerequisites Setup #
82+
##############################################################
83+
84+
# We need both vendor/autoload.php and composer.lock being up to date
85+
.PHONY: prerequisites
86+
prerequisites: report-php-version build/cache vendor/autoload.php .phan composer.lock tools
87+
88+
# Do install if there's no 'vendor'
89+
vendor/autoload.php:
90+
$(SILENT) $(COMPOSER) install --prefer-dist
91+
92+
# If composer.lock is older than `composer.json`, do update,
93+
# and touch composer.lock because composer not always does that
94+
composer.lock: composer.json
95+
$(SILENT) $(COMPOSER) update && touch composer.lock
96+
97+
.phan: $(PHAN)
98+
$(PHP) $(PHAN) --init --init-level=1 --init-overwrite --target-php-version=$(PHAN_PHP_VERSION) > /dev/null
99+
100+
build: build/cache
101+
build/cache:
102+
mkdir -p build/cache
103+
104+
.PHONY: report-php-version
105+
report-php-version:
106+
# Using $(PHP)
107+
108+
.PHONY: tools
109+
tools: $(PHAN) $(PHP_CS_FIXER) $(PHPSTAN) $(INFECTION)
110+
111+
WGET=wget -nv -O
112+
113+
$(PHP_CS_FIXER):
114+
mkdir -p build
115+
$(WGET) $@ https://cs.sensiolabs.org/download/php-cs-fixer-v2.phar
116+
chmod +x $@
117+
touch $@
118+
119+
$(PHPSTAN):
120+
mkdir -p build
121+
$(WGET) $@ https://github.com/phpstan/phpstan/releases/download/0.9.1/phpstan.phar
122+
chmod +x $@
123+
touch $@
124+
125+
$(PHAN):
126+
mkdir -p build
127+
$(WGET) $@ https://github.com/phan/phan/releases/download/0.12.5/phan.phar
128+
chmod +x $@
129+
touch $@
130+
131+
$(INFECTION):
132+
mkdir -p build
133+
$(WGET) $@ https://github.com/infection/infection/releases/download/0.8.0/infection.phar
134+
$(WGET) build/infection.phar.pubkey https://github.com/infection/infection/releases/download/0.8.0/infection.phar.pubkey
135+
chmod +x build/infection.phar
136+
137+
##############################################################
138+
# Quick development testing procedure #
139+
##############################################################
140+
141+
PHP_VERSIONS=php7.1 php7.2
142+
143+
.PHONY: quick
144+
quick:
145+
make --no-print-directory -j test-all
146+
147+
.PHONY: test-all
148+
test-all: $(PHP_VERSIONS)
149+
150+
.PHONY: $(PHP_VERSIONS)
151+
$(PHP_VERSIONS): cs
152+
@make --no-print-directory PHP=$@ PHP_CS_FIXER=/bin/true

infection.json.dist

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"timeout": 10,
3+
"source": {
4+
"directories": [
5+
"src"
6+
]
7+
},
8+
"logs": {
9+
"text": "infection-log.txt"
10+
}
11+
}

0 commit comments

Comments
 (0)