What’s the proper method of installing a plugin during unit testing?

I am testing a plugin that depends on WooCommerce. In order to properly test the integration, I need WooCommerce installed in the WordPress test application.

I tried installing the plugin using wp-cli via the install_wp_tests script:

wp plugin install woocommerce --activate --allow-root --path=$WP_CORE_DIR

This kicks out an error:

Error: 'wp-config.php' not found.

From what I can tell, the test configuration file is in /tmp/wordpress-tests-lib/wp-tests-config.php. From reading the wp-cli docs, I don’t see any method to specify the path to the configuration file.

How can I install WooCommerce during my test setup process?

1 Answer
1

Then there’s the Composer approach described here by Steve Grunwell, to load WooCommerce as a development dependency:

$ composer require --dev --prefer-source woocommerce/woocommerce

where he mentioned doing some composer.json adjustments, like moving WooCommerce under the vendor path:

  "extra": {
    "installer-paths": {
      "vendor/{$vendor}/{$name}": [
        "woocommerce/woocommerce"
      ]
    }
  }

and include WooCommerce tests in the generated autoloader:

  "autoload-dev": {
    "classmap": [
      "vendor/woocommerce/woocommerce/tests/framework"
    ]
  },

followed with:

$ composer update

Then there are corresponding adjustments to the bootstrap file, as described in the article.

The WooCommerce Custom Orders Table plugin on GitHub, from Liquid Web, is a great example of such a plugin.

This test setup worked well for my little WooCommerce depending plugin to be able extend the WC_Unit_Test_Case test class from WooCommerce.

Leave a Comment