From 1c439c97c39d99e162e1feccf800ac07c362cbc6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 25 Oct 2025 09:50:35 +0200 Subject: [PATCH 01/13] Setup mutation testing --- .github/workflows/static-analysis.yml | 5 +++ .github/workflows/tests.yml | 62 +++++++++++++++++++++++++++ infection.json5 | 18 ++++++++ 3 files changed, 85 insertions(+) create mode 100644 infection.json5 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index ec4fb7ba05..8e660c6fc7 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -85,6 +85,11 @@ jobs: - name: "PHPStan" run: "make phpstan" + - uses: "actions/upload-artifact@v4" + with: + name: "result-cache-${{ matrix.php-version }}${{ matrix.operating-system-packages}}" + path: "tmp/resultCache.php" + static-analysis-with-result-cache: name: "PHPStan with result cache" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 976571c5cf..28b71881db 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -222,3 +222,65 @@ jobs: - name: "Tests" run: "make tests" + + mutation-testing: + name: "Mutation Testing" + runs-on: "ubuntu-latest" + needs: ["tests", "tests-levels"] + + 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: ds,mbstring + ini-file: development + ini-values: memory_limit=-1 + + - uses: "ramsey/composer-install@v3" + + - name: "Check PHP configuration" + run: "vendor/bin/phpunit --check-php-configuration" + + - 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" + + - uses: "actions/download-artifact@v4" + with: + name: "result-cache-${{ matrix.php-version }}${{ matrix.operating-system-packages}}" + path: "tmp/" + + - 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/infection.json5 b/infection.json5 new file mode 100644 index 0000000000..f6a55ac107 --- /dev/null +++ b/infection.json5 @@ -0,0 +1,18 @@ +{ + "$schema": "vendor/infection/infection/resources/schema.json", + "timeout": 30, + "source": { + "directories": [ + "src" + ] + }, + "staticAnalysisTool": "phpstan", + "logs": { + "text": "tmp/infection.log" + }, + "bootstrap": "build-infection/vendor/autoload.php", + "mutators": { + "@default": false, + "PHPStan\\Infection\\TrinaryLogicMutator": true + } +} From 8954c43f340060acd824b3828e8669101a851a6c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 25 Oct 2025 09:56:52 +0200 Subject: [PATCH 02/13] simplify --- .github/workflows/static-analysis.yml | 5 ----- .github/workflows/tests.yml | 5 ----- 2 files changed, 10 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 8e660c6fc7..ec4fb7ba05 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -85,11 +85,6 @@ jobs: - name: "PHPStan" run: "make phpstan" - - uses: "actions/upload-artifact@v4" - with: - name: "result-cache-${{ matrix.php-version }}${{ matrix.operating-system-packages}}" - path: "tmp/resultCache.php" - static-analysis-with-result-cache: name: "PHPStan with result cache" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 28b71881db..1b7b05abd8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -267,11 +267,6 @@ jobs: working-directory: "build-infection" run: "composer install --no-interaction --no-progress" - - uses: "actions/download-artifact@v4" - with: - name: "result-cache-${{ matrix.php-version }}${{ matrix.operating-system-packages}}" - path: "tmp/" - - name: "Run infection" run: | git fetch --depth=1 origin $GITHUB_BASE_REF From 8b10978bdc90fa539c0d533ace0ae79657bb2df8 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 25 Oct 2025 10:00:53 +0200 Subject: [PATCH 03/13] Update tests.yml --- .github/workflows/tests.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1b7b05abd8..ae4f52bfc7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -253,6 +253,14 @@ jobs: - uses: "ramsey/composer-install@v3" + - name: "Cache Result cache" + uses: actions/cache@v4 + with: + path: ./tmp + key: "result-cache-v14-${{ matrix.php-version }}-${{ github.run_id }}" + restore-keys: | + result-cache-v14-${{ matrix.php-version }}- + - name: "Check PHP configuration" run: "vendor/bin/phpunit --check-php-configuration" From e2bd318dd72f8c16ef8dcbe8f10f102a90036968 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 25 Oct 2025 10:09:00 +0200 Subject: [PATCH 04/13] test change --- src/Rules/Variables/DefinedVariableRule.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Rules/Variables/DefinedVariableRule.php b/src/Rules/Variables/DefinedVariableRule.php index 8fbb1e5d0b..0ec683cf61 100644 --- a/src/Rules/Variables/DefinedVariableRule.php +++ b/src/Rules/Variables/DefinedVariableRule.php @@ -45,6 +45,15 @@ public function processNode(Node $node, Scope $scope): array $variableNameScopes = [$node->name => $scope]; } else { $nameType = $scope->getType($node->name); + + // testing stuff + $obj = (new ObjectType('SomeClass'))->isSuperTypeOf($nameType); + if ($obj->yes()) { + $x = 1; + } else { + $x = 2; + } + $variableNameScopes = []; foreach ($nameType->getConstantStrings() as $constantString) { $name = $constantString->getValue(); From b0196f9f22d57f30293a1ea10091bd414de8ac5b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 19:01:47 +0100 Subject: [PATCH 05/13] Update tests.yml --- .github/workflows/tests.yml | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ae4f52bfc7..539c7b4fa6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -246,23 +246,16 @@ jobs: with: coverage: "pcov" php-version: "${{ matrix.php-version }}" - tools: pecl, infection:0.31.7 - extensions: ds,mbstring ini-file: development - ini-values: memory_limit=-1 + extensions: ds,mbstring + tools: infection:0.31.7 - - uses: "ramsey/composer-install@v3" + - name: "Allow installing on PHP 8.4" + if: matrix.php-version == '8.4' + run: "composer config platform.php 8.3.99" - - name: "Cache Result cache" - uses: actions/cache@v4 - with: - path: ./tmp - key: "result-cache-v14-${{ matrix.php-version }}-${{ github.run_id }}" - restore-keys: | - result-cache-v14-${{ matrix.php-version }}- - - - name: "Check PHP configuration" - run: "vendor/bin/phpunit --check-php-configuration" + - name: "Install dependencies" + run: "composer install --no-interaction --no-progress" - name: "Checkout build-infection" uses: actions/checkout@v5 @@ -275,6 +268,20 @@ jobs: 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 From ade0affed7a3a51fdc03f02494534212123b30b5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 19:02:54 +0100 Subject: [PATCH 06/13] Update tests.yml --- .github/workflows/tests.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 539c7b4fa6..ef2bc28ae8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -250,10 +250,6 @@ jobs: extensions: ds,mbstring tools: infection:0.31.7 - - name: "Allow installing on PHP 8.4" - if: matrix.php-version == '8.4' - run: "composer config platform.php 8.3.99" - - name: "Install dependencies" run: "composer install --no-interaction --no-progress" From a0bd193e7fa1160d3afd7c4153137bab4b3e2685 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 19:04:00 +0100 Subject: [PATCH 07/13] Delete infection.json5 --- infection.json5 | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 infection.json5 diff --git a/infection.json5 b/infection.json5 deleted file mode 100644 index f6a55ac107..0000000000 --- a/infection.json5 +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "vendor/infection/infection/resources/schema.json", - "timeout": 30, - "source": { - "directories": [ - "src" - ] - }, - "staticAnalysisTool": "phpstan", - "logs": { - "text": "tmp/infection.log" - }, - "bootstrap": "build-infection/vendor/autoload.php", - "mutators": { - "@default": false, - "PHPStan\\Infection\\TrinaryLogicMutator": true - } -} From b61b526085dbe882ccee2370d513558bd06ba40a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 19:09:30 +0100 Subject: [PATCH 08/13] Update DefinedVariableRule.php --- src/Rules/Variables/DefinedVariableRule.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Rules/Variables/DefinedVariableRule.php b/src/Rules/Variables/DefinedVariableRule.php index 0ec683cf61..85dc0cf7bb 100644 --- a/src/Rules/Variables/DefinedVariableRule.php +++ b/src/Rules/Variables/DefinedVariableRule.php @@ -12,6 +12,7 @@ use PHPStan\Rules\IdentifierRuleError; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; +use PHPStan\Type\ObjectType; use function array_merge; use function in_array; use function is_string; From 4863a3cf5682fa61e2e00edac9bf7367df55fe3a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 19:13:42 +0100 Subject: [PATCH 09/13] Discard changes to src/Rules/Variables/DefinedVariableRule.php --- src/Rules/Variables/DefinedVariableRule.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Rules/Variables/DefinedVariableRule.php b/src/Rules/Variables/DefinedVariableRule.php index 85dc0cf7bb..8fbb1e5d0b 100644 --- a/src/Rules/Variables/DefinedVariableRule.php +++ b/src/Rules/Variables/DefinedVariableRule.php @@ -12,7 +12,6 @@ use PHPStan\Rules\IdentifierRuleError; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; -use PHPStan\Type\ObjectType; use function array_merge; use function in_array; use function is_string; @@ -46,15 +45,6 @@ public function processNode(Node $node, Scope $scope): array $variableNameScopes = [$node->name => $scope]; } else { $nameType = $scope->getType($node->name); - - // testing stuff - $obj = (new ObjectType('SomeClass'))->isSuperTypeOf($nameType); - if ($obj->yes()) { - $x = 1; - } else { - $x = 2; - } - $variableNameScopes = []; foreach ($nameType->getConstantStrings() as $constantString) { $name = $constantString->getValue(); From b636db27a987197668f50c388a8b648d89c34eae Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 21:23:53 +0100 Subject: [PATCH 10/13] Update tests.yml --- .github/workflows/tests.yml | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ef2bc28ae8..ba932e152e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -226,7 +226,8 @@ jobs: mutation-testing: name: "Mutation Testing" runs-on: "ubuntu-latest" - needs: ["tests", "tests-levels"] + needs: ["tests"] + if: github.event_name == 'pull_request' strategy: fail-fast: false @@ -241,18 +242,6 @@ jobs: - name: "Checkout" uses: actions/checkout@v5 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-file: development - extensions: ds,mbstring - tools: infection:0.31.7 - - - name: "Install dependencies" - run: "composer install --no-interaction --no-progress" - - name: "Checkout build-infection" uses: actions/checkout@v5 with: @@ -260,6 +249,14 @@ jobs: path: "build-infection" ref: "1.x" + - uses: ./build-infection/.github/actions/setup-php + with: + php-version: "${{ matrix.php-version }}" + extensions: ds,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" From 3dc53c00dfbcc3ce9cbb5ec9f526297379573a7e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 21:30:22 +0100 Subject: [PATCH 11/13] Update tests.yml --- .github/workflows/tests.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ba932e152e..8fdcf94d04 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -267,8 +267,8 @@ jobs: > infection.json5 cat infection.json5 | jq - - name: "Cache Result cache" - uses: actions/cache@v4 + - name: "Restore result cache" + uses: actions/cache/restore@v4 with: path: ./tmp key: "result-cache-v1-${{ matrix.php-version }}-${{ github.run_id }}" @@ -287,3 +287,10 @@ jobs: --log-verbosity=all \ --debug \ --logger-text=php://stdout + + - name: "Save result cache" + uses: actions/cache/save@v4 + if: ${{ !cancelled() }} + with: + path: ./tmp + key: "result-cache-v1-${{ matrix.php-version }}-${{ github.run_id }}" From 447ad116ea9fa7e8d5cbce0cd2b3e8ecc21e18e3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 21:49:10 +0100 Subject: [PATCH 12/13] Update tests.yml --- .github/workflows/tests.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8fdcf94d04..d2db92c587 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -267,6 +267,11 @@ jobs: > infection.json5 cat infection.json5 | jq + - name: "Determine default branch" + id: default-branch + run: | + echo "name=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')" >> $GITHUB_OUTPUT + - name: "Restore result cache" uses: actions/cache/restore@v4 with: @@ -277,9 +282,9 @@ jobs: - name: "Run infection" run: | - git fetch --depth=1 origin $GITHUB_BASE_REF + git fetch --depth=1 origin ${{ steps.default-branch.outputs.name }} infection \ - --git-diff-base=origin/$GITHUB_BASE_REF \ + --git-diff-base=origin/${{ steps.default-branch.outputs.name }} \ --git-diff-lines \ --ignore-msi-with-no-mutations \ --min-msi=100 \ From 823cf3bed6155239f32563e41cedec7f624cab89 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Oct 2025 21:51:15 +0100 Subject: [PATCH 13/13] Update tests.yml --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d2db92c587..348cb70f9c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -264,6 +264,7 @@ jobs: - name: "Configure infection" run: | php build-infection/bin/infection-config.php \ + --source-directory='build/PHPStan/Build' \ > infection.json5 cat infection.json5 | jq