Unit Testing with WooCommerce
Are you developing a plugin or a theme that requires or enhances WooCommerce? Would you like to include or load WooCommerce while your unit testing is run?
With WordPress MVC this is very simple because the framework allows loading any external plugin or theme, in addition to the project, which allows for full testing integration.
How to load WooCommerce during PHPUnit execution?
Before loading WooCommerce, you will need to make sure that you have set up testing in your project, to do this you will need to run the setup wizard command:
php ayuco setup tests
Once unit testing is set up, you will need to open the file tests/bootstrap.php
in your project and find the comment section with the text “Load plugin dependencies here, example below:“, right after, paste the following lines of code:
// ---------------------------- // // Load plugin dependencies here, example below: // // require_once WP_CONTENT_DIR . '/plugins/woocommerce/woocommerce.php'; // // ---------------------------- require_once WP_CONTENT_DIR . '/plugins/woocommerce/woocommerce.php'; require_once WP_CONTENT_DIR . '/plugins/woocommerce/packages/action-scheduler/action-scheduler.php'; require_once WP_CONTENT_DIR . '/plugins/woocommerce/packages/action-scheduler/functions.php'; action_scheduler_initialize_3_dot_4_dot_0();
These lines will load WooCommerce and ActionScheduler (which is needed for certain operations in WooCommerce), and now you are good to go with your testing.