Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/php-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
run: |
npm install

- name: Run PHPUnit tests
run: ./vendor/bin/phpunit --testdox

- name: Make envfile
uses: SpicyPizza/create-envfile@v2.0
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/php-sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
run: |
npm install

- name: Run PHPUnit tests
run: ./vendor/bin/phpunit --testdox

- name: Make envfile
uses: SpicyPizza/create-envfile@v2.0
with:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Run tests

on:
push:
branches:
- '**'
- '!main'
- '!develop'
pull_request:
branches:
- main
- develop

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Check if composer.json exists
id: check_files
uses: andstor/file-existence-action@v1
with:
files: 'composer.json'

- name: Run composer install if composer.json exists
if: steps.check_files.outputs.files_exists == 'true'
run: composer validate --no-check-publish && composer install --prefer-dist --no-progress

- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: npm install
run: npm install

- name: Run PHPUnit tests
run: ./vendor/bin/phpunit --testdox

47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,53 @@ ngrok http 8000
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.
Also update WEBSITE_DOMAIN from you env file

## Tests

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.

### Run the tests

```bash
./vendor/bin/phpunit --testdox
```

### Test structure

```
tests/
├── bootstrap.php
└── Unit/
├── Services/
│ └── ApiWrapperTest.php # Token generation & refresh (OAuth)
├── Repositories/
│ └── AccessTokenRepositoryTest.php # Token storage & retrieval (SQLite)
└── Controllers/
├── AdminControllerTest.php # Dashboard display (admin / user roles)
└── WidgetControllerTest.php # Alert & donation widgets (render + JSON fetch)
```

### Coverage areas

| Suite | Tests | What is verified |
|---|---|---|
| **Token generation** | 6 | Valid token returned, generation when absent, regeneration when expired, API errors |
| **Token refresh** | 6 | Successful refresh, DB update, API errors, expired refresh token |
| **Token storage** | 10 | Insert, update, select by slug, null slug (global token), unknown org |
| **Dashboard** | 4 | Admin vs user template, flash messages forwarded, query isolation |
| **Widget Alert** | 8 | 200 render, 400/404/500 errors, JSON fetch, cache update |
| **Widget Donation** | 9 | 200 render, 400/404 errors, JSON fetch, cache update on amount change, multi-stream events |

### CI integration

Tests run automatically on every push via GitHub Actions, **before** deployment, on both environments:

| Workflow | Branch | Trigger |
|---|---|---|
| `php-sandbox.yml` | `develop` | Push on develop |
| `php-prod.yml` | `main` | Push on main |

A test failure blocks the pipeline immediately — the artifact is never built or deployed.

## Architecture & Code Organization

### Framework & Technologies
Expand Down
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@
"slim/flash": "^0.4.0",
"filp/whoops": "^2.18"
},
"require-dev": {
"phpunit/phpunit": "^11.0"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}
Loading
Loading