Skip to content

chore: Added test to Previews and setup test workflow for plugins #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
83ab584
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy Jun 3, 2025
b402f05
Removed Post_Data_Model class as not used anymore.
colinmurphy Jun 3, 2025
77ae3dd
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy Jun 3, 2025
9ce7e07
Initial setup of testing framework.
colinmurphy Jun 4, 2025
4910d38
Modified workflow to fix working directory issue.
colinmurphy Jun 4, 2025
fd7b00c
Moved codeception into its own action.
colinmurphy Jun 4, 2025
d2417aa
Updated path for the codeception action.
colinmurphy Jun 4, 2025
9c387c0
Fixing action to get it working.
colinmurphy Jun 4, 2025
f41a5fa
Fixed path.
colinmurphy Jun 4, 2025
b9dc66a
Added missing step to get plugin directory.
colinmurphy Jun 4, 2025
4167311
Fixed variable for working directory to include plugins.
colinmurphy Jun 4, 2025
f5d3b54
Updating action. Not complete.
colinmurphy Jun 4, 2025
05e30c4
Updated workflow.
colinmurphy Jun 4, 2025
aaa3442
Fixed workflow.
colinmurphy Jun 4, 2025
bbbc9e4
Added .env.ci file
colinmurphy Jun 4, 2025
00501ab
Added missing install plugins script.
colinmurphy Jun 4, 2025
e949af5
Only install npm if it exists.
colinmurphy Jun 4, 2025
85c2210
Added tests.
colinmurphy Jun 4, 2025
86b4a38
Added codeception config file.
colinmurphy Jun 4, 2025
96881aa
Added missing dev packages for composer.
colinmurphy Jun 4, 2025
faebbea
Fixes for tests
colinmurphy Jun 4, 2025
75615de
Added codeception build.
colinmurphy Jun 4, 2025
a5cc643
Trying to cache composer vendor directory.
colinmurphy Jun 6, 2025
1af13c9
Removed cached files.
colinmurphy Jun 6, 2025
05c017f
Updated other actions for composer.
colinmurphy Jun 6, 2025
14587d1
Fixed working directory for plugin artifact.
colinmurphy Jun 6, 2025
459461d
Added missing file.
colinmurphy Jun 6, 2025
a3f4a08
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy Jun 6, 2025
df45c0a
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy Jun 6, 2025
920735e
Refactor settings to make it easier to test.
colinmurphy Jun 9, 2025
eaaa8c8
Added unit tests for fields. Slight refactor. Added some local test s…
colinmurphy Jun 11, 2025
a82a16a
PHPCS and PHPStan fixes.
colinmurphy Jun 11, 2025
7ccbed2
Update .github/actions/codeception/action.yml
colinmurphy Jun 12, 2025
d94c996
Fix psalm issues.
colinmurphy Jun 12, 2025
2df1bb9
Fixed psalm errors.
colinmurphy Jun 12, 2025
946163d
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy Jun 12, 2025
3e0d4b1
Updated workflow to run tests on various WP and PHP versions
colinmurphy Jun 12, 2025
fbcc6ed
Updating WP and PHP versions.
colinmurphy Jun 12, 2025
ac9df2c
Fixes.
colinmurphy Jun 12, 2025
5b7d09c
Relative path fix.
colinmurphy Jun 12, 2025
962ff8b
Fix composer validating issue.
colinmurphy Jun 12, 2025
9a22a06
Fix for codeception failures.
colinmurphy Jun 12, 2025
f6bbf45
Added retries of up to 3 attempts for a failed Docker image.
colinmurphy Jun 12, 2025
02f9285
Fix directory issue.
colinmurphy Jun 12, 2025
1500833
Added docs (generated by Copilot and edited) on the testing setup.
colinmurphy Jun 12, 2025
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
25 changes: 14 additions & 11 deletions .github/actions/code-quality/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ inputs:
working-directory:
description: 'Directory to run composer and quality tools in'
required: true
php-version:
description: 'PHP version to use'
required: false
default: '7.4'
composer-options:
description: 'Additional composer options'
required: false
default: '--no-progress'

runs:
using: "composite"
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:v2
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v2
- name: Setup PHP with Cached Composer
uses: ./.github/actions/setup-php-composer
with:
php-version: ${{ inputs.php-version }}
working-directory: ${{ inputs.working-directory }}
composer-options: "--no-progress"
composer-options: ${{ inputs.composer-options }}

- name: Run PHPStan
working-directory: ${{ inputs.working-directory }}
Expand All @@ -33,4 +36,4 @@ runs:
- name: Run PHP CodeSniffer
working-directory: ${{ inputs.working-directory }}
run: composer run-script check-cs
shell: bash
shell: bash
106 changes: 106 additions & 0 deletions .github/actions/codeception/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: "Run Codeception Tests"
description: "Sets up environment and runs Codeception test suites"
inputs:
working-directory:
description: "Plugin directory to run tests in"
required: true
php:
description: "PHP version"
required: true
extensions:
description: "PHP extensions"
required: true
wordpress:
description: "WordPress version"
required: true
composer-options:
description: "Additional composer options"
required: false
default: "--no-progress"
runs:
using: "composite"
steps:
- name: Setup PHP with Cached Composer
uses: ./.github/actions/setup-php-composer
with:
php-version: ${{ inputs.php }}
working-directory: ${{ inputs.working-directory }}
composer-options: ${{ inputs.composer-options }}

