Skip to content

Commit

Permalink
[cmsp-679] PHP 8.3 compatibility checks (#135)
Browse files Browse the repository at this point in the history
* add some local test helpers

* let's see where the tests dir lives on ci

* try another thing maybe?

* add a new local phpunit install script and use that

* use the right option

* nocache isn't an option for composer...

* remove the wp dir paths
we don't need them if we're setting TMPDIR

* update the message about where we're installing tests

* use newer versions of phpcompatibility for php8 checks

* add php8 check and add to lint script

* run the php8-check lint in php8.2 tests
the tests run composer phpcs but not composer lint. lint combines phpcs and php8-check so we'll run the php8-check manually

* add new tests for 8.3

* use dev-develop rather than dev-master

* trash all that and use the GH action

* restore line break that i inadvertently removed

* just remove the 8.2 tests
we don't really need to test both things

* update comment

* run a phplint
composer lint is not run, only phpcs, and that's run in a non-php-specific environment, so splitting it out into a separate script and composer lint runs both

* run the phplint script in both the 7.4 and 8.3 tests

* allow any install-wp-tests parameter to be passed in
  • Loading branch information
jazzsequence authored Oct 4, 2023
1 parent 73142f5 commit fa93b95
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 8 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- uses: pantheon-systems/validate-readme-spacing@v1
php8-compatibility:
name: PHP 8.x Compatibility
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: PHP Compatibility
uses: pantheon-systems/phpcompatibility-action@dev
with:
test-versions: 8.0-
paths: ${{ github.workspace }}/*.php ${{ github.workspace }}/inc/*.php
test-phpunit-74:
needs: lint
runs-on: ubuntu-latest
Expand All @@ -54,21 +65,23 @@ jobs:
- name: Install Composer dependencies
run: |
composer update && composer install
- name: Run PHP linting
run: composer phplint
- name: Run PHPUnit
run: bash ./bin/phpunit-test.sh
test-phpunit-82:
test-phpunit-83:
needs: lint
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:10.6
name: PHP 8.2 Unit Tests
name: PHP 8.3 Unit Tests
steps:
- uses: actions/checkout@v3
- name: Setup PHP 8.2
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
extensions: mysqli, zip, imagick
- name: Start MySQL Service
run: sudo systemctl start mysql
Expand All @@ -80,5 +93,7 @@ jobs:
restore-keys: test-phpunit-dependencies-${{ hashFiles('composer.json') }}
- name: Install Composer dependencies
run: composer install
- name: Run PHP linting
run: composer phplint
- name: Run PHPUnit
run: bash ./bin/phpunit-test.sh
61 changes: 61 additions & 0 deletions bin/install-local-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
set -e

# Initialize variables with default values
TMPDIR="/tmp"
DB_NAME="wordpress_test"
DB_USER="root"
DB_PASS=""
DB_HOST="127.0.0.1"
WP_VERSION="latest"
SKIP_DB=""

# Display usage information
usage() {
echo "Usage:"
echo "./install-local-tests.sh [--dbname=wordpress_test] [--dbuser=root] [--dbpass=''] [--dbhost=127.0.0.1] [--wpversion=latest] [--no-db]"
}

# Parse command-line arguments
for i in "$@"
do
case $i in
--dbname=*)
DB_NAME="${i#*=}"
shift
;;
--dbuser=*)
DB_USER="${i#*=}"
shift
;;
--dbpass=*)
DB_PASS="${i#*=}"
shift
;;
--dbhost=*)
DB_HOST="${i#*=}"
shift
;;
--wpversion=*)
WP_VERSION="${i#*=}"
shift
;;
--no-db)
SKIP_DB="true"
shift
;;
*)
# unknown option
usage
exit 1
;;
esac
done

# Run install-wp-tests.sh
echo "Installing local tests into ${TMPDIR}"
bash "$(dirname "$0")/install-wp-tests.sh" "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" "$WP_VERSION" "$SKIP_DB"

# Run PHPUnit
echo "Running PHPUnit"
composer phpunit
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
"prefer-stable": true,
"scripts": {
"lint": [
"@phpcs"
"@phpcs",
"@phplint"
],
"phpcs": "phpcs",
"phpcbf": "phpcbf",
"phpunit": "phpunit",
"test": "@phpunit"
"phplint": "find . -type f -name '*.php' -not -path './vendor/*' -not -path './tests/*' -exec php -l {} \\;",
"phpunit": "phpunit --do-not-cache-result",
"test": "@phpunit",
"test:install": "bin/install-local-tests.sh --no-db",
"test:install:withdb": "bin/install-local-tests.sh"
},
"config": {
"allow-plugins": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa93b95

Please sign in to comment.