From ce8d6359268f405489606bdc51ffc6bfe980aad7 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 24 Jan 2022 20:22:02 -0600 Subject: [PATCH 1/8] Allow for diverging PHPUnit version specifics in tests --- features/install-wp-tests.feature | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index 89050f6a..e92b360e 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -219,7 +219,15 @@ Feature: Scaffold install-wp-tests.sh tests Then the return code should be 1 And STDOUT should contain: """ - Looks like you're using PHPUnit 9.5.8. WordPress requires at least PHPUnit 5.4 and is currently only compatible with PHPUnit up to 7.x. + Looks like you're using PHPUnit 9.5. + """ + And STDOUT should contain: + """ + WordPress requires at least PHPUnit 5. + """ + And STDOUT should contain: + """ + and is currently only compatible with PHPUnit up to 7.x. """ When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < affirmative-response` From 166f83564e8d9f4da15ca44c849bb0b8531af4b3 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 24 Jan 2022 23:16:34 -0600 Subject: [PATCH 2/8] Remove version-specific branches in tests --- features/install-wp-tests.feature | 126 ------------------------------ 1 file changed, 126 deletions(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index e92b360e..79987405 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -14,7 +14,6 @@ Feature: Scaffold install-wp-tests.sh tests """ And the return code should be 1 - @require-php-5.6 @less-than-php-8.0 Scenario: Install latest version of WordPress Given a WP install And a affirmative-response file: @@ -127,131 +126,6 @@ Feature: Scaffold install-wp-tests.sh tests Leaving the existing database (wp_cli_test_scaffold) in place """ - @require-php-8.0 - Scenario: Install latest version of WordPress on PHP 8.0+ - Given a WP install - And a affirmative-response file: - """ - Y - """ - And a negative-response file: - """ - No - """ - And a get-phpunit-phar-url.php file: - """ - = 50600) { - $version = 5; - } - if(PHP_VERSION_ID >= 70000) { - $version = 6; - } - if(PHP_VERSION_ID >= 70100) { - $version = 7; - } - if(PHP_VERSION_ID >= 80000) { - $version = 9; - } - echo "https://phar.phpunit.de/phpunit-{$version}.phar"; - """ - And I run `wp eval-file get-phpunit-phar-url.php --skip-wordpress` - And save STDOUT as {PHPUNIT_PHAR_URL} - And I run `wget -q -O phpunit {PHPUNIT_PHAR_URL}` - And I run `chmod +x phpunit` - And I run `wp plugin path` - And save STDOUT as {PLUGIN_DIR} - And I run `wp scaffold plugin hello-world` - # This throws a warning for the password provided via command line. - And I try `mysql -u{DB_USER} -p{DB_PASSWORD} -h{MYSQL_HOST} -P{MYSQL_PORT} --protocol=tcp -e "DROP DATABASE IF EXISTS wp_cli_test_scaffold"` - - When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest` - Then the return code should be 0 - And the {RUN_DIR}/wordpress-tests-lib directory should contain: - """ - data - """ - And the {RUN_DIR}/wordpress-tests-lib directory should contain: - """ - includes - """ - And the {RUN_DIR}/wordpress-tests-lib directory should contain: - """ - wp-tests-config.php - """ - And the {RUN_DIR}/wordpress directory should contain: - """ - index.php - license.txt - readme.html - wp-activate.php - wp-admin - wp-blog-header.php - wp-comments-post.php - wp-config-sample.php - wp-content - wp-cron.php - wp-includes - wp-links-opml.php - wp-load.php - wp-login.php - wp-mail.php - wp-settings.php - wp-signup.php - wp-trackback.php - xmlrpc.php - """ - And the {PLUGIN_DIR}/hello-world/phpunit.xml.dist file should exist - And STDERR should contain: - """ - install_test_suite - """ - - # This throws a warning for the password provided via command line. - When I try `mysql -u{DB_USER} -p{DB_PASSWORD} -h{MYSQL_HOST} -P{MYSQL_PORT} --protocol=tcp -e "SHOW DATABASES"` - And STDOUT should contain: - """ - wp_cli_test_scaffold - """ - - When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` - Then the return code should be 1 - And STDOUT should contain: - """ - Looks like you're using PHPUnit 9.5. - """ - And STDOUT should contain: - """ - WordPress requires at least PHPUnit 5. - """ - And STDOUT should contain: - """ - and is currently only compatible with PHPUnit up to 7.x. - """ - - When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < affirmative-response` - Then the return code should be 0 - And STDERR should contain: - """ - Reinstalling - """ - And STDOUT should contain: - """ - Recreated the database (wp_cli_test_scaffold) - """ - - When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < negative-response` - Then the return code should be 0 - And STDERR should contain: - """ - Reinstalling - """ - And STDOUT should contain: - """ - Leaving the existing database (wp_cli_test_scaffold) in place - """ - Scenario: Install WordPress from trunk Given a WP install And a get-phpunit-phar-url.php file: From 0d10a5a95ba3c35f86cc50f647a49b8b27849894 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 24 Jan 2022 23:29:11 -0600 Subject: [PATCH 3/8] Point to polyfils for running tests --- features/install-wp-tests.feature | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index 79987405..e581069f 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -101,7 +101,13 @@ Feature: Scaffold install-wp-tests.sh tests wp_cli_test_scaffold """ - When I run `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` + When I run `composer init --name=test/package --require="yoast/phpunit-polyfills:^1" --no-interaction --working-dir=polyfills` + Then the return code should be 0 + + When I run `composer install --no-interaction --working-dir=polyfills` + Then the return code should be 0 + + When I run `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_TESTS_PHPUNIT_POLYFILLS_PATH={RUN_DIR}/polyfills/vendor/yoast/phunit-polyfills ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` Then the return code should be 0 When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < affirmative-response` From 463aeb58442ad509f930480e37d8d9b69239404f Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 24 Jan 2022 23:33:37 -0600 Subject: [PATCH 4/8] Create polyfills directory before composer init --- features/install-wp-tests.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index e581069f..9957698d 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -101,7 +101,7 @@ Feature: Scaffold install-wp-tests.sh tests wp_cli_test_scaffold """ - When I run `composer init --name=test/package --require="yoast/phpunit-polyfills:^1" --no-interaction --working-dir=polyfills` + When I run `mkdir polyfills && composer init --name=test/package --require="yoast/phpunit-polyfills:^1" --no-interaction --working-dir=polyfills` Then the return code should be 0 When I run `composer install --no-interaction --working-dir=polyfills` From 1eab2b3e4ebcf4591b0111313901b63f29a720d7 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 24 Jan 2022 23:45:33 -0600 Subject: [PATCH 5/8] Avoid output from Composer --- features/install-wp-tests.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index 9957698d..1e3af1e9 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -101,10 +101,10 @@ Feature: Scaffold install-wp-tests.sh tests wp_cli_test_scaffold """ - When I run `mkdir polyfills && composer init --name=test/package --require="yoast/phpunit-polyfills:^1" --no-interaction --working-dir=polyfills` + When I run `mkdir polyfills && composer init --name=test/package --require="yoast/phpunit-polyfills:^1" --no-interaction --quiet --working-dir=polyfills` Then the return code should be 0 - When I run `composer install --no-interaction --working-dir=polyfills` + When I run `composer install --no-interaction --working-dir=polyfills --quiet` Then the return code should be 0 When I run `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_TESTS_PHPUNIT_POLYFILLS_PATH={RUN_DIR}/polyfills/vendor/yoast/phunit-polyfills ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` From bd59b3de7e90372200b28beca615e786e65ed6c7 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 25 Jan 2022 00:08:57 -0600 Subject: [PATCH 6/8] Fix typo in polyfills path --- features/install-wp-tests.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index 1e3af1e9..b5a0d703 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -107,7 +107,7 @@ Feature: Scaffold install-wp-tests.sh tests When I run `composer install --no-interaction --working-dir=polyfills --quiet` Then the return code should be 0 - When I run `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_TESTS_PHPUNIT_POLYFILLS_PATH={RUN_DIR}/polyfills/vendor/yoast/phunit-polyfills ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` + When I run `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_TESTS_PHPUNIT_POLYFILLS_PATH={RUN_DIR}/polyfills/vendor/yoast/phpunit-polyfills ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` Then the return code should be 0 When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < affirmative-response` From 2f4655eab2203acfe60755ef47d8a7c6372f5b47 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 25 Jan 2022 00:16:13 -0600 Subject: [PATCH 7/8] Revert "Remove version-specific branches in tests" This reverts commit 04119db730f9bf813cc66d051d147fa457820dd5. --- features/install-wp-tests.feature | 126 ++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index b5a0d703..6e7ccd8f 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -14,6 +14,7 @@ Feature: Scaffold install-wp-tests.sh tests """ And the return code should be 1 + @require-php-5.6 @less-than-php-8.0 Scenario: Install latest version of WordPress Given a WP install And a affirmative-response file: @@ -132,6 +133,131 @@ Feature: Scaffold install-wp-tests.sh tests Leaving the existing database (wp_cli_test_scaffold) in place """ + @require-php-8.0 + Scenario: Install latest version of WordPress on PHP 8.0+ + Given a WP install + And a affirmative-response file: + """ + Y + """ + And a negative-response file: + """ + No + """ + And a get-phpunit-phar-url.php file: + """ + = 50600) { + $version = 5; + } + if(PHP_VERSION_ID >= 70000) { + $version = 6; + } + if(PHP_VERSION_ID >= 70100) { + $version = 7; + } + if(PHP_VERSION_ID >= 80000) { + $version = 9; + } + echo "https://phar.phpunit.de/phpunit-{$version}.phar"; + """ + And I run `wp eval-file get-phpunit-phar-url.php --skip-wordpress` + And save STDOUT as {PHPUNIT_PHAR_URL} + And I run `wget -q -O phpunit {PHPUNIT_PHAR_URL}` + And I run `chmod +x phpunit` + And I run `wp plugin path` + And save STDOUT as {PLUGIN_DIR} + And I run `wp scaffold plugin hello-world` + # This throws a warning for the password provided via command line. + And I try `mysql -u{DB_USER} -p{DB_PASSWORD} -h{MYSQL_HOST} -P{MYSQL_PORT} --protocol=tcp -e "DROP DATABASE IF EXISTS wp_cli_test_scaffold"` + + When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest` + Then the return code should be 0 + And the {RUN_DIR}/wordpress-tests-lib directory should contain: + """ + data + """ + And the {RUN_DIR}/wordpress-tests-lib directory should contain: + """ + includes + """ + And the {RUN_DIR}/wordpress-tests-lib directory should contain: + """ + wp-tests-config.php + """ + And the {RUN_DIR}/wordpress directory should contain: + """ + index.php + license.txt + readme.html + wp-activate.php + wp-admin + wp-blog-header.php + wp-comments-post.php + wp-config-sample.php + wp-content + wp-cron.php + wp-includes + wp-links-opml.php + wp-load.php + wp-login.php + wp-mail.php + wp-settings.php + wp-signup.php + wp-trackback.php + xmlrpc.php + """ + And the {PLUGIN_DIR}/hello-world/phpunit.xml.dist file should exist + And STDERR should contain: + """ + install_test_suite + """ + + # This throws a warning for the password provided via command line. + When I try `mysql -u{DB_USER} -p{DB_PASSWORD} -h{MYSQL_HOST} -P{MYSQL_PORT} --protocol=tcp -e "SHOW DATABASES"` + And STDOUT should contain: + """ + wp_cli_test_scaffold + """ + + When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` + Then the return code should be 1 + And STDOUT should contain: + """ + Looks like you're using PHPUnit 9.5. + """ + And STDOUT should contain: + """ + WordPress requires at least PHPUnit 5. + """ + And STDOUT should contain: + """ + and is currently only compatible with PHPUnit up to 7.x. + """ + + When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < affirmative-response` + Then the return code should be 0 + And STDERR should contain: + """ + Reinstalling + """ + And STDOUT should contain: + """ + Recreated the database (wp_cli_test_scaffold) + """ + + When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < negative-response` + Then the return code should be 0 + And STDERR should contain: + """ + Reinstalling + """ + And STDOUT should contain: + """ + Leaving the existing database (wp_cli_test_scaffold) in place + """ + Scenario: Install WordPress from trunk Given a WP install And a get-phpunit-phar-url.php file: From fe83f234b84b2645a3123a3985b278728cba5f2e Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 25 Jan 2022 00:17:27 -0600 Subject: [PATCH 8/8] Adapt tests for PHP 8.0+ --- features/install-wp-tests.feature | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index 6e7ccd8f..ed408fc8 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -14,7 +14,7 @@ Feature: Scaffold install-wp-tests.sh tests """ And the return code should be 1 - @require-php-5.6 @less-than-php-8.0 + @less-than-php-8.0 Scenario: Install latest version of WordPress Given a WP install And a affirmative-response file: @@ -221,7 +221,13 @@ Feature: Scaffold install-wp-tests.sh tests wp_cli_test_scaffold """ - When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` + When I run `mkdir polyfills && composer init --name=test/package --require="yoast/phpunit-polyfills:^1" --no-interaction --quiet --working-dir=polyfills` + Then the return code should be 0 + + When I run `composer install --no-interaction --working-dir=polyfills --quiet` + Then the return code should be 0 + + When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_TESTS_PHPUNIT_POLYFILLS_PATH={RUN_DIR}/polyfills/vendor/yoast/phpunit-polyfills ./phpunit -c {PLUGIN_DIR}/hello-world/phpunit.xml.dist` Then the return code should be 1 And STDOUT should contain: """