3

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

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.

3
  • Thanks very much for your guidance. I was able to get the tests working, but unfortunately there is no way to preserve the --prefer-source flag in composer.lock, so whenever I push to CI, the build fails. I'll have to find another method. – Ben Harold Feb 19 '19 at 18:54
  • I haven't test if getcomposer.org/doc/06-config.md#preferred-install has any affect, guess not. Just for reference here's the the .travis.yml of the WooCommerce Custom Orders Table plugin. – birgire Feb 19 '19 at 20:18
  • 1
    That worked! Sweet! – Ben Harold Feb 20 '19 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.