Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
108 changes: 57 additions & 51 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
name: PHPUnit
permissions:
contents: read

on:
push:
Expand All @@ -11,65 +9,73 @@ on:
branches:
- develop

permissions:
contents: read

jobs:
check-diffs:
phpunit:
name: Test PHP ${{ matrix.php }} WP ${{ matrix.wp }}
runs-on: ubuntu-latest
outputs:
has_changed: ${{ steps.files-changed.outputs.RSA_PHP_FILES_CHANGED }}
strategy:
fail-fast: false
matrix:
php: [ '8.4', '8.3', '8.2', '8.1', '8.0', '7.4' ]
wp: [ latest, trunk ]
env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Get updated PHP files
id: changed-files
uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1
with:
files: |
**/*.php
composer.json
composer.lock
phpunit.xml

- id: files-changed
- name: Configure environment variables
run: |
if [[ ( "${{ steps.changed-files.outputs.any_changed }}" == 'true' && "${{ github.event_name }}" == "pull_request" ) || "${{ github.event_name }}" == "push" ]]; then
echo "RSA_PHP_FILES_CHANGED=yes" >> $GITHUB_OUTPUT
fi
echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV"
echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV"

phpunit:
runs-on: ubuntu-latest
needs: check-diffs
if: needs.check-diffs.outputs.has_changed == 'yes'

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
persist-credentials: false

- uses: getong/mariadb-action@d6d2ec41fd5588f369be4c9398ce77ee725ca9ea # v1.11
##
# This allows Composer dependencies to be installed using a single step.
#
# Since the tests are currently run within the Docker containers where the PHP version varies,
# the same PHP version needs to be configured for the action runner machine so that the correct
# dependency versions are installed and cached.
##
- name: Set up PHP
uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4
with:
php-version: '${{ matrix.php }}'
coverage: none

- name: Set PHP version
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
with:
php-version: '7.4'
coverage: none
tools: composer:v2
- name: Install Composer dependencies
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1

- name: Install dependencies
run: composer install
- name: Setup Node
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
cache: 'npm'
node-version-file: '.nvmrc'

- name: install node v16
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
with:
node-version-file: '.nvmrc'
- name: Install NPM dependencies
run: npm ci && npm run build

- name: Install dependencies
run: npm i && npm run build
- name: Start the Docker testing environment
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
with:
timeout_minutes: 10
max_attempts: 3
command: |
npm run env:start

- name: Setup WP Tests
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1
- name: Log versions
run: |
npm run env -- run cli php -- -v
npm run env -- run cli wp core version

- name: PHPUnit
run: './vendor/bin/phpunit'
- name: Run PHPUnit tests
id: phpunit
run: |
npm run test:php
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ assets/js/build

tests/cypress/screenshots
tests/cypress/videos
tests/cypress/reports
tests/cypress/reports
/tests/_output/*
!/tests/_output/.gitkeep
/tests/.phpunit.result.cache
21 changes: 19 additions & 2 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
{
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
"core": null,
"plugins": [ ".", "./tests/rsa-seeder" ],
"plugins": [".", "./tests/rsa-seeder"],
"config": {
"WP_ALLOW_MULTISITE": true
},
"env": {
"development": {
"config": {
"WP_DEVELOPMENT_MODE": "plugin",
"WP_ENVIRONMENT_TYPE": "development",
"WP_DEBUG": true,
"WP_DEBUG_LOG": "/var/www/html/wp-content/plugins/restricted-site-access/tests/_output/debug.log"
}
},
"tests": {
"config": {
"WP_DEBUG": true,
"FS_METHOD": "direct"
},
"mappings": {
".htaccess": "./tests/bin/.htaccess"
".htaccess": "./tests/bin/.htaccess",
"wp-cli.yml": "./tests/bin/wp-cli.yml"
}
}
},
"lifecycleScripts": {
"afterStart": "bash ./tests/bin/initialize.sh"
}
}
171 changes: 0 additions & 171 deletions bin/install-wp-tests.sh

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require-dev": {
"10up/phpcs-composer": "dev-master",
"phpunit/phpunit": "9.6.33",
"yoast/phpunit-polyfills": "1.x-dev"
"yoast/phpunit-polyfills": "^4.0"
},
"scripts": {
"test": "phpunit",
Expand Down
Loading
Loading