Skip to content

Commit

Permalink
Remove WooCommerce as a composer dependency (#813)
Browse files Browse the repository at this point in the history
* Update the Jetpack autoloader dependency, remove WooCommerce as a composer dependency

* Change the test install script to install WooCommerce as a regular plugin instead of copying it from WCPay's vendor folder

* Added some clarifying comments

* Run Travis CI on PRs that don't have "master" as a base branch

* Create database before trying to configure WordPress

* Added WC_VERSION env variable to all jobs

* Tweak Travis config to run on PRs that have feature/* as a base branch

* Downgrade the autoloader back to 1.7.0
  • Loading branch information
Daniel Rey López authored Aug 31, 2020
1 parent 1ce2a3f commit 765a550
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 554 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ stages:
- e2e-testing

env:
- WP_VERSION=latest
- WP_VERSION=latest WC_VERSION=4.3.0

# 2. Also test against these combinations, as listed out explicitly one by one

Expand All @@ -39,14 +39,14 @@ matrix:
include:
- name: "Coding standard check"
php: 7.2
env: WP_VERSION=latest RUN_PHPCS=1
env: WP_VERSION=latest WC_VERSION=4.3.0 RUN_PHPCS=1
stage: test
- php: 7.3
env: WP_VERSION=latest
env: WP_VERSION=latest WC_VERSION=4.3.0
stage: test
- name: "PHP 7.3 unit tests using WordPress nightly"
php: 7.3
env: WP_VERSION=nightly
env: WP_VERSION=nightly WC_VERSION=4.3.0
stage: test
- name: "E2E tests"
stage: e2e-testing
Expand All @@ -61,7 +61,7 @@ before_install:
install:
- npm ci
- composer install
- WCPAY_DIR="/home/travis/build/Automattic/woocommerce-payments/" bash ./bin/install-wp-tests.sh woocommerce_test root '' localhost $WP_VERSION false
- WCPAY_DIR="/home/travis/build/Automattic/woocommerce-payments/" bash ./bin/install-wp-tests.sh woocommerce_test root '' localhost $WP_VERSION $WC_VERSION false

script:
- bash bin/phpunit.sh
Expand All @@ -72,3 +72,4 @@ script:
branches:
only:
- master
- /^feature\/.*$/
106 changes: 43 additions & 63 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

if [ $# -lt 3 ] && [ -z $WCPAY_DIR ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [wc-version] [skip-database-creation]"
exit 1
fi

Expand All @@ -10,7 +10,8 @@ DB_USER=${2-root}
DB_PASS=${3-$MYSQL_ROOT_PASSWORD}
DB_HOST=${4-$WORDPRESS_DB_HOST}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}
WC_VERSION=${6-latest}
SKIP_DB_CREATE=${7-false}

TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
Expand All @@ -25,6 +26,18 @@ download() {
fi
}

wp() {
WORKING_DIR="$PWD"
cd "$WP_CORE_DIR"

if [ ! -d $TMPDIR/wp-cli.phar ]; then
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar "$TMPDIR/wp-cli.phar"
fi
php "$TMPDIR/wp-cli.phar" $@

cd "$WORKING_DIR"
}

if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
WP_BRANCH=${WP_VERSION%\-*}
WP_TESTS_TAG="branches/$WP_BRANCH"
Expand Down Expand Up @@ -54,47 +67,26 @@ fi
set -e

install_wp() {

if [ -d $WP_CORE_DIR ]; then
return;
fi

mkdir -p $WP_CORE_DIR

if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p $TMPDIR/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
mv $TMPDIR/wordpress-nightly/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 $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi
wp core download --version=$WP_VERSION

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

configure_wp() {
WP_SITE_URL="http://local.wordpress.test"

if [[ ! -f "$WP_CORE_DIR/wp-config.php" ]]; then
wp core config --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=$DB_HOST --dbprefix=wptests_
fi
wp core install --url="$WP_SITE_URL" --title="Example" --admin_user=admin --admin_password=password [email protected] --skip-email
}

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
Expand Down Expand Up @@ -155,40 +147,28 @@ install_db() {
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}

install_deps() {
WP_SITE_URL="http://local.wordpress.test"
WORKING_DIR="$PWD"
install_woocommerce() {
WC_INSTALL_EXTRA=''
INSTALLED_WC_VERSION=$(wp plugin get woocommerce --field=version)

# copy WooCommerce files to plugins folder so databases can be created before the tests are run
if [[ ! -d "$WP_CORE_DIR/wp-content/plugins/woocommerce" ]]; then
if [[ ! -d "$WCPAY_DIR/vendor/woocommerce/woocommerce" ]]; then
echo "WooCommerce could not be found, installing composer dependencies..."
# install composer dependencies
cd $WCPAY_DIR
download https://getcomposer.org/composer-stable.phar "$TMPDIR/composer.phar"
php "$TMPDIR/composer.phar" install
if [[ -n $INSTALLED_WC_VERSION ]] && [[ $WC_VERSION == 'latest' ]]; then
# WooCommerce is already installed, we just must update it to the latest stable version
wp plugin update woocommerce
wp plugin activate woocommerce
else
if [[ $INSTALLED_WC_VERSION != $WC_VERSION ]]; then
# WooCommerce is installed but it's the wrong version, overwrite the installed version
WC_INSTALL_EXTRA+=" --force"
fi
cp -r "$WCPAY_DIR/vendor/woocommerce/woocommerce" "$WP_CORE_DIR/wp-content/plugins"
fi

# Set up WordPress and activate WooCommerce using wp-cli
# This is needed to create test databases before tests are run and avoid warnings when running them for the first time
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar "$TMPDIR/wp-cli.phar"

cd "$WP_CORE_DIR"
if [[ ! -f "$WP_CORE_DIR/wp-config.php" ]]; then
php "$TMPDIR/wp-cli.phar" core config --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=$DB_HOST --dbprefix=wptests_ --path=$WP_CORE_DIR --quiet
if [[ $WC_VERSION != 'latest' ]]; then
WC_INSTALL_EXTRA+=" --version=$WC_VERSION"
fi
wp plugin install woocommerce --activate$WC_INSTALL_EXTRA
fi
php "$TMPDIR/wp-cli.phar" core install --url="$WP_SITE_URL" --title="Example" --admin_user=admin --admin_password=password [email protected] --path=$WP_CORE_DIR --skip-email --quiet
php "$TMPDIR/wp-cli.phar" plugin activate woocommerce --path=$WP_CORE_DIR --quiet

# Back to original dir
cd "$WORKING_DIR"
}

install_wp
install_test_suite
install_db
if [[ ! -z $WCPAY_DIR ]]; then
install_deps
fi
configure_wp
install_test_suite
install_woocommerce
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"automattic/jetpack-autoloader": "^1.7.0"
},
"require-dev": {
"woocommerce/woocommerce": "^4.1.0",
"composer/installers": "^1.7.0",
"phpunit/phpunit": "6.5.14",
"woocommerce/woocommerce-sniffs": "0.0.10"
Expand Down
Loading

0 comments on commit 765a550

Please sign in to comment.