xwp/wp-dev-lib

Support for plugin-dependent tests

ocean90 opened this issue · 5 comments

Has anyone some experiences with plugin-dependent tests and Travis CI?

xwp_filter_active_plugins_for_phpunit() has support for a WP_TEST_ACTIVATED_PLUGINS constant which looks fine, but I'm more interested on how to get the plugin installed during the build.

The install action is too early because the test suite gets installed on script via run_phpunit_travisci(). But I can't add something before or after because WP is installed on-the-fly, see https://github.com/xwp/wp-dev-lib/blob/master/check-diff.sh#L584.

So, what I need is something which gets called after WP is installed but before phpunit is executed.

Idea: Define a function after_wp_install in .dev-lib and in check-diff.sh do

if [ "$( type -t after_wp_install )" != '' ]; then
    after_wp_install
fi

Thoughts?

I have a PR that does this for themes that I need to finish, and I can extend it to install dependencies for plugins, as well.

@ocean90 WP_TEST_ACTIVATED_PLUGINS doesn't currently work in the Travis CI context where a plugin is the sole part of the repo being tested. We're using it in pre-commit hook or in another CI environment where all of the plugins for a project are already installed and available, so activating just needs a filter.

I like your idea for adding support for a after_wp_install function that would be executed if defined. This allows for a lot of flexibility. This function could then be defined in .dev-lib to install plugin dependencies via WP-CLI if on w.org, or else it can download them from alternate locations if they are private.

@valendesigns You're referring to #150?

@westonruter Yeah, I already thought so. Looking at #150 and it seems like it can only handle plugins which are on GitHub, at least for now. So a after_wp_install "hook" is indeed more flexible. But I don't see any harm in doing both.

I'll play a bit with my idea now.

Is there anything remaining for this now that WP_TEST_ACTIVATED_PLUGINS and after_wp_install are both available?

I don't think so. I'm happy with after_wp_install. 😄