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
9 changes: 4 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,15 @@ make lint-audit

## 🦠 Mutation Tests

We use [`infection/infection`](https://github.com/infection/infection) together with [`roave/infection-static-analysis-plugin`](https://github.com/Roave/infection-static-analysis-plugin) to ensure a minimum quality of the tests. Roave plugin is used to publish mutation score results to the [Stryker Dashboard](https://dashboard.stryker-mutator.io/).
We use [`infection/infection`](https://github.com/infection/infection) with the Testo adapter [`testo/bridge-infection`](https://github.com/php-testo/bridge-infection) to ensure a minimum quality of the tests. CI publishes the mutation score of the `1.x` branch to the [Stryker Dashboard](https://dashboard.stryker-mutator.io/reports/github.com/cycle/active-record/1.x).

Xdebug support is enabled by default when running commands through the `Makefile`:
Infection runs the Unit and SQLite suites and needs Xdebug or PCOV. Install it once, then run it:

```bash
make infect
composer bin infection install
composer infect
```

to run mutation tests.

<br>

## 🔍 Static Code Analysis
Expand Down
51 changes: 10 additions & 41 deletions .github/workflows/infection.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,24 @@
---

name: 🧬 Mutation Tests

on: # yamllint disable-line rule:truthy
pull_request:
push:
branches:
- 1.x

name: 🧬 Mutation Tests

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
infection:
name: Infection · PHP ${{ matrix.php-version }}
timeout-minutes: 10
runs-on: ubuntu-latest
concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
group: infection-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.php-version }}
strategy:
fail-fast: false
matrix:
php-version:
- '8.4'
steps:
- name: 📦 Check out the codebase
uses: actions/checkout@v6
with:
persist-credentials: false

- name: 🛠️ Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, pdo, pdo_sqlite
ini-values: error_reporting=E_ALL
coverage: xdebug

- name: 📥 Install dependencies with composer
uses: ramsey/composer-install@v3
with:
dependency-versions: highest

- name: 📥 Install Infection
run: composer bin infection install --no-interaction --no-progress
name: Infection
uses: cycle/gh-actions/.github/workflows/infection.yml@master
secrets: inherit

- name: 🧬 Run mutation testing with Infection
run: composer infect:ci
env:
# Upload the report to the Stryker dashboard only on push to 1.x.
# On pull requests (and forks) the key is empty, so Infection skips the upload
# instead of overwriting the branch report with PR data.
STRYKER_DASHBOARD_API_KEY: ${{ github.event_name == 'push' && secrets.STRYKER_DASHBOARD_API_KEY || '' }}
...
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"roxblnfk/unpoly": "^1.8",
"spiral/boot": "^3.18",
"spiral/cycle-bridge": "^2.13",
"testo/bridge-infection": "^0.1.9",
"testo/testo": "^0.10.60"
},
"suggest": {
Expand Down Expand Up @@ -124,13 +123,13 @@
"Composer\\Config::disableProcessTimeout",
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_DRIVERS=sqlite",
"infection"
"infection --configuration=infection.json --threads=max"
],
"infect:ci": [
"Composer\\Config::disableProcessTimeout",
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_DRIVERS=sqlite",
"infection --ansi --configuration=infection.json --logger-github --threads=max --show-mutations=0 --min-msi=50"
"infection --ansi --configuration=infection.json --logger-github --threads=max --show-mutations=0"
],
"psalm": "psalm -c vendor-bin/psalm/psalm.xml --show-info=true",
"psalm:baseline": "psalm -c vendor-bin/psalm/psalm.xml --set-baseline=vendor-bin/psalm/psalm-baseline.xml",
Expand All @@ -148,5 +147,9 @@
"@putenv DB_DRIVERS=sqlite",
"testo --coverage"
]
},
"scripts-descriptions": {
"infect": "Run mutation testing with Infection (install it first: composer bin infection install)",
"infect:ci": "Run mutation testing in CI: GitHub annotations and the MSI thresholds"
}
}
18 changes: 8 additions & 10 deletions infection.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"$schema": "vendor-bin/infection/vendor/infection/infection/resources/schema.json",
"ignoreMsiWithNoMutations": true,
"logs": {
"text": "runtime/infection/infection-log.txt",
"stryker": {
"report": "1.x"
}
},
"minCoveredMsi": 50,
"minMsi": 50,
"source": {
"directories": [
"src"
Expand All @@ -17,7 +8,14 @@
"Bridge"
]
},
"timeout": 10,
"minMsi": 90,
"minCoveredMsi": 90,
"testFramework": "testo",
"tmpDir": "runtime",
"timeout": 10
"logs": {
"stryker": {
"report": "1.x"
}
}
}
2 changes: 1 addition & 1 deletion vendor-bin/infection/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"infection/infection": "^0.35",
"infection/infection": "^0.35.12",
"testo/bridge-infection": "^0.1.9"
},
"config": {
Expand Down
Loading