Skip to content

Commit

Permalink
[CMSP-678]: PHP 8.3 compatibility and code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rwagner00 authored Oct 13, 2023
1 parent 60030f5 commit 1771ca4
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 122 deletions.
64 changes: 0 additions & 64 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ workflows:
main:
jobs:
- test-behat
- test-phpunit-74
- test-phpunit-82
nightly:
triggers:
- schedule:
Expand Down Expand Up @@ -83,66 +81,4 @@ jobs:
- run:
command: ./bin/behat-cleanup.sh
when: always
test-phpunit-74:
resource_class: small
working_directory: ~/pantheon-systems/wp-native-php-sessions
docker:
- image: circleci/php:7.4-node-browsers
- image: cimg/mariadb:10.3
environment:
- WP_TESTS_DIR: "/tmp/wordpress-tests-lib"
- WP_CORE_DIR: "/tmp/wordpress/"
steps:
- checkout
- restore_cache:
keys:
- test-phpunit-74-dependencies-{{ checksum "composer.json" }}
- run: composer update && composer install -n --prefer-dist
- save_cache:
key: test-phpunit-74-dependencies-{{ checksum "composer.json" }}
paths:
- vendor
- run:
name: "Install Extras"
command: |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
sudo apt-get update
sudo apt-get install subversion
sudo apt-get install -y libmagickwand-dev --no-install-recommends
yes '' | sudo pecl install imagick || true
sudo docker-php-ext-enable imagick
sudo docker-php-ext-install mysqli
sudo apt-get install mariadb-client-10.5
- run_test

