Skip to content

Check the purity declarations of methods without a body #33589

Check the purity declarations of methods without a body

Check the purity declarations of methods without a body #33589

Workflow file for this run

# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Tests"
on:
pull_request:
paths-ignore:
- 'compiler/**'
- 'apigen/**'
- 'changelog-generator/**'
- 'issue-bot/**'
push:
branches:
- "2.3.x"
paths-ignore:
- 'compiler/**'
- 'apigen/**'
- 'changelog-generator/**'
- 'issue-bot/**'
concurrency:
group: tests-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches
cancel-in-progress: true
jobs:
tests:
name: "Tests PHPUnit 12.x"
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
php-version:
- "8.3"
- "8.4"
- "8.5"
- "8.6"
operating-system: [ ubuntu-latest, windows-latest ]
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: "Install PHP"
uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # 2.37.2
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=-1
- name: "Upgrade PHPUnit 12"
shell: bash
run: |
composer require --dev phpunit/phpunit:^12 brianium/paratest:^7.16 symfony/process:^7 symfony/string:^7 symfony/console:^7 --update-with-dependencies --ignore-platform-reqs --working-dir=tests
composer require --dev phpunit/phpunit:^12 sebastian/diff --update-with-dependencies --ignore-platform-reqs
- name: "Check PHP configuration"
run: "vendor/bin/phpunit --check-php-configuration"
- name: "Tests"
run: "php tests/vendor/bin/paratest --runner WrapperRunner --no-coverage"
tests-phpunit11:
name: "Tests PHPUnit 11.x"
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
php-version:
- "8.2"
operating-system: [ ubuntu-latest, windows-latest ]
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: "Install PHP"
uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # 2.37.2
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=-1
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
- name: "Check PHP configuration"
run: "vendor/bin/phpunit --check-php-configuration"
- name: "Tests"
run: "make tests"
tests-integration:
name: "Integration tests"
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest ]
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: "Install PHP"
uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # 2.37.2
with:
coverage: "none"
php-version: "8.2"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=-1
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
- name: "Check PHP configuration"
run: "vendor/bin/phpunit --check-php-configuration"
- name: "Tests"
run: "make tests-integration"
tests-levels-matrix:
name: "Determine levels tests matrix"
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: "Install PHP"
uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # 2.37.2
with:
coverage: "none"
php-version: "8.3"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=1G
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
- id: set-matrix
run: echo "matrix=$(php .github/workflows/tests-levels-matrix.php)" >> "$GITHUB_OUTPUT"
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
tests-levels:
needs: tests-levels-matrix
name: "Levels tests"
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
script: "${{fromJson(needs.tests-levels-matrix.outputs.matrix)}}"
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: "Install PHP"
uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # 2.37.2
with:
coverage: "none"
php-version: "8.3"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=-1
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
- name: "Check PHP configuration"
run: "vendor/bin/phpunit --check-php-configuration"
- name: "Tests"
run: "${{ matrix.script }}"
tests-with-old-phpunit:
name: "Tests with old PHPUnit"
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
operating-system: [ ubuntu-latest, windows-latest ]
include:
- php-version: "8.1"
operating-system: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: "Install PHP"
uses: "shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240" # 2.37.2
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=2G
- name: "Downgrade PHPUnit"
shell: bash
run: "composer require --dev phpunit/phpunit:^9.6 sebastian/diff:^4.0 doctrine/instantiator:^1.0 --update-with-dependencies --ignore-platform-reqs"
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
- name: "Downgrade PHPUnit with Paratest"
shell: bash
run: "composer require --dev phpbench/phpbench:^1.2.15 phpunit/phpunit:^9.6 brianium/paratest:^6.5 symfony/console:^5.4 symfony/process:^5.4 doctrine/instantiator:^1.0 --update-with-dependencies --ignore-platform-reqs --working-dir=tests"
- uses: ./.github/actions/downgrade-code
with:
php-version: "${{ matrix.php-version }}"
- name: "Tests"
run: "make tests"
mutation-testing-changed-files:
name: "Mutation Testing: changed files"
runs-on: "ubuntu-latest"
if: github.event_name == 'pull_request'
permissions:
contents: read
env:
# The branch the diff is taken against - the branch this file lives on.
# Flipped by the "Open X.Y.x" commit, like the push branch above.
MUTATION_TESTING_BASE_BRANCH: "2.3.x"
outputs:
base-branch: ${{ env.MUTATION_TESTING_BASE_BRANCH }}
any: ${{ steps.changed-files.outputs.any }}
files: ${{ steps.changed-files.outputs.files }}
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
# The same files Infection picks with --git-diff-base and its default AM
# filter over its source directories
- name: "Find changed source files"
id: changed-files
run: |
git fetch --depth=1 origin "$MUTATION_TESTING_BASE_BRANCH"
base=$(git merge-base "origin/$MUTATION_TESTING_BASE_BRANCH" HEAD || echo "origin/$MUTATION_TESTING_BASE_BRANCH")
files=$(git diff "$base" --diff-filter=AM --name-only -- src build/PHPStan/Build | grep '\.php$' || true)
echo "$files"
{
if [ -n "$files" ]; then echo "any=true"; else echo "any=false"; fi
echo 'files<<EOF'
echo "$files"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
mutation-testing:
name: "Mutation Testing"
runs-on: "ubuntu-latest"
needs: ["tests", "mutation-testing-changed-files"]
if: github.event_name == 'pull_request' && needs.mutation-testing-changed-files.outputs.any == 'true'
strategy:
fail-fast: false
matrix:
php-version:
- "8.3"
- "8.4"
operating-system: [ubuntu-latest]
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: "Checkout build-infection"
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
repository: "phpstan/build-infection"
path: "build-infection"
ref: "1.x"
- uses: ./build-infection/.github/actions/setup-php
with:
php-version: "${{ matrix.php-version }}"
php-extensions: ds,mbstring
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
with:
working-directory: "tests/"
- name: "Upgrade PHPUnit with Paratest to speedup coverage generation"
shell: bash
run: |
composer require --dev phpunit/phpunit:^12 brianium/paratest:^7.16 symfony/process:^7 symfony/string:^7 symfony/console:^7 --update-with-dependencies --ignore-platform-reqs --working-dir=tests
composer require --dev phpunit/phpunit:^12 sebastian/diff --update-with-dependencies --ignore-platform-reqs
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
with:
working-directory: "build-infection/"
- name: "Configure infection"
run: |
php build-infection/bin/infection-config.php \
--source-directory='build/PHPStan/Build' \
--timeout=500 \
> infection.json5
jq < infection.json5
- name: "Restore result cache"
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: ./tmp
key: "result-cache-v1-${{ matrix.php-version }}-${{ github.run_id }}"
restore-keys: |
result-cache-v1-${{ matrix.php-version }}-
# Infection reads the coverage report of every source file it lists, and
# the whole of src/ outgrew the runner's memory - only the mutated files
# need it
- name: "Restrict coverage to the changed source files"
env:
CHANGED_FILES: ${{ needs.mutation-testing-changed-files.outputs.files }}
run: |
echo "$CHANGED_FILES" > "$RUNNER_TEMP/changed-files.txt"
php -- "$RUNNER_TEMP/changed-files.txt" <<'PHP'
<?php
$document = new DOMDocument();
$document->load('phpunit.xml');
$include = $document->getElementsByTagName('source')->item(0)->getElementsByTagName('include')->item(0);
while ($include->firstChild !== null) {
$include->removeChild($include->firstChild);
}
foreach (file($argv[1], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $file) {
$include->appendChild($document->createElement('file', $file));
}
$document->save('phpunit-mutation-testing.xml');
PHP
grep -A5 "<source" phpunit-mutation-testing.xml
# see https://infection.github.io/guide/command-line-options.html#coverage
- name: "Create coverage in parallel"
run: |
php -d pcov.enabled=1 tests/vendor/bin/paratest \
--configuration=phpunit-mutation-testing.xml \
--passthru-php="'-d' 'pcov.enabled=1'" \
--coverage-xml=tmp/coverage/coverage-xml \
--coverage-clover=tmp/coverage/clover.xml \
--log-junit=tmp/coverage/junit.xml \
--exclude-source-from-xml-coverage
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage-reports
path: tmp/coverage
- name: "Run infection"
env:
BASE_BRANCH: ${{ needs.mutation-testing-changed-files.outputs.base-branch }}
run: |
git fetch --depth=1 origin "$BASE_BRANCH"
infection \
--git-diff-base="origin/$BASE_BRANCH" \
--git-diff-lines \
--coverage=tmp/coverage \
--skip-initial-tests \
--ignore-msi-with-no-mutations \
--min-msi=100 \
--min-covered-msi=100 \
--log-verbosity=all \
--debug \
--logger-text=php://stdout
- name: "Save result cache"
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
if: ${{ !cancelled() }}
with:
path: ./tmp
key: "result-cache-v1-${{ matrix.php-version }}-${{ github.run_id }}"