Skip to content

Commit dc4d033

Browse files
committed
Update test-framework
1 parent 9c42f97 commit dc4d033

File tree

10 files changed

+249
-124
lines changed

10 files changed

+249
-124
lines changed

.github/workflows/php.yml

Lines changed: 182 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,65 @@
1+
---
2+
13
name: CI
24

3-
on:
5+
on: # yamllint disable-line rule:truthy
46
push:
5-
branches: [ '**' ]
7+
branches: ['**']
68
paths-ignore:
79
- '**.md'
810
pull_request:
9-
branches: [ master, release-* ]
11+
branches: [master, release-*]
1012
paths-ignore:
1113
- '**.md'
14+
workflow_dispatch:
1215

1316
jobs:
14-
basic-tests:
15-
name: Syntax and unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}
16-
runs-on: ${{ matrix.operating-system }}
17-
strategy:
18-
fail-fast: false
19-
matrix:
20-
operating-system: [ubuntu-latest, windows-latest]
21-
php-versions: ['7.4', '8.0', '8.1', '8.2']
17+
linter:
18+
name: Linter
19+
runs-on: ['ubuntu-latest']
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Lint Code Base
27+
uses: github/super-linter/slim@v4
28+
env:
29+
LOG_LEVEL: NOTICE
30+
VALIDATE_ALL_CODEBASE: true
31+
LINTER_RULES_PATH: 'tools/linters'
32+
VALIDATE_CSS: true
33+
VALIDATE_JAVASCRIPT_ES: true
34+
VALIDATE_JSON: true
35+
VALIDATE_PHP_BUILTIN: true
36+
VALIDATE_YAML: true
37+
VALIDATE_XML: true
38+
VALIDATE_GITHUB_ACTIONS: true
39+
40+
quality:
41+
name: Quality control
42+
runs-on: [ubuntu-latest]
2243

2344
steps:
2445
- name: Setup PHP, with composer and extensions
25-
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
46+
id: setup-php
47+
# https://github.com/shivammathur/setup-php
48+
uses: shivammathur/setup-php@v2
2649
with:
27-
coverage: pcov
28-
extensions: intl, mbstring, xml
29-
ini-values: error_reporting=E_ALL
30-
php-version: ${{ matrix.php-versions }}
31-
tools: composer:v2
50+
# Should be the higest supported version, so we can use the newest tools
51+
php-version: '8.2'
52+
tools: composer, composer-require-checker, composer-unused, phpcs, psalm
53+
# optional performance gain for psalm: opcache
54+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, opcache, openssl, pcre, posix, spl, xml
3255

3356
- name: Setup problem matchers for PHP
3457
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
3558

36-
- name: Setup problem matchers for PHPUnit
37-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
38-
39-
- name: Set git to use LF
40-
run: |
41-
git config --global core.autocrlf false
42-
git config --global core.eol lf
43-
4459
- uses: actions/checkout@v3
4560

46-
- name: Get composer cache directory (linux)
47-
if: ${{ matrix.operating-system == 'ubuntu-latest' }}
48-
run: echo "COMPOSER_CACHE=$(composer config cache-files-dir)" >> $GITHUB_ENV
49-
50-
- name: Get composer cache directory (windows)
51-
if: ${{ matrix.operating-system == 'windows-latest' }}
52-
run: echo "COMPOSER_CACHE=$(composer config cache-files-dir)" >> $env:GITHUB_ENV
61+
- name: Get composer cache directory
62+
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
5363

5464
- name: Cache composer dependencies
5565
uses: actions/cache@v3
@@ -64,49 +74,65 @@ jobs:
6474
- name: Install Composer dependencies
6575
run: composer install --no-progress --prefer-dist --optimize-autoloader
6676

67-
- name: Syntax check PHP
68-
run: bash vendor/bin/check-syntax-php.sh
77+
- name: Check code for hard dependencies missing in composer.json
78+
run: composer-require-checker check --config-file=tools/composer-require-checker.json composer.json
79+
80+
- name: Check code for unused dependencies in composer.json
81+
run: composer-unused
6982

