Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
47e83a6
ignore node_modules
aaronjorbin Jul 6, 2023
16f22b0
Change dependencies for development
aaronjorbin Jul 6, 2023
7a71157
Add wp-env for testing and development
aaronjorbin Jul 6, 2023
04b915b
Make tests compatable with yoast pollyfill
aaronjorbin Jul 6, 2023
d488471
Remove vendor files from git
aaronjorbin Jul 6, 2023
faf2892
Ensure composer has been run for the plugin
aaronjorbin Jul 6, 2023
24a9241
restore production dependencies
aaronjorbin Jul 6, 2023
4ea2621
Use version 1.9.1 of Markdown Parser
aaronjorbin Jul 6, 2023
cb183cf
Ignore PHPUNIT results cache
aaronjorbin Jul 6, 2023
81dd58b
add vendor packages
aaronjorbin Jul 6, 2023
1aeb28c
Add test instructions
aaronjorbin Jul 6, 2023
b8d06b3
First pass at phpunit action
aaronjorbin Jul 7, 2023
de44707
Push to any branch should trigger tests
aaronjorbin Jul 7, 2023
f2f4fd8
install node modules during tests
aaronjorbin Jul 7, 2023
01fe461
Use local version of wp-env
aaronjorbin Jul 7, 2023
b61d5a4
properly pass commands to wp-env
aaronjorbin Jul 7, 2023
c4a0bce
Don't activate as an MU plugin during tests
aaronjorbin Jul 7, 2023
65b5142
remove dev-dependencies again
aaronjorbin Jul 7, 2023
4f88e5e
remove PHP watcher
aaronjorbin Jul 7, 2023
100af79
Don't fail fast
aaronjorbin Jul 7, 2023
e9f8f17
Remove all dependencies
aaronjorbin Jul 7, 2023
bf7d015
Don't fail fast
aaronjorbin Jul 7, 2023
83814df
cut down on the matrix until the tests are passing
aaronjorbin Jul 7, 2023
6283099
Use snake case setups
aaronjorbin Jul 7, 2023
7b000a7
Use seperate dependecies for PHP7 and PHP8
aaronjorbin Jul 7, 2023
bcd92a1
Update plugin to work with v4 of Rollbar library
aaronjorbin Jul 10, 2023
7400a1d
Exclude non test files from tests
aaronjorbin Jul 10, 2023
d154c18
Adjust test matrix
aaronjorbin Jul 10, 2023
47ea7e1
Update documentation for test running
aaronjorbin Jul 10, 2023
f3097e9
Update path to rollbar snippit
aaronjorbin Jul 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
123 changes: 123 additions & 0 deletions .github/workflows/php_unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Unit Tests

# Since Unit Tests are required to pass for each PR,
# we cannot disable them for documentation-only changes.
on:
pull_request:
push:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
compute-previous-wordpress-version:
name: Compute previous WordPress version
runs-on: ubuntu-latest
outputs:
previous-wordpress-version: ${{ steps.get-previous-wordpress-version.outputs.previous-wordpress-version }}
latest-wordpress-version: ${{ steps.get-latest-wordpress-version.outputs.latest-wordpress-version }}

steps:
- name: Get latest WordPress version
id: get-latest-wordpress-version
run: |
curl \
-H "Accept: application/json" \
-o versions.json \
"http://api.wordpress.org/core/stable-check/1.0/"
LATEST_WP_VERSION=$(jq --raw-output 'with_entries(select(.value=="latest"))|keys[]' versions.json)
echo "latest-wordpress-version=${LATEST_WP_VERSION}" >> $GITHUB_OUTPUT
rm versions.json
- name: Get previous WordPress version
id: get-previous-wordpress-version
run: |
curl \
-H "Accept: application/json" \
-o versions.json \
"http://api.wordpress.org/core/stable-check/1.0/"
LATEST_WP_VERSION=$(jq --raw-output 'with_entries(select(.value=="latest"))|keys[]' versions.json)
IFS='.' read LATEST_WP_MAJOR LATEST_WP_MINOR LATEST_WP_PATCH <<< "${LATEST_WP_VERSION}"
if [[ ${LATEST_WP_MINOR} == "0" ]]; then
PREVIOUS_WP_SERIES="$((LATEST_WP_MAJOR - 1)).9"
else
PREVIOUS_WP_SERIES="${LATEST_WP_MAJOR}.$((LATEST_WP_MINOR - 1))"
fi
PREVIOUS_WP_VERSION=$(jq --raw-output --arg series "${PREVIOUS_WP_SERIES}" 'with_entries(select(.key|startswith($series)))|keys[-1]' versions.json)
echo "previous-wordpress-version=${PREVIOUS_WP_VERSION}" >> $GITHUB_OUTPUT
rm versions.json

