Skip to content
Merged
Changes from 1 commit
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
52 changes: 32 additions & 20 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
name: CI-coverage

on: [ push ]
on: [ push, pull_request ]

permissions:
contents: read

jobs:
test-php:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php-versions: [ "7.4", "8.0", "8.4" ]
phpunit-versions: [ "9" ]
php-version: [ "7.4", "8.0", "8.4" ]
steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v6
- uses: actions/checkout@v5

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php_version: "${{ matrix.php-versions }}"
dev: yes
interaction: no
- name: PHPUnit Tests php
uses: php-actions/phpunit@v2
php-version: "${{ matrix.php-version }}"
extensions: curl, json
coverage: xdebug
tools: composer:v2
ini-values: xdebug.mode=coverage

Comment on lines +18 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enable Xdebug/coverage only on the coverage job; drop redundant json extension

  • json is built-in on supported PHP versions; no need to list it.
  • You enable coverage for every matrix job; that slows tests considerably. Only the 8.4 job uploads coverage, so turn Xdebug on only there.

Apply:

       - name: Set up PHP
         uses: shivammathur/setup-php@v2
         with:
           php-version: "${{ matrix.php-version }}"
-          extensions: curl, json
-          coverage: xdebug
+          extensions: curl
+          coverage: ${{ matrix.php-version == '8.4' && 'xdebug' || 'none' }}
           tools: composer:v2
-          ini-values: xdebug.mode=coverage

Then adjust the PHPUnit step (see below) to only enable coverage on 8.4.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
.github/workflows/phpunit.yml lines 18-26: the workflow currently lists the
built-in json extension and enables Xdebug/coverage for every matrix job; remove
json from the extensions list and make Xdebug/coverage and its ini-values only
enabled for the 8.4 matrix job. Update the setup-php step to omit json (e.g.,
extensions: curl) and add a conditional so coverage: xdebug and ini-values:
xdebug.mode=coverage are set only when matrix.php-version == '8.4', and then
modify the PHPUnit step to only run coverage-related flags/upload when
matrix.php-version == '8.4'.

- name: Validate Composer files
run: composer validate --strict

- name: Install dependencies
uses: ramsey/composer-install@v3
with:
version: "${{ matrix.phpunit-versions }}"
php_version: "${{ matrix.php-versions }}"
php_extensions: xdebug
bootstrap: vendor/autoload.php
configuration: phpunit.xml
args: --coverage-clover=coverage.xml --exclude-group local-only
composer-options: --no-interaction --prefer-dist

- name: Run PHPUnit
run: vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml --exclude-group local-only
env:
XDEBUG_MODE: coverage
- name: Upload to Codecov
uses: codecov/codecov-action@v1

Comment on lines +35 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Run coverage only on PHP 8.4 to speed up the matrix

Currently you collect coverage on all PHP versions. Use a small shell wrapper to only enable coverage on 8.4 and run plain tests elsewhere.

-      - name: Run PHPUnit
-        run: vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml --exclude-group local-only
-        env:
-          XDEBUG_MODE: coverage
+      - name: Run PHPUnit
+        run: |
+          if [[ "${{ matrix.php-version }}" == "8.4" ]]; then
+            XDEBUG_MODE=coverage vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml --exclude-group local-only
+          else
+            vendor/bin/phpunit --configuration phpunit.xml --exclude-group local-only
+          fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run PHPUnit
run: vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml --exclude-group local-only
env:
XDEBUG_MODE: coverage
- name: Upload to Codecov
uses: codecov/codecov-action@v1
- name: Run PHPUnit
run: |
if [[ "${{ matrix.php-version }}" == "8.4" ]]; then
XDEBUG_MODE=coverage vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml --exclude-group local-only
else
vendor/bin/phpunit --configuration phpunit.xml --exclude-group local-only
fi
🤖 Prompt for AI Agents
In .github/workflows/phpunit.yml around lines 35 to 39, the workflow currently
sets XDEBUG_MODE: coverage and collects coverage on every PHP version; change
the run command to a small shell wrapper that checks the PHP version (e.g., from
the matrix PHP version env or php -v) and only sets XDEBUG_MODE=coverage and
passes --coverage-clover=coverage.xml when the version equals 8.4, otherwise run
vendor/bin/phpunit without XDEBUG_MODE and without the --coverage-clover flag;
ensure the wrapper preserves the PHPUnit exit code so the job fails on test
failures.

- name: Upload coverage to Codecov
if: matrix.php-version == '8.4'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
files: ./coverage.xml
disable_search: true
fail_ci_if_error: true
Comment on lines +40 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Prevent failures on forked PRs; gate Codecov upload by event

On pull_request from forks, CODECOV_TOKEN is not available. With fail_ci_if_error: true, the workflow can fail the PR. Gate the upload to push events (or when the token exists).

-      - name: Upload coverage to Codecov
-        if: matrix.php-version == '8.4'
+      - name: Upload coverage to Codecov
+        if: github.event_name == 'push' && matrix.php-version == '8.4'
         uses: codecov/codecov-action@v4
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
           files: ./coverage.xml
           disable_search: true
-          fail_ci_if_error: true
+          fail_ci_if_error: true

Alternatively, if you want uploads on PRs from the same repo, use:

  • if: matrix.php-version == '8.4' && github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Upload coverage to Codecov
if: matrix.php-version == '8.4'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
files: ./coverage.xml
disable_search: true
fail_ci_if_error: true
- name: Upload coverage to Codecov
if: github.event_name == 'push' && matrix.php-version == '8.4'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
disable_search: true
fail_ci_if_error: true
🤖 Prompt for AI Agents
.github/workflows/phpunit.yml around lines 40 to 47: the Codecov upload step
currently runs on pull_request for forked PRs where CODECOV_TOKEN is unavailable
and fail_ci_if_error:true can fail the workflow; update the step’s if condition
to only run when it’s safe — e.g., require push events or that the event is a
pull_request from the same repo (github.event_name != 'pull_request' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork
== false)), or alternatively check that secrets.CODECOV_TOKEN exists before
running — this will prevent failures on forked PRs while allowing uploads from
allowed events.

Loading