70-
- name: Decide whether to run code coverage or not
71-
if: ${{ matrix.php-versions != '7.4' || matrix.operating-system != 'ubuntu-latest' }}
83+
- name: PHP Code Sniffer
84+
run: phpcs
85+
86+
- name: Psalm
87+
continue-on-error: true
7288
run: |
73-
echo "NO_COVERAGE=--no-coverage" >> $GITHUB_ENV
89+
psalm -c psalm.xml \
90+
--show-info=true \
91+
--shepherd \
92+
--php-version=${{ steps.setup-php.outputs.php-version }}
7493
75-
- name: Run unit tests
94+
- name: Psalm (testsuite)
7695
run: |
77-
echo $NO_COVERAGE
78-
./vendor/bin/phpunit $NO_COVERAGE
96+
psalm -c psalm-dev.xml \
97+
--show-info=true \
98+
--shepherd \
99+
--php-version=${{ steps.setup-php.outputs.php-version }}
79100
80-
- name: Save coverage data
81-
if: ${{ matrix.php-versions == '7.4' && matrix.operating-system == 'ubuntu-latest' }}
82-
uses: actions/upload-artifact@v3
83-
with:
84-
name: build-data
85-
path: ${{ github.workspace }}/build
101+
- name: Psalter
102+
run: |
103+
psalm --alter \
104+
--issues=UnnecessaryVarAnnotation \
105+
--dry-run \
106+
--php-version=${{ steps.setup-php.outputs.php-version }}
86107
87108
security:
88109
name: Security checks
89110
runs-on: [ubuntu-latest]
90111
steps:
91112
- name: Setup PHP, with composer and extensions
92-
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
113+
# https://github.com/shivammathur/setup-php
114+
uses: shivammathur/setup-php@v2
93115
with:
94-
php-version: '7.4'
95-
tools: composer:v2
96-
extensions: ldap, mbstring, xml
97-
coverage: none
116+
# Should be the lowest supported version
117+
php-version: '8.0'
118+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, posix, spl, xml
119+
tools: composer
120+
coverage: none
98121

99122
- name: Setup problem matchers for PHP
100123
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
101124

102125
- uses: actions/checkout@v3
103126

127+
- name: Get composer cache directory
128+
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
129+
104130
- name: Cache composer dependencies
105131
uses: actions/cache@v3
106132
with:
107-
path: $COMPOSER_CACHE
108-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
109-
restore-keys: ${{ runner.os }}-composer-
133+
path: $COMPOSER_CACHE
134+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
135+
restore-keys: ${{ runner.os }}-composer-
110136

111137
- name: Install Composer dependencies
112138
run: composer install --no-progress --prefer-dist --optimize-autoloader
@@ -120,85 +146,147 @@ jobs:
120146
- name: Security check for updated dependencies
121147
run: composer audit
122148

123-
sanity-check:
124-
name: Sanity checks
125-
runs-on: [ubuntu-latest]
149+
unit-tests-linux:
150+
name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}"
151+
runs-on: ${{ matrix.operating-system }}
152+
needs: [linter, quality, security]
153+
strategy:
154+
fail-fast: false
155+
matrix:
156+
operating-system: [ubuntu-latest]
157+
php-versions: ['8.0', '8.1', '8.2']
126158

127159
steps:
128160
- name: Setup PHP, with composer and extensions
129-
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
161+
# https://github.com/shivammathur/setup-php
162+
uses: shivammathur/setup-php@v2
130163
with:
131-
php-version: '7.4'
132-
tools: composer:v2
133-
extensions: ldap, mbstring, xml
134-
coverage: none
164+
php-version: ${{ matrix.php-versions }}
165+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, posix, spl, xml
166+
tools: composer
167+
ini-values: error_reporting=E_ALL
168+
coverage: pcov
135169

136170
- name: Setup problem matchers for PHP
137171
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
138172

173+
- name: Setup problem matchers for PHPUnit
174+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
175+
176+
- name: Set git to use LF
177+
run: |
178+
git config --global core.autocrlf false
179+
git config --global core.eol lf
180+
139181
- uses: actions/checkout@v3
140182

183+
- name: Get composer cache directory
184+
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV"
185+
141186
- name: Cache composer dependencies
142187
uses: actions/cache@v3
143188
with:
144-
path: $COMPOSER_CACHE
145-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
146-
restore-keys: ${{ runner.os }}-composer-
189+
path: $COMPOSER_CACHE
190+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
191+
restore-keys: ${{ runner.os }}-composer-
147192

148193
- name: Install Composer dependencies
149194
run: composer install --no-progress --prefer-dist --optimize-autoloader
150195

151-
- name: Syntax check YAML / XML / JSON
152-
run: |
153-
bash vendor/bin/check-syntax-yaml.sh
154-
bash vendor/bin/check-syntax-xml.sh
155-
bash vendor/bin/check-syntax-json.sh
196+
- name: Run unit tests with coverage
197+
if: ${{ matrix.php-versions == '8.2' }}
198+
run: vendor/bin/phpunit
156199