test-php:
name: PHP ${{ matrix.php }}${{ matrix.wordpress != '' && format( ' (WP {0}) ', matrix.wordpress ) || '' }} on ubuntu-latest
needs: compute-previous-wordpress-version
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
wordpress: ["${{needs.compute-previous-wordpress-version.outputs.latest-wordpress-version}}" ] # Latest WordPress version.
include:
# Test with the previous WP version.
- php: '7.0'
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
- php: '7.4'
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
- php: '8.2'
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
# Test with the upcoming WP version.
- php: '7.0'
wordpress: ''
- php: '7.4'
wordpress: ''
- php: '8.2'
wordpress: ''

env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wordpress == '' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wordpress ) }}

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Install Dependencies
run: npm ci

- name: Docker debug information
run: |
docker -v
docker-compose -v

- name: General debug information
run: |
npm --version
node --version
curl --version
git --version
locale -a
echo "PHP version: ${WP_ENV_PHP_VERSION}"
echo "WordPress version: ${WP_ENV_CORE}"

- name: Start Docker environment
run: npm run wp-env start

- name: Log running Docker containers
run: docker ps -a

- name: Running unit tests
run: |
set -o pipefail
npm run test:php
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dwsync.xml
# PHPUnit
phpunit.xml
phpunit.env
.phpunit.result.cache

# PHPCS
phpcs.xml
Expand All @@ -47,4 +48,5 @@ composer.lock
intermediate
.idea
cache
deploy.sh
deploy.sh
node_modules
11 changes: 11 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"core": "WordPress/WordPress",
"plugins": [ "." ],
"env": {
"tests": {
"mappings": {
"wp-content/plugins/rollbar": "."
}
}
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ The original author of this package is [@flowdee](https://twitter.com/flowdee/).

## Testing

The following is Mac/Linux only - Windows is not supported.
In order to run the tests, you will need to install the dependencies for [@wordpress/env](https://www.npmjs.com/package/@wordpress/env) including Node.js, git, and docker.

Before you run tests, provide test database credentials in `phpunit.env` (you can copy `phpunit.env.dist`, removing the comment in the first line). Then start your `mysqld` service.

Tests are in `tests`; to run them, do `composer test`. To fix code style issues, do `composer fix`.
1. npm install
2. npm run test
You can set the `WP_ENV_PHP_VERSION` enviormental variable to test with different versions of PHP. If you are changing the version, you can do so by running `WP_ENV_PHP_VERSION="8.2" npm run wp-env start -- --update` and setting the enviornmental variable based on

## Tagging

Expand Down
127 changes: 0 additions & 127 deletions bin/install-wp-tests.sh

This file was deleted.

22 changes: 22 additions & 0 deletions bin/update-composer-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# Print Commands
set -x

# Exit on error
set -e

# Change to the parent directory of this script
cd "$(dirname "$(dirname "$(readlink -fm "$0")")")"

# restart the container in PHP 7
WP_ENV_PHP_VERSION="7.0" npm run wp-env start -- --update

# install composer dependencies
WP_ENV_PHP_VERSION="7.0" npm run wp-env -- run --env-cwd='wp-content/plugins/rollbar-php-wordpress/php7' tests-cli composer update

# restart the container in PHP 8.0
WP_ENV_PHP_VERSION="8.0" npm run wp-env start -- --update

# install composer dependencies
WP_ENV_PHP_VERSION="8.0" npm run wp-env -- run --env-cwd='wp-content/plugins/rollbar-php-wordpress/php8' tests-cli composer update
22 changes: 15 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
"name": "rollbar/rollbar-php-wordpress",
"description": "WordPress plugin for Rollbar",
"type": "wordpress-plugin",
"require": {
"rollbar/rollbar": "^1",
"phpunit/phpunit": "4.8.*",
"michelf/php-markdown": "*"
"require-dev": {
"yoast/phpunit-polyfills": "^2.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/php-compatibility": "^9.3",
"wp-coding-standards/wpcs": "^2.2",
"sirbrillig/phpcs-variable-analysis": "^2.8"
},
"license": "GNU GPL",
"authors": [
Expand Down Expand Up @@ -36,16 +39,21 @@
},
"extra": {
"scripts-description": {
"test": "Run all tests. Make sure that local Mysql server is running."
"test": "Run all tests. Wrapper around npm run test"
}
},
"scripts": {
"test": [
"@pre-test",
"phpunit --coverage-clover build/logs/clover.xml"
"npm run test"
],
"pre-test": [
"export $(cat phpunit.env | xargs) && bash bin/install-wp-tests.sh $WP_TEST_DB $WP_TEST_USER \"$WP_TEST_PASS\" $WP_TEST_HOST $WP_VERSION || true"
"npm install"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
Loading