Content · Web Development · PHP

Running PHP Tests with GitHub Actions

GitHub Actions runs repeatable PHP test jobs on commits and pull requests. Use least-privilege workflow permissions and pin trusted build.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

GitHub Actions runs repeatable PHP test jobs on commits and pull requests.

What It Does


GitHub Actions runs repeatable PHP test jobs on commits and pull requests. The following examples distinguish a normal use case, a boundary case and a practical application.

Requirements and Compatibility


A local Composer project with a compatible PHPUnit version and isolated fixtures or stubs.

The code focuses on the core concept. Production implementation may also need routes, validation, persistence, authorization or deployment tooling.

Example 1: Basic Behavior


Set up PHP, install locked dependencies, and run PHPUnit on pushes and pull requests.

name: php-tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.4'
          coverage: none
      - run: composer install --no-interaction --prefer-dist
      - run: vendor/bin/phpunit --colors=never

This is a YAML configuration example; use it in its appropriate file or shell, not in the PHP source editor.

Example 2: Another Case


Fail CI early when package metadata or vulnerable locked dependencies need action.

composer validate --strict
composer audit --locked

This is a command-line example; use it in its appropriate file or shell, not in the PHP source editor.

Practical Example: Putting It to Use


A CI matrix checks supported PHP versions rather than only the development interpreter.

<?php
$supported = ['8.2', '8.3', '8.4'];
foreach ($supported as $version) echo 'Test matrix: PHP ' . $version . '; ';

Important Behavior and Edge Cases


Use least-privilege workflow permissions and pin trusted build dependencies.

Comparison with Related Functions or Approaches


OptionWhat it means in practice
Running Tests with GitHub ActionsGitHub Actions runs repeatable PHP test jobs on commits and pull requests.
Related approachComposer install plus PHPUnit is a common baseline workflow.

Common Beginner Mistakes


MistakeCorrect approach
Ignoring the important boundary for Running Tests with GitHub ActionsUse least-privilege workflow permissions and pin trusted build dependencies.
Assuming a related mechanism has the same behaviorComposer install plus PHPUnit is a common baseline workflow.

Key Takeaways


  • GitHub Actions runs repeatable PHP test jobs on commits and pull requests.
  • Use least-privilege workflow permissions and pin trusted build dependencies.
  • Composer install plus PHPUnit is a common baseline workflow.

Before adapting these examples, verify the return values, test the failure paths and confirm that your application meets its security and environment requirements.

Share this resourceSend this page to someone who may find it useful.