157-
quality:
158-
name: Quality control
159-
runs-on: [ubuntu-latest]
160-
needs: [basic-tests]
200+
- name: Run unit tests (no coverage)
201+
if: ${{ matrix.php-versions != '8.2' }}
202+
run: vendor/bin/phpunit --no-coverage
203+
204+
- name: Save coverage data
205+
if: ${{ matrix.php-versions == '8.2' }}
206+
uses: actions/upload-artifact@v3
207+
with:
208+
name: coverage-data
209+
path: ${{ github.workspace }}/build
210+
211+
unit-tests-windows:
212+
name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}"
213+
runs-on: ${{ matrix.operating-system }}
214+
needs: [linter, quality, security]
215+
strategy:
216+
fail-fast: true
217+
matrix:
218+
operating-system: [windows-latest]
219+
php-versions: ['8.0', '8.1', '8.2']
161220

162221
steps:
163222
- name: Setup PHP, with composer and extensions
164-
id: setup-php
165-
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
223+
# https://github.com/shivammathur/setup-php
224+
uses: shivammathur/setup-php@v2
166225
with:
167-
php-version: '7.4'
168-
tools: composer:v2
169-
extensions: ldap, mbstring, xml
226+
php-version: ${{ matrix.php-versions }}
227+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, posix, spl, xml
228+
tools: composer
229+
ini-values: error_reporting=E_ALL
230+
coverage: none
170231

171232
- name: Setup problem matchers for PHP
172233
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
173234

235+
- name: Setup problem matchers for PHPUnit
236+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
237+
238+
- name: Set git to use LF
239+
run: |
240+
git config --global core.autocrlf false
241+
git config --global core.eol lf
242+
174243
- uses: actions/checkout@v3
175244

245+
- name: Get composer cache directory
246+
run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$env:GITHUB_ENV"
247+
176248
- name: Cache composer dependencies
177249
uses: actions/cache@v3
178250
with:
179-
path: $COMPOSER_CACHE
180-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
181-
restore-keys: ${{ runner.os }}-composer-
251+
path: $COMPOSER_CACHE
252+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
253+
restore-keys: ${{ runner.os }}-composer-
182254

183255
- name: Install Composer dependencies
184-
run: composer install --no-progress --prefer-dist --optimize-autoloader
256+
run: composer install --no-progress --prefer-dist --optimize-autoloader --ignore-platform-req=ext-posix
257+
258+
- name: Run unit tests
259+
run: vendor/bin/phpunit --no-coverage
260+
261+
coverage:
262+
name: Code coverage
263+
runs-on: [ubuntu-latest]
264+
needs: [unit-tests-linux]
265+
steps:
266+
- uses: actions/checkout@v3
185267

186268
- uses: actions/download-artifact@v3
187269
with:
188-
name: build-data
270+
name: coverage-data
189271
path: ${{ github.workspace }}/build
190272

191273
- name: Codecov
192274
uses: codecov/codecov-action@v3
275+
with:
276+
token: ${{ secrets.CODECOV_TOKEN }}
277+
fail_ci_if_error: true
278+
verbose: true
193279

194-
- name: PHP Code Sniffer
195-
continue-on-error: true
196-
run: php vendor/bin/phpcs
197-
198-
- name: Psalm
199-
continue-on-error: true
200-
run: php vendor/bin/psalm --show-info=true --shepherd --php-version=${{ steps.setup-php.outputs.php-version }}
280+
cleanup:
281+
name: Cleanup artifacts
282+
needs: [unit-tests-linux, coverage]
283+
runs-on: [ubuntu-latest]
284+
if: |
285+
always() &&
286+
needs.coverage.result == 'success' &&
287+
(needs.unit-tests-linux == 'success' || needs.coverage == 'skipped')
201288
202-
- name: Psalter
203-
continue-on-error: true
204-
run: php vendor/bin/psalter --issues=UnnecessaryVarAnnotation --dry-run --php-version=${{ steps.setup-php.outputs.php-version }}
289+
steps:
290+
- uses: geekyeggo/delete-artifact@v2
291+
with:
292+
name: coverage-data

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
composer.lock
44
cs_fixer_tmp*
55
bin/*
6-
tools/*
76
vendor/*
87
build/*
98
.phpunit.result.cache

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939

4040
"simplesamlphp/assert": "^1.0",
4141
"simplesamlphp/composer-module-installer": "^1.3.4",
42-
"simplesamlphp/simplesamlphp": "*",
43-
"simplesamlphp/simplesamlphp-module-consent": "*"
42+
"simplesamlphp/simplesamlphp": "dev-master",
43+
"simplesamlphp/simplesamlphp-module-consent": "^1.3",
44+
"symfony/http-foundation": "^6.0"
4445
},
4546
"require-dev": {
4647
"simplesamlphp/simplesamlphp-test-framework": "^1.5.5"

0 commit comments

Comments
 (0)