Jack Robson
Jack Robson

Reputation: 2302

Unit-Testing a WooCommerce Extension

I'm new to using PHPStorm along with PHPUnit, and the wordpress-develop package.

My projects rely on WooCommerce a lot.

Is it possible to add it as a dependency to the project?

At the moment I get this result: enter image description here

And have the following setup:

enter image description here

enter image description here

Any help appreciated.

Upvotes: 0

Views: 920

Answers (1)

Jack Robson
Jack Robson

Reputation: 2302

Got it working

What I did was use git to clone the woocommerce project

git clone https://github.com/woocommerce/woocommerce/ temp

Then I copied the tests folder and put it inside my project. Then I kept making edits until it worked with my existing code.

Here is what my project looks like now:

enter image description here

I have a copy of the normal woocommerce project in my includes. The one without the tests, the one you can download from the WordPress plugin repository.

I copied the WooCommerce tests into the project, see folder wc_tests.

Here is what the tests/bootstrap.php file looks like

enter image description here

Note the last line that requires the wc_tests/bootstrap.php file.

I only made one change to the wc_tests file, I changed the plugin directory.

enter image description here

        $this->plugin_dir   = dirname( $this->tests_dir ) . '/includes/woocommerce';

Combined with a line of code out of screen, it makes the WC available for the project

        require_once $this->plugin_dir . '/woocommerce.php';

I'm probably doing some of this wrong, but it works.

Any further questions, tips or advice appreciated.

Upvotes: 3

Related Questions