Skip to content

Commit

Permalink
CI: Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryJones committed May 22, 2024
1 parent 95e00a6 commit e8c547f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Unit Tests

on: [push]

jobs:
test:
name: WP ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.allowed_failure }}

env:
WP_VERSION: ${{ matrix.wordpress }}

strategy:
matrix:
include:
# Check lowest supported WP version, with the lowest supported PHP.
- wordpress: '5.9'
php: '7.4'
allowed_failure: false
# Check latest WP with the highest supported PHP.
- wordpress: 'latest'
php: 'latest'
allowed_failure: false
# Check upcoming WP.
- wordpress: 'trunk'
php: 'latest'
allowed_failure: true
# Check upcoming PHP - only needed when a new version has been forked (typically Sep-Nov)
# - wordpress: 'trunk'
# php: 'nightly'
# allowed_failure: true
fail-fast: false

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: ${{ matrix.ini-values }}
coverage: ${{ matrix.coverage }}

- name: Install Composer dependencies
uses: ramsey/composer-install@v3
with:
composer-options: --ignore-platform-req=php+

- name: Set up problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Set up problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Show PHP and PHPUnit version info
run: |
php --version
./vendor/bin/phpunit --version
- name: Run unit tests (single site)
run: composer test-unit

- name: Run unit tests (multisite)
run: composer test-unit-ms
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"test-unit": [
"@php ./vendor/phpunit/phpunit/phpunit --testdox --no-coverage"
],
"test-unit-ms": [
"@putenv WP_MULTISITE=1",
"@test-unit"
],
"test-coverage": [
"@php ./vendor/phpunit/phpunit/phpunit --coverage-text --coverage-html=coverage && echo coverage/index.html"
]
Expand Down

0 comments on commit e8c547f

Please sign in to comment.