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

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