Skip to content

Commit 11c2844

Browse files
committed
Initial commit: PHP invoicing example for CoverageTracker
Idiomatic PHPUnit project reporting Cobertura coverage and Lizard complexity to the coverage-tracker demo instance.
0 parents  commit 11c2844

16 files changed

Lines changed: 2506 additions & 0 deletions

.github/workflows/coverage.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: coverage
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
permissions:
7+
id-token: write # OIDC → Worker
8+
checks: write # PR Check Run
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: '8.4'
18+
coverage: xdebug
19+
20+
- run: composer install --no-interaction --prefer-dist
21+
22+
- run: vendor/bin/phpunit --coverage-cobertura=coverage.xml
23+
env:
24+
XDEBUG_MODE: coverage
25+
26+
- uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.x'
29+
30+
- run: pip install lizard
31+
32+
- run: python -m lizard src --xml > lizard-report.xml
33+
34+
- uses: CoverageTracker/coverage-tracker/.github/actions/report@v0.2.0
35+
with:
36+
worker-url: https://demo.coveragetracker.dev
37+
coverage-tool: phpunit

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor/
2+
composer.phar
3+
.phpunit.result.cache
4+
coverage.xml
5+
lizard-report.xml
6+
.idea/

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# example-php
2+
3+
[![coverage badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fdemo.coveragetracker.dev%2Fapi%2Fbadge%2FCoverageTracker%2Fexample-php%2Fcoverage.json)](https://demo.coveragetracker.dev/CoverageTracker/example-php?metric=coverage)
4+
[![complexity badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fdemo.coveragetracker.dev%2Fapi%2Fbadge%2FCoverageTracker%2Fexample-php%2Fcomplexity.json)](https://demo.coveragetracker.dev/CoverageTracker/example-php?metric=complexity)
5+
6+
A small, idiomatic PHP invoicing library used as the PHP reference example
7+
for [Coverage Tracker](https://coveragetracker.dev). It exists to give the
8+
PHP row in the
9+
[coverage report generation guide](https://coveragetracker.dev/docs/generating-coverage-reports)
10+
a live, working reference, and to populate the
11+
[demo dashboard](https://demo.coveragetracker.dev) with real trend data.
12+
13+
**This is a demo/marketing repo, not a test suite for Coverage Tracker
14+
itself.**
15+
16+
## What's here
17+
18+
- `src/``Money` (integer-cents value object), `Discount` (percentage/fixed,
19+
promo-code lookup), `TaxCalculator` (tiered jurisdiction rates with a
20+
de-minimis exemption), `LineItem`, and `Invoice`, each with real branching
21+
logic.
22+
- `tests/` — a [PHPUnit](https://phpunit.de) suite with several deliberately
23+
uncovered branches (unknown promo codes, unknown tax jurisdictions,
24+
guard-clause validation), so `branch_coverage < line_coverage` shows up on
25+
the dashboard.
26+
- `.github/workflows/coverage.yml` — runs the suite under PHPUnit with
27+
Xdebug's path-coverage mode, generates a
28+
[Lizard](https://github.com/terryyin/lizard) complexity report, then
29+
reports both to the demo instance via the `coverage-tracker` reporting
30+
Action with `coverage-tool: phpunit` (Cobertura's XML shape doesn't
31+
self-identify its generator, so the reporter needs to be told to trust
32+
`branch-rate`).
33+
34+
## Running locally
35+
36+
```sh
37+
composer install
38+
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-cobertura=coverage.xml # writes coverage.xml
39+
python -m lizard src --xml > lizard-report.xml
40+
```
41+
42+
`phpunit.xml` sets `<coverage pathCoverage="true"/>` — Xdebug only emits
43+
branch data when path coverage is requested; without it PHPUnit's Cobertura
44+
report always writes `branch-rate="0"`.

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "coveragetracker/example-php",
3+
"description": "PHP reference example for Coverage Tracker: a small invoicing library (money, discounts, tiered tax, line items).",
4+
"type": "library",
5+
"license": "MIT",
6+
"require": {
7+
"php": "^8.2"
8+
},
9+
"require-dev": {
10+
"phpunit/phpunit": "^11.3"
11+
},
12+
"autoload": {
13+
"psr-4": {
14+
"CoverageTracker\\Invoicing\\": "src/"
15+
}
16+
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"CoverageTracker\\Invoicing\\Tests\\": "tests/"
20+
}
21+
},
22+
"config": {
23+
"sort-packages": true
24+
}
25+
}

0 commit comments

Comments
 (0)