Skip to content

Commit d552031

Browse files
authored
Merge pull request #114 from aaronjorbin/fix/unit-tests
Fix unit tests and PHP8.1+ compatability
2 parents 0b547c3 + f3097e9 commit d552031

File tree

2,021 files changed

+59022
-117308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,021 files changed

+59022
-117308
lines changed

.github/workflows/php_unit.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Unit Tests
2+
3+
# Since Unit Tests are required to pass for each PR,
4+
# we cannot disable them for documentation-only changes.
5+
on:
6+
pull_request:
7+
push:
8+
# Allow manually triggering the workflow.
9+
workflow_dispatch:
10+
11+
# Cancels all previous workflow runs for pull requests that have not completed.
12+
concurrency:
13+
# The concurrency group contains the workflow name and the branch name for pull requests
14+
# or the commit hash for any other events.
15+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
compute-previous-wordpress-version:
20+
name: Compute previous WordPress version
21+
runs-on: ubuntu-latest
22+
outputs:
23+
previous-wordpress-version: ${{ steps.get-previous-wordpress-version.outputs.previous-wordpress-version }}
24+
latest-wordpress-version: ${{ steps.get-latest-wordpress-version.outputs.latest-wordpress-version }}
25+
26+
steps:
27+
- name: Get latest WordPress version
28+
id: get-latest-wordpress-version
29+
run: |
30+
curl \
31+
-H "Accept: application/json" \
32+
-o versions.json \
33+
"http://api.wordpress.org/core/stable-check/1.0/"
34+
LATEST_WP_VERSION=$(jq --raw-output 'with_entries(select(.value=="latest"))|keys[]' versions.json)
35+
echo "latest-wordpress-version=${LATEST_WP_VERSION}" >> $GITHUB_OUTPUT
36+
rm versions.json
37+
- name: Get previous WordPress version
38+
id: get-previous-wordpress-version
39+
run: |
40+
curl \
41+
-H "Accept: application/json" \
42+
-o versions.json \
43+
"http://api.wordpress.org/core/stable-check/1.0/"
44+
LATEST_WP_VERSION=$(jq --raw-output 'with_entries(select(.value=="latest"))|keys[]' versions.json)
45+
IFS='.' read LATEST_WP_MAJOR LATEST_WP_MINOR LATEST_WP_PATCH <<< "${LATEST_WP_VERSION}"
46+
if [[ ${LATEST_WP_MINOR} == "0" ]]; then
47+
PREVIOUS_WP_SERIES="$((LATEST_WP_MAJOR - 1)).9"
48+
else
49+
PREVIOUS_WP_SERIES="${LATEST_WP_MAJOR}.$((LATEST_WP_MINOR - 1))"
50+
fi
51+
PREVIOUS_WP_VERSION=$(jq --raw-output --arg series "${PREVIOUS_WP_SERIES}" 'with_entries(select(.key|startswith($series)))|keys[-1]' versions.json)
52+
echo "previous-wordpress-version=${PREVIOUS_WP_VERSION}" >> $GITHUB_OUTPUT
53+
rm versions.json
54+
55+
test-php:
56+
name: PHP ${{ matrix.php }}${{ matrix.wordpress != '' && format( ' (WP {0}) ', matrix.wordpress ) || '' }} on ubuntu-latest
57+
needs: compute-previous-wordpress-version
58+
runs-on: ubuntu-latest
59+
timeout-minutes: 20
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
php:
64+
- '7.0'
65+
- '7.1'
66+
- '7.2'
67+
- '7.3'
68+
- '7.4'
69+
- '8.0'
70+
- '8.1'
71+
- '8.2'
72+
wordpress: ["${{needs.compute-previous-wordpress-version.outputs.latest-wordpress-version}}" ] # Latest WordPress version.
73+
include:
74+
# Test with the previous WP version.
75+
- php: '7.0'
76+
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
77+
- php: '7.4'
78+
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
79+
- php: '8.2'
80+
wordpress: ${{ needs.compute-previous-wordpress-version.outputs.previous-wordpress-version }}
81+
# Test with the upcoming WP version.
82+
- php: '7.0'
83+
wordpress: ''
84+
- php: '7.4'
85+
wordpress: ''
86+
- php: '8.2'
87+
wordpress: ''
88+
89+
env:
90+
WP_ENV_PHP_VERSION: ${{ matrix.php }}
91+
WP_ENV_CORE: ${{ matrix.wordpress == '' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wordpress ) }}
92+
93+
steps:
94+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
95+
96+
- name: Install Dependencies
97+
run: npm ci
98+
99+
- name: Docker debug information
100+
run: |
101+
docker -v
102+
docker-compose -v
103+
104+
- name: General debug information
105+
run: |
106+
npm --version
107+
node --version
108+
curl --version
109+
git --version
110+
locale -a
111+
echo "PHP version: ${WP_ENV_PHP_VERSION}"
112+
echo "WordPress version: ${WP_ENV_CORE}"
113+
114+
- name: Start Docker environment
115+
run: npm run wp-env start
116+
117+
- name: Log running Docker containers
118+
run: docker ps -a
119+
120+
- name: Running unit tests
121+
run: |
122+
set -o pipefail
123+
npm run test:php

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dwsync.xml
3333
# PHPUnit
3434
phpunit.xml
3535
phpunit.env
36+
.phpunit.result.cache
3637

