Skip to content

Commit 8a8a96f

Browse files
committed
Add test
1 parent 3dd2b81 commit 8a8a96f

11 files changed

Lines changed: 3053 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:

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)