-
Notifications
You must be signed in to change notification settings - Fork 24
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
Make it easier to write tests for WordPress plugins containing CLI commands #31
Conversation
This points to the source directory of the project where the test suite has been installed
Allows installing plugins from ZIP files residing in PROJECT_DIR
wearerequired/traduttore#124 is where I'm currently using this PR. |
I think this is a good first step to support this, and the changes generally make sense in any case. However, I think we should ultimately try to make it possible to test a plugin without needing to zip it up first. |
Oh, absolutely. I explored that too but quickly ran into problems with the autoloader, getting errors like these (as described in wearerequired/traduttore#124):
|
Make it easier to write tests for WordPress plugins containing CLI commands
Situation:
I'm developing a WordPress plugin that registers some WP-CLI commands. Now I want to write some functional tests for these, ideally by leveraging this identical testing framework as for standalone commands.
In case anyone's wondering, the plugin I'm developing can be found at https://github.com/wearerequired/traduttore.
To run the tests, I need to activate / load the plugin somehow.
One suggestion by Daniel that led me to the right path was creating a ZIP archive and installing that ZIP file. He did this in a plugin once where
FeatureContext.php
was part of the code base. I obviously can't edit that file because it's now in thewp-cli-tests
package.Alain's suggestion was to use something like this:
However, variables are currently not being replaced in the
these installed and active plugins
step.Plus,
RUN_DIR
points to the WordPress directory used for the tests, not the actual repository where my plugin and my ZIP file reside.Thus, I decided to add a new variable,
PROJECT_DIR
which aims to be the plugin source directory. That's also wherewp-cli/wp-cli-tests
is installed using Composer inPROJECT_DIR/vendor/wp-cli/wp-cli-tests
.This way I can use the following scenario: