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 .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
26 changes: 26 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Tests

env:
COMPOSE_USER: runner

on:
pull_request:

jobs:
phpunit:
name: PHPUnit + coverage gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Create docker network
run: docker network create frontend

- name: Install dependencies
run: docker compose run --rm phpfpm composer install

- name: Run PHPUnit with coverage
run: docker compose run -e XDEBUG_MODE=coverage --rm phpfpm vendor/bin/phpunit --coverage-clover=coverage/clover.xml

- name: Enforce coverage threshold (100%)
run: docker compose run --rm phpfpm vendor/bin/coverage-check coverage/clover.xml 100
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@
###> vincentlanglet/twig-cs-fixer ###
/.twig-cs-fixer.cache
###< vincentlanglet/twig-cs-fixer ###

###> phpunit/phpunit ###
/phpunit.xml
/.phpunit.cache/
/coverage/
###< phpunit/phpunit ###
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(stack, structure, execution policy, branching, commits, CHANGELOG,
ADRs, domain glossary).
- Initial Symfony 8 application scaffold.
- PHPUnit test harness with 100% coverage gate enforced in CI via
`rregeer/phpunit-coverage-check`
([#31](https://github.com/itk-dev/ai-lib/issues/31)).

### Changed

Expand All @@ -27,9 +30,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ADR `docs/adr/002-project-license-mpl-2.md` recording the MPL-2.0 license
decision and its rationale.
- License section in `README.md` referencing the new `LICENSE` file and ADR.

### Changed

- Project license declared as **MPL-2.0** (Mozilla Public License 2.0); the
`license` field in `composer.json` updated from the Symfony skeleton
default `proprietary` to the SPDX identifier `MPL-2.0`.
Expand All @@ -45,4 +45,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rewrite the project README around the AI Bibliotek catalog: adds project
description, status banner, feature list, tech stack, Task-based local
development workflow, contributing pointers, and prototype references.

7 changes: 7 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ task coding-standards-composer-apply

# Run every check at once
task coding-standards-check

# Tests
task test # PHPUnit, no coverage
task test-coverage # PHPUnit + Xdebug coverage, enforces 100% gate
```

The coverage gate is **100%** and is enforced by the `Tests` GitHub
Actions workflow on every pull request — see `.github/workflows/tests.yaml`.

Run the matching check before committing changes in that area. For
commands without a dedicated task, fall back to `task compose -- <args>`
or `itkdev-docker-compose <args>`.
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ task coding-standards-composer-apply

# Run every coding-standards check
task coding-standards-check

# Run the PHPUnit test suite
task test

# Run PHPUnit with coverage and enforce the 100% gate
task test-coverage
```

For one-off commands without a dedicated task, fall back to the underlying
Expand Down Expand Up @@ -100,6 +106,28 @@ task open
The site is served through Traefik on a `*.local.itkdev.dk` domain (the exact
URL is printed by the start task).

## Testing

Tests live under `tests/` (PSR-4 namespace `App\Tests\`) and run with
[PHPUnit](https://phpunit.de/) inside the `phpfpm` container. Code
coverage is enforced at **100%** in CI — pull requests that drop coverage
below that threshold fail the `Tests` workflow.

```sh
# Run the full suite (no coverage)
task test

# Run the suite under Xdebug coverage and enforce the 100% gate
task test-coverage
```

`task test-coverage` runs PHPUnit with `XDEBUG_MODE=coverage`, writes a
Clover report to `coverage/clover.xml`, and then runs
[`rregeer/phpunit-coverage-check`](https://github.com/richardregeer/phpunit-coverage-check)
against the report. The same two steps run in the `Tests` GitHub Actions
workflow on every pull request; a coverage figure below 100% fails the
build.

## References

- **Estimation note:** <https://itk-dev.github.io/research-projects/projects/ai-bibliotek/estimeringsnotat>
Expand Down
15 changes: 15 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ tasks:
- open "$(task site-url)"
silent: true

# ---- Tests ------------------------------------------------------------

test:
desc: 'Run the PHPUnit test suite (no coverage).'
cmds:
- task compose-exec -- phpfpm vendor/bin/phpunit
silent: true

test-coverage:
desc: 'Run PHPUnit with coverage and enforce the 100% gate.'
cmds:
- task compose -- exec -e XDEBUG_MODE=coverage phpfpm vendor/bin/phpunit --coverage-clover=coverage/clover.xml
- task compose-exec -- phpfpm vendor/bin/coverage-check coverage/clover.xml 100
silent: true

# ---- Coding standards -------------------------------------------------

coding-standards-check:
Expand Down
4 changes: 4 additions & 0 deletions bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env php
<?php

require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"require-dev": {
"ergebnis/composer-normalize": "^2.52",
"friendsofphp/php-cs-fixer": "^3.95",
"phpunit/phpunit": "^11.5",
"rregeer/phpunit-coverage-check": "^0.3.1",
"symfony/browser-kit": "~8.1.0",
"symfony/css-selector": "~8.1.0",
"symfony/phpunit-bridge": "~8.1.0",
"vincentlanglet/twig-cs-fixer": "^3.14"
},
"replace": {
Expand Down
Loading