Skip to content

Commit f20e872

Browse files
authored
Add QA things in CI (#5)
* add first batch of unit tests * adds Db class so we can reuse it in tests * refactor classes to use db class * add jti cleanup * add php CI workflow * add workflows for json, markdown, yaml * send reasons for bad request to error log
1 parent 214d9b0 commit f20e872

22 files changed

+784
-86
lines changed

.config/.remarkrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": [
3+
"remark-preset-lint-recommended",
4+
["remark-lint-list-item-indent", "space"]
5+
]
6+
}

.config/.yamllint

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
extends: default
3+
4+
ignore: |
5+
vendor/
6+
7+
rules:
8+
brackets:
9+
max-spaces-inside: 1
10+
document-start: disable
11+
line-length:
12+
level: warning
13+
max: 120
14+
truthy: {allowed-values: ["true", "false", "on"]}

.github/workflows/json.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: JSON Quality Assistance
3+
4+
on:
5+
# This event occurs when there is activity on a pull request. The workflow
6+
# will be run against the commits, after merge to the target branch (main).
7+
pull_request:
8+
branches: [ main ]
9+
paths:
10+
- '**.json'
11+
- '.github/workflows/json.yml'
12+
types: [ opened, reopened, synchronize ]
13+
# This event occurs when there is a push to the repository.
14+
push:
15+
paths:
16+
- '**.json'
17+
- '.github/workflows/json.yml'
18+
# Allow manually triggering the workflow.
19+
workflow_dispatch:
20+
21+
# Cancels all previous workflow runs for the same branch that have not yet completed.
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
permissions:
27+
# Needed to allow the "concurrency" section to cancel a workflow run.
28+
actions: write
29+
30+
jobs:
31+
# 01.preflight.json.lint-syntax.yml
32+
lint-json-syntax:
33+
name: JSON Syntax Linting
34+
runs-on: ubuntu-24.04
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: docker://pipelinecomponents/jsonlint
38+
with:
39+
args: >-
40+
find .
41+
-not -path '*/.git/*'
42+
-not -path '*/node_modules/*'
43+
-not -path '*/vendor/*'
44+
-name '*.json'
45+
-type f
46+
-exec jsonlint --quiet {} ;

.github/workflows/markdown.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: Markdown Quality Assistance
3+
4+
on:
5+
# This event occurs when there is activity on a pull request. The workflow
6+
# will be run against the commits, after merge to the target branch (main).
7+
pull_request:
8+
branches: [ main ]
9+
paths:
10+
- '**.md'
11+
- '.github/workflows/markdown.yml'
12+
types: [ opened, reopened, synchronize ]
13+
# This event occurs when there is a push to the repository.
14+
push:
15+
paths:
16+
- '**.md'
17+
- '.github/workflows/markdown.yml'
18+
# Allow manually triggering the workflow.
19+
workflow_dispatch:
20+
21+
# Cancels all previous workflow runs for the same branch that have not yet completed.
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
permissions:
27+
# Needed to allow the "concurrency" section to cancel a workflow run.
28+
actions: write
29+
30+
jobs:
31+
# 01.quality.markdown.lint-syntax.yml
32+
lint-markdown-syntax:
33+
name: Markdown Linting
34+
runs-on: ubuntu-24.04
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: docker://pipelinecomponents/remark-lint
38+
with:
39+
args: >-
40+
remark
41+
--rc-path=.config/.remarkrc
42+
--ignore-pattern='*/vendor/*'

