Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created November 18, 2022 16:58
Show Gist options
  • Save danielbachhuber/454c165bbc061d094ecc6bf3ec4ec728 to your computer and use it in GitHub Desktop.
Save danielbachhuber/454c165bbc061d094ecc6bf3ec4ec728 to your computer and use it in GitHub Desktop.
diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature
index c2af718d0..76d043b06 100644
--- a/features/install-wp-tests.feature
+++ b/features/install-wp-tests.feature
@@ -32,7 +32,7 @@ Feature: Scaffold install-wp-tests.sh tests
And I try `rm -fr /tmp/behat-wordpress-tests-lib`
And I try `rm -fr /tmp/behat-wordpress`
- When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold wp_cli_test password1 localhost latest`
+ When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh -d wp_cli_test_scaffold -u wp_cli_test -p password1 -h localhost -v latest`
Then the return code should be 0
And the /tmp/behat-wordpress-tests-lib directory should contain:
"""
@@ -84,7 +84,7 @@ Feature: Scaffold install-wp-tests.sh tests
When I run `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist`
Then the return code should be 0
- When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold wp_cli_test password1 localhost latest < affirmative-response`
+ When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh -d wp_cli_test_scaffold -u wp_cli_test -p password1 -h localhost -v latest < affirmative-response`
Then the return code should be 0
And STDERR should contain:
"""
@@ -95,7 +95,7 @@ Feature: Scaffold install-wp-tests.sh tests
Recreated the database (wp_cli_test_scaffold)
"""
- When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold wp_cli_test password1 localhost latest < negative-response`
+ When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh -d wp_cli_test_scaffold -u wp_cli_test -p password1 -h localhost -v latest < negative-response`
Then the return code should be 0
And STDERR should contain:
"""
@@ -116,7 +116,7 @@ Feature: Scaffold install-wp-tests.sh tests
And I try `rm -fr /tmp/behat-wordpress-tests-lib`
And I try `rm -fr /tmp/behat-wordpress`
- When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold wp_cli_test password1 localhost trunk`
+ When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh -d wp_cli_test_scaffold -u wp_cli_test -p password1 -h localhost -v trunk`
Then the return code should be 0
And the /tmp/behat-wordpress-tests-lib directory should contain:
"""
@@ -190,7 +190,7 @@ Feature: Scaffold install-wp-tests.sh tests
And I try `rm -fr /tmp/behat-wordpress-tests-lib`
And I try `rm -fr /tmp/behat-wordpress`
- When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold wp_cli_test password1 localhost 3.7`
+ When I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh -d wp_cli_test_scaffold -u wp_cli_test -p password1 -h localhost -v 3.7`
Then the return code should be 0
And the /tmp/behat-wordpress-tests-lib directory should contain:
"""
diff --git a/features/scaffold-plugin-tests.feature b/features/scaffold-plugin-tests.feature
index e42358d1d..fd354f73a 100644
--- a/features/scaffold-plugin-tests.feature
+++ b/features/scaffold-plugin-tests.feature
@@ -128,17 +128,17 @@ Feature: Scaffold plugin unit tests
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
"""
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
- bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 4.5 $SKIP_DB_CREATE
+ bash bin/install-wp-tests.sh -d wordpress_test -u root -p '' -h 127.0.0.1 -v 4.5 -s $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
- bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest $SKIP_DB_CREATE
+ bash bin/install-wp-tests.sh -d wordpress_test -u root -p '' -h 127.0.0.1 -v latest -s $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
- bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 trunk $SKIP_DB_CREATE
+ bash bin/install-wp-tests.sh -d wordpress_test -u root -p '' -h 127.0.0.1 -v trunk -s $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
diff --git a/features/scaffold-theme-tests.feature b/features/scaffold-theme-tests.feature
index 7168ff2eb..5798037ad 100644
--- a/features/scaffold-theme-tests.feature
+++ b/features/scaffold-theme-tests.feature
@@ -89,7 +89,7 @@ Feature: Scaffold theme unit tests
And I run `MYSQL_PWD=password1 mysql -u wp_cli_test -e "DROP DATABASE IF EXISTS wp_cli_test_scaffold"`
And I try `rm -fr /tmp/behat-wordpress-tests-lib`
And I try `rm -fr /tmp/behat-wordpress`
- And I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress {THEME_DIR}/p2child/bin/install-wp-tests.sh wp_cli_test_scaffold wp_cli_test password1 localhost latest`
+ And I try `WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib WP_CORE_DIR=/tmp/behat-wordpress {THEME_DIR}/p2child/bin/install-wp-tests.sh -d wp_cli_test_scaffold -u wp_cli_test -p password1 -h localhost -v latest`
Then the return code should be 0
When I run `cd {THEME_DIR}/p2child; WP_TESTS_DIR=/tmp/behat-wordpress-tests-lib phpunit`
diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh
index 6ec9130c8..3c42f5f3f 100644
--- a/templates/install-wp-tests.sh
+++ b/templates/install-wp-tests.sh
@@ -1,16 +1,29 @@
#!/usr/bin/env bash
-if [ $# -lt 3 ]; then
- echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
- exit 1
+while getopts d:u:p:h:v:s: option; do
+ case ${option} in
+ d) DB_NAME=${OPTARG};;
+ u) DB_USER=${OPTARG};;
+ p) DB_PASS=${OPTARG};;
+ h) DB_HOST=${OPTARG};;
+ v) WP_VERSION=${OPTARG};;
+ s) SKIP_DB_CREATE=${OPTARG};;
+ esac
+done
+
+if [ -z "${DB_NAME}" ] || [ -z ${DB_USER} ] || [ -z ${DB_PASS} ]; then
+ echo "usage: $0 -d <db-name> -u <db-user> -p <db-pass> -h [db-host] -v [wp-version] -s [skip-database-creation]";
+ exit 1;
fi
-DB_NAME=$1
-DB_USER=$2
-DB_PASS=$3
-DB_HOST=${4-localhost}
-WP_VERSION=${5-latest}
-SKIP_DB_CREATE=${6-false}
+
+
+DB_NAME=${DB_NAME}
+DB_USER=${DB_USER}
+DB_PASS=${DB_PASS}
+DB_HOST=${DB_HOST-localhost}
+WP_VERSION=${WP_VERSION-latest}
+SKIP_DB_CREATE=${SKIP_DB_CREATE-false}
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
diff --git a/templates/plugin-bitbucket.mustache b/templates/plugin-bitbucket.mustache
index bae271745..b6562b6b6 100644
--- a/templates/plugin-bitbucket.mustache
+++ b/templates/plugin-bitbucket.mustache
@@ -27,7 +27,7 @@ pipelines:
- phpunit --version
## Run PHPUnit
- - bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
+ - bash bin/install-wp-tests.sh -d wordpress_tests -u root -p root -h 127.0.0.1 -v latest -s true
- phpunit
services:
- database
@@ -59,7 +59,7 @@ pipelines:
- phpunit --version
## Run PHPUnit
- - bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
+ - bash bin/install-wp-tests.sh -d wordpress_tests -u root -p root -h 127.0.0.1 -v latest -s true
- phpunit
services:
- database
@@ -91,7 +91,7 @@ pipelines:
- phpunit --version
## Run PHPUnit
- - bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
+ - bash bin/install-wp-tests.sh -d wordpress_tests -u root -p root -h 127.0.0.1 -v latest -s true
- phpunit
services:
- database
@@ -123,7 +123,7 @@ pipelines:
- phpunit --version
## Run PHPUnit
- - bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
+ - bash bin/install-wp-tests.sh -d wordpress_tests -u root -p root -h 127.0.0.1 -v latest -s true
- phpunit
services:
- database
diff --git a/templates/plugin-circle.mustache b/templates/plugin-circle.mustache
index ed2b5748f..ce3610465 100644
--- a/templates/plugin-circle.mustache
+++ b/templates/plugin-circle.mustache
@@ -43,7 +43,7 @@ job-references:
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
phpcs
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
- bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
+ bash bin/install-wp-tests.sh -d wordpress_test -u root -p '' -h 127.0.0.1 -v latest
phpunit
WP_MULTISITE=1 phpunit
@@ -67,7 +67,7 @@ jobs:
SKIP_DB_CREATE=false
{{#wp_versions_to_test}}
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
- bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 {{.}} $SKIP_DB_CREATE
+ bash bin/install-wp-tests.sh -d wordpress_test -u root -p '' -h 127.0.0.1 -v {{.}} -s $SKIP_DB_CREATE
phpunit
WP_MULTISITE=1 phpunit
SKIP_DB_CREATE=true
diff --git a/templates/plugin-gitlab.mustache b/templates/plugin-gitlab.mustache
index 78d1f13d1..11e371ef2 100644
--- a/templates/plugin-gitlab.mustache
+++ b/templates/plugin-gitlab.mustache
@@ -17,7 +17,7 @@ before_script:
- docker-php-ext-enable mbstring mcrypt mysqli pdo_mysql intl gd zip bz2
# Set up WordPress tests
- - bash bin/install-wp-tests.sh wordpress_tests root mysql mysql latest true
+ - bash bin/install-wp-tests.sh -d wordpress_tests -u root -p mysql -h mysql -v latest -s true
# Install PHPCS and WPCS
- composer global require "squizlabs/php_codesniffer=*"
diff --git a/templates/plugin-travis.mustache b/templates/plugin-travis.mustache
index 7ec76b953..1d34f019c 100644
--- a/templates/plugin-travis.mustache
+++ b/templates/plugin-travis.mustache
@@ -44,7 +44,7 @@ before_script:
fi
- |
if [[ ! -z "$WP_VERSION" ]] ; then
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
+ bash bin/install-wp-tests.sh -d wordpress_test -u root -p '' -h localhost -v $WP_VERSION
composer global require "phpunit/phpunit=4.8.*|5.7.*"
fi
- |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment