Skip to content

Commit 669b19d

Browse files
authored
Merge pull request #20 from HelloAsso/add-test
Add test
2 parents 3dd2b81 + fb96fd8 commit 669b19d

12 files changed

Lines changed: 3102 additions & 3 deletions

File tree

.github/workflows/php-prod.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
run: |
3939
npm install
4040
41+
- name: Run PHPUnit tests
42+
run: ./vendor/bin/phpunit --testdox
43+
4144
- name: Make envfile
4245
uses: SpicyPizza/create-envfile@v2.0
4346
with:

.github/workflows/php-sandbox.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
run: |
4040
npm install
4141
42+
- name: Run PHPUnit tests
43+
run: ./vendor/bin/phpunit --testdox
44+
4245
- name: Make envfile
4346
uses: SpicyPizza/create-envfile@v2.0
4447
with:

.github/workflows/php-tests.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
- '!main'
8+
- '!develop'
9+
pull_request:
10+
branches:
11+
- main
12+
- develop
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: '8.3'
28+
29+
- name: Check if composer.json exists
30+
id: check_files
31+
uses: andstor/file-existence-action@v1
32+
with:
33+
files: 'composer.json'
34+
35+
- name: Run composer install if composer.json exists
36+
if: steps.check_files.outputs.files_exists == 'true'
37+
run: composer validate --no-check-publish && composer install --prefer-dist --no-progress
38+
39+
- name: Set up Node.js version
40+
uses: actions/setup-node@v3
41+
with:
42+
node-version: '20.x'
43+
44+
- name: npm install
45+
run: npm install
46+
47+
- name: Run PHPUnit tests
48+
run: ./vendor/bin/phpunit --testdox
49+

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,53 @@ ngrok http 8000
8181
This command will create a secure tunnel to your localhost server running on port 8000, allowing you to safely test your application's HTTPS functionality. Ensure that your application is running on port 8000 or adjust the port number in the command accordingly.
8282
Also update WEBSITE_DOMAIN from you env file
8383

84+
## Tests
85+
86+
The project includes a PHPUnit test suite covering token management, widget rendering and dashboard display. Tests are fully isolated (SQLite in-memory, mocked dependencies) and require no running database or external API.
87+
88+
### Run the tests
89+
90+
```bash
91+
./vendor/bin/phpunit --testdox
92+
```
93+
94+
### Test structure
95+
96+
```
97+
tests/
98+
├── bootstrap.php
99+
└── Unit/
100+
├── Services/
101+
│ └── ApiWrapperTest.php # Token generation & refresh (OAuth)
102+
├── Repositories/
103+
│ └── AccessTokenRepositoryTest.php # Token storage & retrieval (SQLite)
104+
└── Controllers/
105+
├── AdminControllerTest.php # Dashboard display (admin / user roles)
106+
└── WidgetControllerTest.php # Alert & donation widgets (render + JSON fetch)
107+
```
108+
109+
### Coverage areas
110+
111+
| Suite | Tests | What is verified |
112+
|---|---|---|
113+
| **Token generation** | 6 | Valid token returned, generation when absent, regeneration when expired, API errors |
114+
| **Token refresh** | 6 | Successful refresh, DB update, API errors, expired refresh token |
115+
| **Token storage** | 10 | Insert, update, select by slug, null slug (global token), unknown org |
116+
| **Dashboard** | 4 | Admin vs user template, flash messages forwarded, query isolation |
117+
| **Widget Alert** | 8 | 200 render, 400/404/500 errors, JSON fetch, cache update |
118+
| **Widget Donation** | 9 | 200 render, 400/404 errors, JSON fetch, cache update on amount change, multi-stream events |
119+
120+
### CI integration
121+
122+
Tests run automatically on every push via GitHub Actions, **before** deployment, on both environments:
123+
124+
| Workflow | Branch | Trigger |
125+
|---|---|---|
126+
| `php-sandbox.yml` | `develop` | Push on develop |
127+
| `php-prod.yml` | `main` | Push on main |
128+
129+
A test failure blocks the pipeline immediately — the artifact is never built or deployed.
130+
84131
## Architecture & Code Organization
85132

86133
### Framework & Technologies

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@
1717
"slim/flash": "^0.4.0",
1818
"filp/whoops": "^2.18"
1919
},
20+
"require-dev": {
21+
"phpunit/phpunit": "^11.0"
22+
},
2023
"autoload": {
2124
"psr-4": {
2225
"App\\": "src/"
2326
}
27+
},
28+
"autoload-dev": {
29+
"psr-4": {
30+
"Tests\\": "tests/"
31+
}
2432
}
2533
}

0 commit comments

Comments
 (0)