.github/workflows/php.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
name: PHP Quality Assistance
3+
4+
on:
5+
# This event occurs when there is activity on a pull request. The workflow
6+
# will be run against the commits, after merge to the target branch (main).
7+
pull_request:
8+
paths:
9+
- '**.php'
10+
- '.config/phpcs.xml.dist'
11+
- 'tests/phpunit/phpunit.xml'
12+
- '.github/workflows/php.yml'
13+
- 'composer.json'
14+
- 'composer.lock'
15+
branches: [ main, feature/php-ci ]
16+
types: [ opened, reopened, synchronize ]
17+
# This event occurs when there is a push to the repository.
18+
push:
19+
paths:
20+
- '**.php'
21+
- '.config/phpcs.xml.dist'
22+
- 'tests/phpunit/phpunit.xml'
23+
- '.github/workflows/php.yml'
24+
- 'composer.json'
25+
- 'composer.lock'
26+
# Allow manually triggering the workflow.
27+
workflow_dispatch:
28+
29+
30+
# Cancels all previous workflow runs for the same branch that have not yet completed.
31+
concurrency:
32+
group: ${{ github.workflow }}-${{ github.ref }}
33+
cancel-in-progress: true
34+
35+
permissions:
36+
# Needed to allow the "concurrency" section to cancel a workflow run.
37+
actions: write
38+
39+
jobs:
40+
# 01.preflight.php.lint-syntax.yml
41+
lint-php-syntax:
42+
name: PHP Syntax Linting
43+
runs-on: ubuntu-24.04
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: docker://pipelinecomponents/php-linter
47+
with:
48+
args: >-
49+
parallel-lint
50+
--exclude .git
51+
--exclude vendor
52+
--no-progress
53+
.
54+
# # 01.quality.php.validate.dependencies-file.yml
55+
validate-dependencies-file:
56+
name: Validate dependencies file
57+
runs-on: ubuntu-24.04
58+
steps:
59+
- uses: actions/checkout@v4
60+
- run: >-
61+
composer validate
62+
--check-lock
63+
--no-plugins
64+
--no-scripts
65+
--strict
66+
# 02.test.php.test-unit.yml
67+
php-unittest:
68+
name: PHP Unit Tests
69+
needs:
70+
- lint-php-syntax
71+
- validate-dependencies-file
72+
runs-on: ubuntu-24.04
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
php:
77+
- '8.1' # from 2021-11 to 2023-11 (2025-12)
78+
- '8.2' # from 2022-12 to 2024-12 (2026-12)
79+
- '8.3' # from 2023-11 to 2025-12 (2027-12)
80+
steps:
81+
- uses: actions/checkout@v4
82+
- uses: shivammathur/setup-php@v2
83+
with:
84+
coverage: xdebug
85+
ini-values: error_reporting=E_ALL, display_errors=On
86+
php-version: ${{ matrix.php }}
87+
- name: Install and Cache Composer dependencies
88+
uses: "ramsey/composer-install@v2"
89+
env:
90+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
91+
- run: vendor/bin/phpunit --configuration tests/phpunit/phpunit.xml
92+
# 03.quality.php.scan.dependencies-vulnerabilities.yml
93+
scan-dependencies-vulnerabilities:
94+
name: Scan Dependencies Vulnerabilities
95+
needs:
96+
- validate-dependencies-file
97+
runs-on: ubuntu-24.04
98+
steps:
99+
- uses: actions/checkout@v4
100+
- name: Install and Cache Composer dependencies
101+
uses: "ramsey/composer-install@v2"
102+
env:
103+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
104+
- run: >-
105+
composer audit
106+
--abandoned=report
107+
--no-dev
108+
--no-plugins
109+
--no-scripts
110+
# 03.quality.php.lint-version-compatibility.yml
111+
php-check-version-compatibility:
112+
name: PHP Version Compatibility
113+
needs:
114+
- lint-php-syntax
115+
runs-on: ubuntu-24.04
116+
strategy:
117+
fail-fast: false
118+
matrix:
119+
php:
120+
- '8.1' # from 2021-11 to 2023-11 (2025-12)
121+
- '8.2' # from 2022-12 to 2024-12 (2026-12)
122+
- '8.3' # from 2023-11 to 2025-12 (2027-12)
123+
steps:
124+
- uses: actions/checkout@v4
125+
- uses: docker://pipelinecomponents/php-codesniffer
126+
with:
127+
args: >-
128+
phpcs
129+
-s
130+
--extensions=php
131+
--ignore='*vendor/*'
132+
--runtime-set testVersion ${{ matrix.php }}
133+
--standard=PHPCompatibility
134+
.