test-phpunit-82:
resource_class: small
working_directory: ~/pantheon-systems/wp-native-php-sessions
docker:
- image: cimg/php:8.2.0
- image: cimg/mariadb:10.3
environment:
- WP_TESTS_DIR: "/tmp/wordpress-tests-lib"
- WP_CORE_DIR: "/tmp/wordpress/"
steps:
- checkout
- restore_cache:
keys:
- test-phpunit-82-dependencies-{{ checksum "composer.json" }}
- run: composer install -n --prefer-dist
- save_cache:
key: test-phpunit-82-dependencies-{{ checksum "composer.json" }}
paths:
- vendor
- run:
name: "Install Extras"
command: |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
sudo apt-get update
sudo apt-get install subversion
sudo apt-get install -y libmagickwand-dev --no-install-recommends
yes '' | sudo pecl install imagick || true
sudo docker-php-ext-enable imagick
sudo docker-php-ext-install mysqli
sudo apt-get install mariadb-client-10.6
- run_test
74 changes: 73 additions & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,76 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: pantheon-systems/validate-readme-spacing@v1
- uses: pantheon-systems/validate-readme-spacing@v1
lint:
name: PHPCS Linting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/vendor
key: test-lint-dependencies-{{ checksum "composer.json" }}
restore-keys: test-lint-dependencies-{{ checksum "composer.json" }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
- name: Install dependencies
run: composer install -n --prefer-dist
- name: Run PHPCS
run: composer lint
php8-compatibility:
name: PHP 8.x Compatibility
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: pantheon-systems/phpcompatibility-action@dev
with:
paths: ${{ github.workspace }}/*.php ${{ github.workspace }}/inc/*.php
test-versions: 8.0-
wporg-validation:
name: WP.org Plugin Validation
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: pantheon-systems/[email protected]
with:
type: 'plugin'
test:
needs: lint
name: Test
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:10.5
strategy:
matrix:
php_version: [7.4, 8.2, 8.3]
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: mysqli, zip, imagick
- name: Start MySQL Service
run: sudo systemctl start mysql
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/vendor
key: test-dependencies-{{ checksum "composer.json" }}
restore-keys: test-dependencies-{{ checksum "composer.json" }}
- name: Install dependencies
run: |
if [ ${{ matrix.php_version }} = "7.4" ]; then
composer update
fi
composer install
- name: Run PHPUnit
run: bash ./bin/phpunit-test.sh
14 changes: 14 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Shellcheck
on:
push:
paths:
- 'bin/*.sh'
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Shellcheck
run: find bin/ -name "*.sh" | grep -v "install-wp-tests.sh" | xargs shellcheck
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Adds a WP-CLI command to add an index to the sessions table if one does not exis
* Adds new CLI command to add a Primary Column (id) to the `pantheon_sessions` table for users who do not have one. [[#265](https://github.com/pantheon-systems/wp-native-php-sessions/pull/265)]
* Adds alert to dashboard for users who need to run the new command.
* Updates Pantheon WP Coding Standards to 2.0 [[#264](https://github.com/pantheon-systems/wp-native-php-sessions/pull/264)]
* 8.3 compatibility and code quality updates

### 1.3.6 (June 1, 2023) ###
* Fixes PHP 8.2 deprecated dynamic property error [[#251](https://github.com/pantheon-systems/wp-native-php-sessions/pull/251)] (props @miguelaxcar)
Expand Down
8 changes: 1 addition & 7 deletions bin/behat-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
# Delete the Pantheon site environment after the Behat test suite has run.
###

terminus whoami > /dev/null
if [ $? -ne 0 ]; then
echo "Terminus unauthenticated; assuming unauthenticated build"
exit 0
fi

if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then
echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set"
exit 1
Expand All @@ -25,4 +19,4 @@ set -ex
###
# Delete the environment used for this test run.
###
terminus multidev:delete $SITE_ENV --delete-branch --yes
terminus multidev:delete "$SITE_ENV" --delete-branch --yes
42 changes: 18 additions & 24 deletions bin/behat-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
# such that it can be run a second time if a step fails.
###

terminus whoami > /dev/null
if [ $? -ne 0 ]; then
echo "Terminus unauthenticated; assuming unauthenticated build"
exit 0
fi

if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then
echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set"
exit 1
Expand All @@ -27,58 +21,58 @@ set -ex
###
# Create a new environment for this particular test run.
###
terminus env:create $TERMINUS_SITE.dev $TERMINUS_ENV
terminus env:wipe $SITE_ENV --yes
terminus env:create "${TERMINUS_SITE}.dev" "$TERMINUS_ENV"
terminus env:wipe "$SITE_ENV" --yes

###
# Get all necessary environment details.
###
PANTHEON_GIT_URL=$(terminus connection:info $SITE_ENV --field=git_url)
PANTHEON_GIT_URL=$(terminus connection:info "$SITE_ENV" --field=git_url)
PANTHEON_SITE_URL="$TERMINUS_ENV-$TERMINUS_SITE.pantheonsite.io"
PREPARE_DIR="/tmp/$TERMINUS_ENV-$TERMINUS_SITE"
BASH_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

###
# Switch to git mode for pushing the files up
###
terminus connection:set $SITE_ENV git
rm -rf $PREPARE_DIR
git clone -b $TERMINUS_ENV $PANTHEON_GIT_URL $PREPARE_DIR
terminus connection:set "$SITE_ENV" git
rm -rf "$PREPARE_DIR"
git clone -b "$TERMINUS_ENV" "$PANTHEON_GIT_URL" "$PREPARE_DIR"

###
# Add the copy of this plugin itself to the environment
###
rm -rf $PREPARE_DIR/wp-content/plugins/wp-native-php-sessions
cd $BASH_DIR/..
rsync -av --exclude='vendor/' --exclude='node_modules/' --exclude='tests/' ./* $PREPARE_DIR/wp-content/plugins/wp-native-php-sessions
rm -rf $PREPARE_DIR/wp-content/plugins/wp-native-php-sessions/.git
rm -rf "$PREPARE_DIR"/wp-content/plugins/wp-native-php-sessions
cd "$BASH_DIR"/..
rsync -av --exclude='vendor/' --exclude='node_modules/' --exclude='tests/' ./* "$PREPARE_DIR"/wp-content/plugins/wp-native-php-sessions
rm -rf "$PREPARE_DIR"/wp-content/plugins/wp-native-php-sessions/.git

###
# Add the debugging plugin to the environment
###
rm -rf $PREPARE_DIR/wp-content/mu-plugins/sessions-debug.php
cp $BASH_DIR/fixtures/sessions-debug.php $PREPARE_DIR/wp-content/mu-plugins/sessions-debug.php
rm -rf "$PREPARE_DIR"/wp-content/mu-plugins/sessions-debug.php
cp "$BASH_DIR"/fixtures/sessions-debug.php "$PREPARE_DIR"/wp-content/mu-plugins/sessions-debug.php

###
# Push files to the environment
###
cd $PREPARE_DIR
cd "$PREPARE_DIR"
git add wp-content
git config user.email "[email protected]"
git config user.name "Pantheon"
git commit -m "Include WP Native PHP Sessions and its configuration files"
git push

# Sometimes Pantheon takes a little time to refresh the filesystem
terminus build:workflow:wait $TERMINUS_SITE.$TERMINUS_ENV
terminus build:workflow:wait "$TERMINUS_SITE"."$TERMINUS_ENV"

###
# Set up WordPress, theme, and plugins for the test run
###
# Silence output so as not to show the password.
{
terminus wp $SITE_ENV -- core install --title=$TERMINUS_ENV-$TERMINUS_SITE --url=$PANTHEON_SITE_URL --admin_user=$WORDPRESS_ADMIN_USERNAME [email protected] --admin_password=$WORDPRESS_ADMIN_PASSWORD
terminus wp "$SITE_ENV" -- core install --title="$TERMINUS_ENV"-"$TERMINUS_SITE" --url="$PANTHEON_SITE_URL" --admin_user="$WORDPRESS_ADMIN_USERNAME" [email protected] --admin_password="$WORDPRESS_ADMIN_PASSWORD"
} &> /dev/null
terminus wp $SITE_ENV -- plugin activate wp-native-php-sessions
terminus wp $SITE_ENV -- theme activate twentytwentythree
terminus wp $SITE_ENV -- rewrite structure '/%year%/%monthnum%/%day%/%postname%/'
terminus wp "$SITE_ENV" -- plugin activate wp-native-php-sessions
terminus wp "$SITE_ENV" -- theme activate twentytwentythree
terminus wp "$SITE_ENV" -- rewrite structure '/%year%/%monthnum%/%day%/%postname%/'
6 changes: 0 additions & 6 deletions bin/behat-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
# Execute the Behat test suite against a prepared Pantheon site environment.
###

terminus whoami > /dev/null
if [ $? -ne 0 ]; then
echo "Terminus unauthenticated; assuming unauthenticated build"
exit 0
fi

if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then
echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set"
exit 1
Expand Down
4 changes: 2 additions & 2 deletions bin/fixtures/sessions-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
return;
}
session_start();
echo "(" . $_GET['key'] . ':' . $_SESSION[ $_GET['key'] ] . ")";
echo "(" . esc_html($_GET['key']) . ':' . esc_html( $_SESSION[ $_GET['key'] ] ) . ")"; // guardrails-disable-line
exit;
});

Expand Down Expand Up @@ -44,7 +44,7 @@
global $wpdb;
$results = $wpdb->get_results( "SELECT user_id,data FROM {$wpdb->pantheon_sessions}" );
foreach( $results as $result ) {
echo $result->user_id . '-' . $result->data . PHP_EOL;
echo esc_html($result->user_id) . '-' . esc_html($result->data) . PHP_EOL;
}
exit;
});
Expand Down
14 changes: 7 additions & 7 deletions bin/full-teardown-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}

file_delete() {
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
rm -rf "$WP_TESTS_DIR" "$WP_CORE_DIR"
}

drop_db() {

# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local PARTS=("${DB_HOST//\:/ }")
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
if [ -n "$DB_HOSTNAME" ] ; then
if echo "$DB_SOCK_OR_PORT" | grep -q -e '^[0-9]\{1,\}$'; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
elif [ -n "$DB_SOCK_OR_PORT" ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
elif [ -n "$DB_HOSTNAME" ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi

# create database
echo Y | mysqladmin drop $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
echo Y | mysqladmin drop "$DB_NAME" --user="$DB_USER" --password="$DB_PASS""$EXTRA"
}

file_delete
Expand Down
Loading

0 comments on commit 1771ca4

Please sign in to comment.