- name: Setup environment
run: |
cp ${{ inputs.working-directory }}/.docker/.env.ci ${{ inputs.working-directory }}/.env
cd ${{ inputs.working-directory }}
echo "INCLUDE_EXTENSIONS=${{ inputs.extensions }}" >> .env
echo "WP_VERSION=${{ inputs.wordpress }}" >> .env
echo "PHP_VERSION=${{ inputs.php }}" >> .env
shell: bash

- name: Build test environment
run: composer run docker:build
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
WP_VERSION: ${{ inputs.wordpress }}
PHP_VERSION: ${{ inputs.php }}

- name: Start test environment
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
docker compose --env-file .env up --detach

CONTAINER_ID=$(docker compose ps -q wordpress)
if [ -n "$CONTAINER_ID" ]; then
docker exec $CONTAINER_ID init-docker.sh
else
echo "Error: WordPress container not found."
exit 1
fi
env:
WP_VERSION: ${{ inputs.wordpress }}
PHP_VERSION: ${{ inputs.php }}

- name: Run Acceptance Tests w/ Docker
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
docker exec \
--env DEBUG=${{ env.DEBUG }} \
--env SKIP_TESTS_CLEANUP=${{ env.SKIP_TESTS_CLEANUP }} \
--env SUITES=acceptance \
$(docker compose ps -q wordpress) \
bash -c "cd wp-content/plugins/$(basename ${{ inputs.working-directory }}) && bin/run-codeception.sh"
env:
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
SKIP_TESTS_CLEANUP: "true"
continue-on-error: true

- name: Run Functional Tests w/ Docker
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
docker exec \
--env DEBUG=${{ env.DEBUG }} \
--env SKIP_TESTS_CLEANUP=${{ env.SKIP_TESTS_CLEANUP }} \
--env SUITES=functional \
$(docker compose ps -q wordpress) \
bash -c "cd wp-content/plugins/$(basename ${{ inputs.working-directory }}) && bin/run-codeception.sh"
env:
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
SKIP_TESTS_CLEANUP: "true"
continue-on-error: true

- name: Run WPUnit Tests w/ Docker
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
docker exec \
--env COVERAGE=${{ inputs.coverage }} \
--env USING_XDEBUG=${{ inputs.coverage }} \
--env DEBUG=${{ env.DEBUG }} \
--env SUITES=wpunit \
$(docker compose ps -q wordpress) \
bash -c "cd wp-content/plugins/$(basename ${{ inputs.working-directory }}) && bin/run-codeception.sh"
env:
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
15 changes: 10 additions & 5 deletions .github/actions/create-plugin-artifact/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ inputs:
slug:
description: 'Plugin slug (directory name under plugins/)'
required: true
composer-options:
description: 'Additional composer options'
required: false
default: '--no-progress'
runs:
using: "composite"
steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
- name: Setup PHP with Cached Composer
uses: ./.github/actions/setup-php-composer
with:
php-version: '7.4'
php-version: ${{ inputs.php }}
working-directory: plugins/${{ inputs.slug }}
composer-options: ${{ inputs.composer-options }}

- name: Install dependencies and build
- name: Create plugin artifact
working-directory: plugins/${{ inputs.slug }}
run: |
composer install --no-dev --optimize-autoloader
echo "${GITHUB_SHA}" > build-sha.txt
rm -f plugin-build/${{ inputs.slug }}-*.zip
composer archive -vvv --format=zip --file="plugin-build/${{ inputs.slug }}" --dir="."
Expand Down
50 changes: 50 additions & 0 deletions .github/actions/setup-php-composer/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Setup PHP with Cached Composer"
description: "Setup PHP and install Composer dependencies with caching"
inputs:
php-version:
description: "PHP version to setup"
required: false
default: "7.4"
working-directory:
description: "Working directory for composer install"
required: true
composer-options:
description: "Additional composer options"
required: false
default: "--no-progress --optimize-autoloader"
tools:
description: "Tools to install with PHP"
required: false
default: "composer:v2"

runs:
using: "composite"
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
tools: ${{ inputs.tools }}
coverage: none

- name: Get Composer cache directory
id: composer-cache
shell: bash
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: |
${{ steps.composer-cache.outputs.dir }}
${{ inputs.working-directory }}/vendor
key: composer-${{ runner.os }}-php${{ inputs.php-version }}-${{ hashFiles(format('{0}/composer.lock', inputs.working-directory)) }}
restore-keys: |
composer-${{ runner.os }}-php${{ inputs.php-version }}-
composer-${{ runner.os }}-

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
working-directory: ${{ inputs.working-directory }}
composer-options: ${{ inputs.composer-options }}
7 changes: 6 additions & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Code Quality

on:
push:
branches:
- main
paths:
- 'plugins/**.php'
pull_request:
paths:
- 'plugins/**'
- 'plugins/**.php'

jobs:
run:
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Codeception

on:
push:
branches:
- main
paths:
- 'plugins/**.php'
pull_request:
paths:
- 'plugins/**.php'

# Cancel previous workflow run groups that have not completed.
concurrency:
# Group workflow runs by workflow name, along with the head branch ref of the pull request
# or otherwise the branch or tag ref.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
continuous_integration:
runs-on: ubuntu-latest
name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}

strategy:
matrix:
# TODO: Add back in once working
# php: ["8.4","8.3","8.2", "8.1", "8.0", "7.4"]
# wordpress: ["6.8","6.7", "6.6", "6.5", "6.4", "6.3", "6.2"]
php: [ "8.2"]
wordpress: [ "6.8" ]
include:
- php: "8.2"
wordpress: "6.8"
coverage: 1
exclude:
# New WP versions that dont support older PHP versions
- php: "8.0"
wordpress: "6.8"
- php: "8.0"
wordpress: "6.7"
- php: "8.0"
wordpress: "6.6"
- php: "8.0"
wordpress: "6.5"
- php: "7.4"
wordpress: "6.8"
- php: "7.4"
wordpress: "6.7"
- php: "7.4"
wordpress: "6.6"
- php: "7.4"
wordpress: "6.5"
fail-fast: false

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

- name: Get changed plugin directory
id: plugin
run: |
git fetch --prune --unshallow
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
echo "slug=$plugin" >> $GITHUB_OUTPUT

- name: Run Codeception Tests
uses: ./.github/actions/codeception
with:
working-directory: plugins/${{ steps.plugin.outputs.slug }}
php: ${{ matrix.php }}
wordpress: ${{ matrix.wordpress }}
extensions: json,mbstring
2 changes: 1 addition & 1 deletion .github/workflows/plugin-artifact-for-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Plugin Artifact for PR
on:
pull_request:
paths:
- 'plugins/**'
- 'plugins/**.php'

jobs:
create-plugin-artifact:
Expand Down
59 changes: 59 additions & 0 deletions plugins/hwp-previews/.docker/.env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
PLUGIN_SLUG=hwp-previews

# Configure these to match your existing testing environment or the one you want to create with Docker.
## Usually, these values should match the ones in the `wp-config.php` file.
## If using Local by Flywheel, you can `open AdminerEvo` and find the values in the URL: `http://localhost:{DB_PORT}/?username={DB_USER}&db={DB_NAME}`
## NOTE: Codeception may modify or the database during testing. If you want to preserve your local data, create a new database and use that for the `DB_NAME`.
DB_NAME=wordpress
DB_HOST=mysql
DB_USER=root
DB_PASSWORD=password
DB_PORT=3306

# The local path to the WordPress root directory, the one containing the wp-load.php file.
## This can be a relative path from the directory that contains the codeception.yml file, or an absolute path.
## If you are using Local by Flywheel, you can find the path in the Local by Flywheel app under the site's settings.
WORDPRESS_ROOT_DIR="/var/www/html"

# This table prefix used by the WordPress site, and in Acceptance tests.
WORDPRESS_TABLE_PREFIX=wp_

# The URL and domain of the WordPress site, and in Acceptance tests.
## If the port is in use, you can change it to a different port.
WORDPRESS_URL=http://localhost
WORDPRESS_DOMAIN=localhost
WORDPRESS_ADMIN_PATH=/wp-admin

# The username and password of the administrator user of the WordPress site, and in Acceptance tests.
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=password
WORDPRESS_ADMIN_EMAIL=[email protected]

# Tests will require a MySQL database to run.
# Do not use a database that contains important data!
WORDPRESS_DB_HOST=${DB_HOST}
WORDPRESS_DB_USER=${DB_USER}
WORDPRESS_DB_PASSWORD=${DB_PASSWORD}
WORDPRESS_DB_NAME=${DB_NAME}
WORDPRESS_DB_PORT=${DB_PORT}

# WPUnit tests will use these variables instead.
# By default this is the same as WordPress
TEST_DB_HOST=${WORDPRESS_DB_HOST}
TEST_DB_USER=${WORDPRESS_DB_USER}
TEST_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}
TEST_DB_NAME=${WORDPRESS_DB_NAME}
TEST_DB_PORT=${WORDPRESS_DB_PORT}
# The Integration suite will use this table prefix for the WordPress tables.
TEST_TABLE_PREFIX=test_

# The DSN used by Acceptance tests.
TEST_DB_DSN="mysql:host=${TEST_DB_HOST};port=${TEST_DB_PORT};dbname=${TEST_DB_NAME}"

# The following variables are used to determine test behavior.

# Include 3rd party plugins (e.g. WooCommerce) in the tests.
# Skips recreating the database before running the tests.
SKIP_DB_CREATE=false
# Skips configuring the WordPress installation
SKIP_WP_SETUP=false
Loading
Loading