.github/workflows/yaml.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: YAML Quality Assistance
3+
4+
on:
5+
# This event occurs when there is activity on a pull request. The workflow
6+
# will be run against the commits, after merge to the target branch (main).
7+
pull_request:
8+
branches: [ main ]
9+
paths:
10+
- '**.yml'
11+
- '**.yaml'
12+
types: [ opened, reopened, synchronize ]
13+
# This event occurs when there is a push to the repository.
14+
push:
15+
paths:
16+
- '**.yml'
17+
- '**.yaml'
18+
# Allow manually triggering the workflow.
19+
workflow_dispatch:
20+
21+
# Cancels all previous workflow runs for the same branch that have not yet completed.
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
permissions:
27+
# Needed to allow the "concurrency" section to cancel a workflow run.
28+
actions: write
29+
30+
jobs:
31+
# 01.preflight.yaml.lint.yml
32+
lint-yaml:
33+
name: YAML Linting
34+
runs-on: ubuntu-24.04
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: docker://pipelinecomponents/yamllint
38+
with:
39+
args: >-
40+
yamllint
41+
--config-file=.config/.yamllint
42+
.

TODO

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,21 @@
5757
- [v] webid
5858
- [v] wac
5959
- [v] solid-crud
60-
- [v] CI integration
60+
- [v] CI integration
61+
62+
------ Unit tests -----
63+
- [v] ClientRegistration
64+
- [v] JtiStore
65+
- [v] IpAttempts
66+
- [v] Util
67+
- [v] PasswordValidator
68+
- [ ] Mailer
69+
- [ ] MailTemplateGenerator
70+
- [ ] MailTemplates
71+
- [ ] Server
72+
- [ ] SolidNotifications
73+
- [ ] SolidPubSub
74+
- [ ] StorageServer
75+
- [ ] User
76+
- [-] Middleware
77+
- [-] Db

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "pdsinterop/php-solid",
3+
"description": "Multi-user Solid Server for PHP",
34
"type": "project",
45
"license": "MIT",
56
"autoload": {
@@ -17,12 +18,12 @@
1718
"pdsinterop/solid-auth": "v0.13.0",
1819
"pdsinterop/solid-crud": "v0.8.1",
1920
"phpmailer/phpmailer": "^6.10",
20-
"sweetrdf/easyrdf": "v1.15",
21+
"sweetrdf/easyrdf": "~1.15.0",
2122
"phpseclib/bcmath_compat": "^2.0",
2223
"phrity/websocket": "^3.5"
2324
},
2425
"require-dev": {
25-
"phpunit/phpunit": "^12.2",
26+
"phpunit/phpunit": "^9 || ^10 || ^11 || ^12",
2627
"phpstan/phpstan": "^2.1"
2728
}
2829
}

init.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function initDatabase() {
3232
)',
3333
'CREATE TABLE IF NOT EXISTS jti (
3434
jti VARCHAR(255) NOT NULL PRIMARY KEY,
35-
expires TEXT
35+
expires TEXT NOT NULL
3636
)',
3737
'CREATE TABLE IF NOT EXISTS users (
3838
user_id VARCHAR(255) NOT NULL PRIMARY KEY,
@@ -43,7 +43,7 @@ function initDatabase() {
4343
'CREATE TABLE IF NOT EXISTS ipAttempts (
4444
ip VARCHAR(255) NOT NULL,
4545
type VARCHAR(255) NOT NULL,
46-
expires NOT NULL
46+
expires TEXT NOT NULL
4747
)',
4848
];
4949

0 commit comments

Comments
 (0)