3738
# PHPCS
3839
phpcs.xml
@@ -47,4 +48,5 @@ composer.lock
4748
intermediate
4849
.idea
4950
cache
50-
deploy.sh
51+
deploy.sh
52+
node_modules

.wp-env.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"core": "WordPress/WordPress",
3+
"plugins": [ "." ],
4+
"env": {
5+
"tests": {
6+
"mappings": {
7+
"wp-content/plugins/rollbar": "."
8+
}
9+
}
10+
}
11+
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ The original author of this package is [@flowdee](https://twitter.com/flowdee/).
7575

7676
## Testing
7777

78-
The following is Mac/Linux only - Windows is not supported.
78+
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.
7979

80-
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.
81-
82-
Tests are in `tests`; to run them, do `composer test`. To fix code style issues, do `composer fix`.
80+
1. npm install
81+
2. npm run test
82+
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
8383

8484
## Tagging
8585

bin/install-wp-tests.sh

Lines changed: 0 additions & 127 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# Print Commands
4+
set -x
5+
6+
# Exit on error
7+
set -e
8+
9+
# Change to the parent directory of this script
10+
cd "$(dirname "$(dirname "$(readlink -fm "$0")")")"
11+
12+
# restart the container in PHP 7
13+
WP_ENV_PHP_VERSION="7.0" npm run wp-env start -- --update
14+
15+
# install composer dependencies
16+
WP_ENV_PHP_VERSION="7.0" npm run wp-env -- run --env-cwd='wp-content/plugins/rollbar-php-wordpress/php7' tests-cli composer update
17+
18+
# restart the container in PHP 8.0
19+
WP_ENV_PHP_VERSION="8.0" npm run wp-env start -- --update
20+
21+
# install composer dependencies
22+
WP_ENV_PHP_VERSION="8.0" npm run wp-env -- run --env-cwd='wp-content/plugins/rollbar-php-wordpress/php8' tests-cli composer update

composer.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
"name": "rollbar/rollbar-php-wordpress",
33
"description": "WordPress plugin for Rollbar",
44
"type": "wordpress-plugin",
5-
"require": {
6-
"rollbar/rollbar": "^1",
7-
"phpunit/phpunit": "4.8.*",
8-
"michelf/php-markdown": "*"
5+
"require-dev": {
6+
"yoast/phpunit-polyfills": "^2.0",
7+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
8+
"squizlabs/php_codesniffer": "^3.5",
9+
"phpcompatibility/php-compatibility": "^9.3",
10+
"wp-coding-standards/wpcs": "^2.2",
11+
"sirbrillig/phpcs-variable-analysis": "^2.8"
912
},
1013
"license": "GNU GPL",
1114
"authors": [
@@ -36,16 +39,21 @@
3639
},
3740
"extra": {
3841
"scripts-description": {
39-
"test": "Run all tests. Make sure that local Mysql server is running."
42+
"test": "Run all tests. Wrapper around npm run test"
4043
}
4144
},
4245
"scripts": {
4346
"test": [
4447
"@pre-test",
45-
"phpunit --coverage-clover build/logs/clover.xml"
48+
"npm run test"
4649
],
4750
"pre-test": [
48-
"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"
51+
"npm install"
4952
]
53+
},
54+
"config": {
55+
"allow-plugins": {
56+
"dealerdirect/phpcodesniffer-composer-installer": true
57+
}
5058
}
5159
}

0 commit comments

Comments
 (0)