Skip to content
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

Development #846

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f3dfdfe
Sync branch [skip ci]
pirate-bot Sep 11, 2024
40a7cba
Sync branch [skip ci]
pirate-bot Sep 11, 2024
ed18909
ci: disable php memory limit when running phpcs or phpstan
carlalexander Sep 13, 2024
d2f7fe3
ci: remove references to phplint and rename to phpcs
carlalexander Sep 13, 2024
9d54bb5
ci: mention the php version being used for workflows that don't use a…
carlalexander Sep 13, 2024
12e203e
style: update code block to say php 7.4
carlalexander Sep 13, 2024
b69b376
ci: switch to `actions/checkout@v4`
carlalexander Sep 13, 2024
0a05de5
ci: remove caching composer directory
carlalexander Sep 13, 2024
2231d1f
style: mention the step installs dependencies
carlalexander Sep 13, 2024
7c10de2
ci: update phpunit workflow to match wp-cli generated workflow
carlalexander Sep 13, 2024
dad4b3b
Merge pull request #836 from Codeinwp/testing-improvements
selul Sep 24, 2024
3dc19f4
ci: switch to using composer script to install wordpress tests
carlalexander Sep 25, 2024
f530260
ci: update `install-wp-tests.sh` to match wp-cli generated script
carlalexander Sep 25, 2024
72cd6ef
style: add some spacing between `if` conditions
carlalexander Sep 26, 2024
bed19e9
test: fix `if` condition so that it doesn't rely on an environment va…
carlalexander Sep 26, 2024
96a6b63
ci: ensure that we have subversion installed for phpunit tests
carlalexander Sep 26, 2024
2ad1f8b
ci: switch to using a composer script to run unit tests
carlalexander Sep 26, 2024
370bdad
style: clean up the bootstrap file
carlalexander Sep 27, 2024
f8e3fbb
test: fix issue where test broke if you ran phpunit from the project …
carlalexander Sep 27, 2024
bb4b6b1
test: fix `development.php` to also return if we run a test as a sepa…
carlalexander Sep 27, 2024
7b7a032
ci: switch to installing dev dependencies for phpunit tests
carlalexander Sep 27, 2024
f69f5df
Merge pull request #839 from Codeinwp/fix-local-tests
selul Oct 1, 2024
63118cc
build(deps): bump codeinwp/themeisle-sdk from 3.3.30 to 3.3.32
dependabot[bot] Oct 21, 2024
9dd9305
add fix for edge cases when user_data has missing format
selul Oct 22, 2024
32e0464
Merge pull request #845 from Codeinwp/dependabot/composer/development…
selul Oct 22, 2024
fa8fd31
fix lint
selul Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 25 additions & 53 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ concurrency:
cancel-in-progress: true
jobs:
phplint:
name: Phplint
name: PHPCS on PHP 8.0
runs-on: ubuntu-latest
steps:
- name: Setup PHP version
Expand All @@ -17,62 +17,45 @@ jobs:
php-version: '8.0'
extensions: simplexml
- name: Checkout source code
uses: actions/checkout@v2
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer
uses: actions/checkout@v4
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run PHPCS
run: composer run lint
run: composer phpcs
phpunit:
name: Phpunit
name: PHPUnit tests on ${{ matrix.php-versions }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
services:
mysql:
image: mysql:5.7
database:
image: mysql:latest
env:
MYSQL_DATABASE: wordpress_tests
MYSQL_ROOT_PASSWORD: root
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
- 3306:3306
steps:
- name: Setup PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: ${{ matrix.php-version }}
extensions: simplexml, mysql
tools: phpunit-polyfills
tools: phpunit-polyfills:1.1
- name: Install Subversion
run: sudo apt-get update && sudo apt-get install -y subversion
- name: Checkout source code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install WordPress Test Suite
run: |
bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer
run: composer install --prefer-dist --no-progress --no-suggest --no-dev
run: composer install-wp-tests
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run phpunit
run: phpunit
run: composer phpunit
phpstan:
name: PHPStan
name: PHPStan on PHP 8.0
runs-on: ubuntu-latest
steps:
- name: Setup PHP version
Expand All @@ -81,19 +64,8 @@ jobs:
php-version: '8.0'
extensions: simplexml, mysql
- name: Checkout source code
uses: actions/checkout@v2
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer
uses: actions/checkout@v4
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: PHPStan Static Analysis
run: composer phpstan
6 changes: 3 additions & 3 deletions assets/src/dashboard/parts/connected/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ if ( 'undefined' !== typeof window && optimoleDashboardApp.user_data.plan ) {
status: optimoleDashboardApp.user_data.status,
language: optimoleDashboardApp.language,
cname_assigned: optimoleDashboardApp.user_data.is_cname_assigned || 'no',
connected_websites: optimoleDashboardApp.user_data.whitelist.length.toString(),
traffic: convertToCategory( optimoleDashboardApp.user_data.traffic, 500 ).toString(),
images_number: convertToCategory( optimoleDashboardApp.user_data.images_number, 100 ).toString(),
connected_websites: optimoleDashboardApp.user_data.whitelist && optimoleDashboardApp.user_data.whitelist.length.toString(),
traffic: convertToCategory( optimoleDashboardApp.user_data.traffic || 0, 500 ).toString(),
images_number: convertToCategory( optimoleDashboardApp.user_data.images_number || 0, 100 ).toString(),
days_since_install: convertToCategory( optimoleDashboardApp.days_since_install ).toString()
}
});
Expand Down
112 changes: 88 additions & 24 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,43 @@ DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}

WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress}

command_exists() {
type -t "$1" >/dev/null 2>&1
}
download() {
if command_exists "curl"; then
curl -s -o "${2:--}" "$1"
elif command_exists "wget"; then
wget -nv -O "${2:--}" "$1"
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
else
echo "Error: Neither curl nor wget is installed."
exit 1
fi
}
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
WP_TESTS_TAG="tags/$WP_VERSION"

# Check if svn is installed
check_svn_installed() {
if ! command -v svn > /dev/null; then
echo "Error: svn is not installed. Please install svn and try again."
exit 1
fi
}

if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
WP_BRANCH=${WP_VERSION%\-*}
WP_TESTS_TAG="branches/$WP_BRANCH"

elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
WP_TESTS_TAG="tags/${WP_VERSION%??}"
else
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
Expand All @@ -40,10 +62,8 @@ else
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi

set -ex


install_wp() {

if [ -d $WP_CORE_DIR ]; then
Expand All @@ -53,27 +73,44 @@ install_wp() {
mkdir -p $WP_CORE_DIR

if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p /tmp/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
mkdir -p $TMPDIR/wordpress-trunk
rm -rf $TMPDIR/wordpress-trunk/*
check_svn_installed
svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR/wordpress-trunk/wordpress
mv $TMPDIR/wordpress-trunk/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
# https serves multiple offers, whereas http serves single.
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
LATEST_VERSION=${WP_VERSION%??}
else
# otherwise, scan the releases and get the most up to date minor version of the major release
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
fi
if [[ -z "$LATEST_VERSION" ]]; then
local ARCHIVE_NAME="wordpress-$WP_VERSION"
else
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
fi
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi

download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
local ioption='-i.bak'
else
local ioption='-i'
fi
Expand All @@ -82,15 +119,18 @@ install_test_suite() {
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
rm -rf $WP_TESTS_DIR/{includes,data}
check_svn_installed
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s:__DIR__ . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
Expand All @@ -99,6 +139,23 @@ install_test_suite() {

}

recreate_db() {
shopt -s nocasematch
if [[ $1 =~ ^(y|yes)$ ]]
then
mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA
create_db
echo "Recreated the database ($DB_NAME)."
else
echo "Leaving the existing database ($DB_NAME) in place."
fi
shopt -u nocasematch
}

create_db() {
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}

install_db() {

if [ ${SKIP_DB_CREATE} = "true" ]; then
Expand All @@ -122,7 +179,14 @@ install_db() {
fi

# create database
mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute "CREATE DATABASE IF NOT EXISTS $DB_NAME;"
if [ $(mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ]
then
echo "Reinstalling will delete the existing test database ($DB_NAME)"
read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB
recreate_db $DELETE_EXISTING_DB
else
create_db
fi
}

install_wp
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml --report-summary --report-source",
"phpcs": "phpcs --standard=phpcs.xml --extensions=php -s",
"test": "[ -z \"$WP_TESTS_DIR\" ] || [ -z \"$WP_CORE_DIR\" ] && echo 'Error: Both WP_TESTS_DIR and WP_CORE_DIR must be defined.' && exit 1 || phpunit --configuration=phpunit.xml",
"lint": "composer run-script phpcs",
"phpstan": "phpstan analyse --memory-limit 2G",
"install-wp-tests": "bash bin/install-wp-tests.sh wordpress_test root '' localhost latest"
"phpcs": "phpcs --standard=phpcs.xml --extensions=php -s -d memory_limit=-1",
"phpstan": "phpstan analyse --memory-limit=-1",
"phpunit": "phpunit --configuration=phpunit.xml",
"install-wp-tests": "bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true"
},
"require": {
"php": ">=7.4",
Expand Down
15 changes: 8 additions & 7 deletions composer.lock

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

12 changes: 11 additions & 1 deletion development.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
*
* @package ThemeIsle
*/
if ( ! empty( getenv( 'WP_TESTS_DIR' ) ) ) {

// This condition tries to detect if we're running PHPUnit. This is complex because the file is loaded via the
// composer autoloader. You can detect that 99% of the time because PHPUnit uses the constant
// PHPUNIT_COMPOSER_INSTALL to load the autoloader. That said, if you run a test in a separate process, it won't
// run that code again and the constant doesn't exist. As a fallback, we use the PHPUNIT_RUNNING environment variable
// defined in the phpunit.xml to detect if we're in a PHPUnit process. We can't always use the environment variable
// because by default PHPUnit loads the composer autoloader before it assigns those environment variables. That's
// why both conditions are needed.
if ( defined( 'PHPUNIT_COMPOSER_INSTALL' ) || getenv( 'PHPUNIT_RUNNING' ) ) {
return;
}

if ( ! defined( 'ENABLE_OPTIMOLE_WP_DEV' ) ) {
define( 'ENABLE_OPTIMOLE_WP_DEV', true );
}

if ( ENABLE_OPTIMOLE_WP_DEV ) {
$optiml_constants = [
'OPTIML_API_ROOT' => 'https://staging-dashboard.optimole.com/api/',
Expand Down
2 changes: 1 addition & 1 deletion optimole-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function optml_deactivate() {
}

/**
* Shows a notice for sites running PHP less than 5.4.
* Shows a notice for sites running PHP less than 7.4.
*/
function optml_php_notice() {
?>
Expand Down
Loading
Loading