From c40d545ef8baa83f6416f7d040473b98f6711735 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 18 Nov 2018 16:30:46 +0100 Subject: [PATCH 1/5] Declare new PROJECT_DIR variable This points to the source directory of the project where the test suite has been installed --- features/bootstrap/FeatureContext.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 02e3ca319..774bfb362 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -209,8 +209,9 @@ private static function get_behat_internal_variables() { } $variables = [ - 'SRC_DIR' => realpath( dirname( dirname( __DIR__ ) ) ), 'FRAMEWORK_ROOT' => realpath( $framework_root ), + 'SRC_DIR' => realpath( dirname( __DIR__, 2 ) ), + 'PROJECT_DIR' => realpath( dirname( __DIR__, 5 ) ), ]; return $variables; From aed835e931ea7f7c3b3fd112b73765d6038967f5 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 18 Nov 2018 16:31:41 +0100 Subject: [PATCH 2/5] Replace variables in step to install plugins Allows installing plugins from ZIP files residing in PROJECT_DIR --- features/steps/given.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/features/steps/given.php b/features/steps/given.php index 97ce11ec8..ef0425a18 100644 --- a/features/steps/given.php +++ b/features/steps/given.php @@ -134,6 +134,8 @@ function ( $world, $type = 'subdirectory' ) { '/^these installed and active plugins:$/', function( $world, $stream ) { $plugins = implode( ' ', array_map( 'trim', explode( PHP_EOL, (string) $stream ) ) ); + $plugins = $world->replace_variables( $plugins ); + $world->proc( "wp plugin install $plugins --activate" )->run_check(); } ); From 7564d15c48ce0dc6b86ec9764bed236bb00b90d9 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 2 Dec 2018 13:40:15 +0100 Subject: [PATCH 3/5] Use nested dirname instead of PHP 7 only feature --- README.md | 71 +-------------------------- features/bootstrap/FeatureContext.php | 4 +- 2 files changed, 4 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index c4cd5a07a..819b3290c 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,10 @@ To make use of the WP-CLI testing framework, you need to complete the following 2. Add the required test scripts to the `composer.json` file: ```json "scripts": { - "behat": "run-behat-tests", - "behat-rerun": "rerun-behat-tests", "lint": "run-linter-tests", "phpcs": "run-phpcs-tests", "phpunit": "run-php-unit-tests", + "behat": "run-behat-tests", "prepare-tests": "install-package-tests", "test": [ "@lint", @@ -52,7 +51,7 @@ To make use of the WP-CLI testing framework, you need to complete the following ``` This will make sure that the automated Behat system works across all platforms. This is needed on Windows. -5. Update your composer dependencies and regenerate your autoloader and binary folders: +4. Update your composer dependencies and regenerate your autoloader and binary folders: ```bash composer update ``` @@ -81,72 +80,6 @@ Prepending with the double dash is needed because the arguments would otherwise ### Controlling the test environment -#### WordPress Version - -You can run the tests against a specific version of WordPress by setting the `WP_VERSION` environment variable. - -This variable understands any numeric version, as well as the special terms `latest` and `trunk`. - -Note: This only applies to the Behat functional tests. All other tests never load WordPress. - -Here's how to run your tests against the latest trunk version of WordPress: -```bash -WP_VERSION=trunk composer behat -``` - -#### WP-CLI Binary - -You can run the tests against a specific WP-CLI binary, instead of using the one that has been built in your project's `vendor/bin` folder. - -This can be useful to run your tests against a specific Phar version of WP_CLI. - -To do this, you can set the `WP_CLI_BIN_DIR` environment variable to point to a folder that contains an executable `wp` binary. Note: the binary has to be named `wp` to be properly recognized. - -As an example, here's how to run your tests against a specific Phar version you've downloaded. -```bash -# Prepare the binary you've downloaded into the ~/wp-cli folder first. -mv ~/wp-cli/wp-cli-1.2.0.phar ~/wp-cli/wp -chmod +x ~/wp-cli/wp - -WP_CLI_BIN_DIR=~/wp-cli composer behat -``` - -### Setting up the tests in Travis CI - -Basic rules for setting up the test framework with Travis CI: - -* `composer prepare-tests` needs to be called once per environment. -* `linting and sniffing` is a static analysis, so it shouldn't depend on any specific environment. You should do this only once, as a separate stage, instead of per environment. -* `composer behat || composer behat-rerun` causes the Behat tests to run in their entirety first, and in case their were failed scenarios, a second run is done with only the failed scenarios. This usually gets around intermittent issues like timeouts or similar. - -Here's a basic setup of how you can configure Travis CI to work with the test framework (extract): -```yml -install: - - composer install - - composer prepare-tests - -script: - - composer phpunit - - composer behat || composer behat-rerun - -jobs: - include: - - stage: sniff - script: - - composer lint - - composer phpcs - env: BUILD=sniff - - stage: test - php: 7.2 - env: WP_VERSION=latest - - stage: test - php: 7.2 - env: WP_VERSION=3.7.11 - - stage: test - php: 7.2 - env: WP_VERSION=trunk -``` - #### WP-CLI version You can point the tests to a specific version ow WP-CLI through the `WP_CLI_BIN_DIR` constant: diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 774bfb362..fb9387877 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -210,8 +210,8 @@ private static function get_behat_internal_variables() { $variables = [ 'FRAMEWORK_ROOT' => realpath( $framework_root ), - 'SRC_DIR' => realpath( dirname( __DIR__, 2 ) ), - 'PROJECT_DIR' => realpath( dirname( __DIR__, 5 ) ), + 'SRC_DIR' => realpath( dirname( dirname( __DIR__ ) ) ), + 'PROJECT_DIR' => realpath( dirname( dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) ) ), ]; return $variables; From 9272359c0e1445596e621a709a3c1957eb79e2e2 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 3 Dec 2018 21:40:35 +0100 Subject: [PATCH 4/5] Revert the inadvertent changes to the README.md file that were caused by #32 --- .commit-readme-md | 0 README.md | 71 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 .commit-readme-md diff --git a/.commit-readme-md b/.commit-readme-md new file mode 100644 index 000000000..e69de29bb diff --git a/README.md b/README.md index 819b3290c..c4cd5a07a 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,11 @@ To make use of the WP-CLI testing framework, you need to complete the following 2. Add the required test scripts to the `composer.json` file: ```json "scripts": { + "behat": "run-behat-tests", + "behat-rerun": "rerun-behat-tests", "lint": "run-linter-tests", "phpcs": "run-phpcs-tests", "phpunit": "run-php-unit-tests", - "behat": "run-behat-tests", "prepare-tests": "install-package-tests", "test": [ "@lint", @@ -51,7 +52,7 @@ To make use of the WP-CLI testing framework, you need to complete the following ``` This will make sure that the automated Behat system works across all platforms. This is needed on Windows. -4. Update your composer dependencies and regenerate your autoloader and binary folders: +5. Update your composer dependencies and regenerate your autoloader and binary folders: ```bash composer update ``` @@ -80,6 +81,72 @@ Prepending with the double dash is needed because the arguments would otherwise ### Controlling the test environment +#### WordPress Version + +You can run the tests against a specific version of WordPress by setting the `WP_VERSION` environment variable. + +This variable understands any numeric version, as well as the special terms `latest` and `trunk`. + +Note: This only applies to the Behat functional tests. All other tests never load WordPress. + +Here's how to run your tests against the latest trunk version of WordPress: +```bash +WP_VERSION=trunk composer behat +``` + +#### WP-CLI Binary + +You can run the tests against a specific WP-CLI binary, instead of using the one that has been built in your project's `vendor/bin` folder. + +This can be useful to run your tests against a specific Phar version of WP_CLI. + +To do this, you can set the `WP_CLI_BIN_DIR` environment variable to point to a folder that contains an executable `wp` binary. Note: the binary has to be named `wp` to be properly recognized. + +As an example, here's how to run your tests against a specific Phar version you've downloaded. +```bash +# Prepare the binary you've downloaded into the ~/wp-cli folder first. +mv ~/wp-cli/wp-cli-1.2.0.phar ~/wp-cli/wp +chmod +x ~/wp-cli/wp + +WP_CLI_BIN_DIR=~/wp-cli composer behat +``` + +### Setting up the tests in Travis CI + +Basic rules for setting up the test framework with Travis CI: + +* `composer prepare-tests` needs to be called once per environment. +* `linting and sniffing` is a static analysis, so it shouldn't depend on any specific environment. You should do this only once, as a separate stage, instead of per environment. +* `composer behat || composer behat-rerun` causes the Behat tests to run in their entirety first, and in case their were failed scenarios, a second run is done with only the failed scenarios. This usually gets around intermittent issues like timeouts or similar. + +Here's a basic setup of how you can configure Travis CI to work with the test framework (extract): +```yml +install: + - composer install + - composer prepare-tests + +script: + - composer phpunit + - composer behat || composer behat-rerun + +jobs: + include: + - stage: sniff + script: + - composer lint + - composer phpcs + env: BUILD=sniff + - stage: test + php: 7.2 + env: WP_VERSION=latest + - stage: test + php: 7.2 + env: WP_VERSION=3.7.11 + - stage: test + php: 7.2 + env: WP_VERSION=trunk +``` + #### WP-CLI version You can point the tests to a specific version ow WP-CLI through the `WP_CLI_BIN_DIR` constant: From 36b47c967750a1e0f9338bbe3239aaeb78d011b3 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 3 Dec 2018 21:41:44 +0100 Subject: [PATCH 5/5] Remove left-over file --- .commit-readme-md | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .commit-readme-md diff --git a/.commit-readme-md b/.commit-readme-md deleted file mode 100644 index e69de29bb..000000000