-
Notifications
You must be signed in to change notification settings - Fork 2
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
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 b402f05
Removed Post_Data_Model class as not used anymore.
colinmurphy 77ae3dd
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy 9ce7e07
Initial setup of testing framework.
colinmurphy 4910d38
Modified workflow to fix working directory issue.
colinmurphy fd7b00c
Moved codeception into its own action.
colinmurphy d2417aa
Updated path for the codeception action.
colinmurphy 9c387c0
Fixing action to get it working.
colinmurphy f41a5fa
Fixed path.
colinmurphy b9dc66a
Added missing step to get plugin directory.
colinmurphy 4167311
Fixed variable for working directory to include plugins.
colinmurphy f5d3b54
Updating action. Not complete.
colinmurphy 05e30c4
Updated workflow.
colinmurphy aaa3442
Fixed workflow.
colinmurphy bbbc9e4
Added .env.ci file
colinmurphy 00501ab
Added missing install plugins script.
colinmurphy e949af5
Only install npm if it exists.
colinmurphy 85c2210
Added tests.
colinmurphy 86b4a38
Added codeception config file.
colinmurphy 96881aa
Added missing dev packages for composer.
colinmurphy faebbea
Fixes for tests
colinmurphy 75615de
Added codeception build.
colinmurphy a5cc643
Trying to cache composer vendor directory.
colinmurphy 1af13c9
Removed cached files.
colinmurphy 05c017f
Updated other actions for composer.
colinmurphy 14587d1
Fixed working directory for plugin artifact.
colinmurphy 459461d
Added missing file.
colinmurphy a3f4a08
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy df45c0a
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy 920735e
Refactor settings to make it easier to test.
colinmurphy eaaa8c8
Added unit tests for fields. Slight refactor. Added some local test s…
colinmurphy a82a16a
PHPCS and PHPStan fixes.
colinmurphy 7ccbed2
Update .github/actions/codeception/action.yml
colinmurphy d94c996
Fix psalm issues.
colinmurphy 2df1bb9
Fixed psalm errors.
colinmurphy 946163d
Merge branch 'main' into chore-add-phpunit-tests
colinmurphy 3e0d4b1
Updated workflow to run tests on various WP and PHP versions
colinmurphy fbcc6ed
Updating WP and PHP versions.
colinmurphy ac9df2c
Fixes.
colinmurphy 5b7d09c
Relative path fix.
colinmurphy 962ff8b
Fix composer validating issue.
colinmurphy 9a22a06
Fix for codeception failures.
colinmurphy f6bbf45
Added retries of up to 3 attempts for a failed Docker image.
colinmurphy 02f9285
Fix directory issue.
colinmurphy 1500833
Added docs (generated by Copilot and edited) on the testing setup.
colinmurphy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.