From ab709591d7e834692ac974f6b8610e93398ff5ae Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 19:25:22 +0100 Subject: [PATCH 1/2] Setup mutation testing --- .github/workflows/build.yml | 73 +++++++++++++++++++++++++++++++++++++ phpstan.neon | 2 + phpunit.xml | 3 +- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index db0977e..0915351 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,10 @@ on: branches: - "2.0.x" +concurrency: + group: build-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches + cancel-in-progress: true + jobs: lint: name: "Lint" @@ -159,3 +163,72 @@ jobs: - name: "PHPStan" run: "make phpstan" + + mutation-testing: + name: "Mutation Testing" + runs-on: "ubuntu-latest" + needs: ["tests", "static-analysis"] + + strategy: + fail-fast: false + matrix: + php-version: + - "8.2" + - "8.3" + - "8.4" + operating-system: [ubuntu-latest] + + steps: + - name: "Checkout" + uses: actions/checkout@v5 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + tools: pecl, infection:0.31.7 + extensions: mbstring + ini-file: development + ini-values: memory_limit=-1 + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress" + + - name: "Checkout build-infection" + uses: actions/checkout@v5 + with: + repository: "phpstan/build-infection" + path: "build-infection" + ref: "1.x" + + - name: "Install build-infection dependencies" + working-directory: "build-infection" + run: "composer install --no-interaction --no-progress" + + - name: "Configure infection" + run: | + php build-infection/bin/infection-config.php \ + > infection.json5 + cat infection.json5 | jq + + - name: "Cache Result cache" + uses: actions/cache@v4 + with: + path: ./tmp + key: "result-cache-v1-${{ matrix.php-version }}-${{ github.run_id }}" + restore-keys: | + result-cache-v1-${{ matrix.php-version }}- + + - name: "Run infection" + run: | + git fetch --depth=1 origin $GITHUB_BASE_REF + infection \ + --git-diff-base=origin/$GITHUB_BASE_REF \ + --git-diff-lines \ + --ignore-msi-with-no-mutations \ + --min-msi=100 \ + --min-covered-msi=100 \ + --log-verbosity=all \ + --debug \ + --logger-text=php://stdout diff --git a/phpstan.neon b/phpstan.neon index 3e184cd..4a083f0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,5 +5,7 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon parameters: + resultCachePath: tmp/resultCache.php + excludePaths: - tests/*/data/* diff --git a/phpunit.xml b/phpunit.xml index edb71a8..ae3db0d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,7 +10,8 @@ beStrictAboutTodoAnnotatedTests="true" failOnRisky="true" failOnWarning="true" - xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xml" + xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" + executionOrder="random" > From baa4aba12f0f549936900d751ddbb5165c3b4f53 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 21:20:46 +0100 Subject: [PATCH 2/2] Update build.yml --- .github/workflows/build.yml | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0915351..3709a74 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -182,19 +182,6 @@ jobs: - name: "Checkout" uses: actions/checkout@v5 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - tools: pecl, infection:0.31.7 - extensions: mbstring - ini-file: development - ini-values: memory_limit=-1 - - - name: "Install dependencies" - run: "composer install --no-interaction --no-progress" - - name: "Checkout build-infection" uses: actions/checkout@v5 with: @@ -202,6 +189,14 @@ jobs: path: "build-infection" ref: "1.x" + - uses: ./build-infection/.github/actions/setup-php + with: + php-version: "${{ matrix.php-version }}" + extensions: mbstring + + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress" + - name: "Install build-infection dependencies" working-directory: "build-infection" run: "composer install --no-interaction --no-progress"