It's been a while since the last serious work on this repo, so this PR does some basic maintenance:
Update Composer dependencies
Replace deprecated WPCS: comments with the standard phpcs:ignore/disable/enable syntax
Bump WordPress, WooCommerce, and PHP versions in the Travis testing matrix
This PR also adds composer test and composer test:all as shortcuts for running PHPUnit with just the "plugin" test suite or all test suites, respectively.
Changing the way WooCommerce is installed
Perhaps the biggest change is the way that WooCommerce core is being installed: recent versions of WooCommerce have started splitting off portions into separate packages, which are then loaded by Composer and processed on a post-install-cmd hook. However, only the Composer scripts defined in the root package (read: this) are fired, so test runs would end up with errors like the following:
Instead of trying to keep up with every change in WooCommerce's build process, I wrote tests/bin/install-woocommerce.sh which does a shallow checkout of woocommerce/woocommerce at either master or release/{version}, installs it to vendor/woocommerce/woocommerce-src-{version}, then builds the plugin in-place there.
While this goes a bit outside of Composer, it lets a single development environment have multiple versions of WooCommerce available for testing at once, toggled via the WC_VERSION environment variable.
For example, I can run the tests against WooCommerce 3.7, 3.8, 3.9, and master with the following commands:
Each version will be cached in my vendor/ directory, so subsequent runs will be much quicker.
Dynamic PHPUnit test suites
The next challenge comes in the form of the "core" test suite.
Remember: we have two test suites for the plugin: "plugin", which is for tests specific to the plugin, and "core" which runs the WooCommerce core test suite with the WooCommerce Custom Orders Table plugin activated.
Unfortunately, PHPUnit doesn't support variables in phpunit.xml(.dist) files, so I had to get sneaky with reflection (and abuse the heck out of the Singleton pattern) to hijack the in-memory instance of the PHPUnit configuration file and dynamically rewrite "%WC_VERSION%" placeholders.
For more details on that, please see the commit message for dfe822a.
It's been a while since the last serious work on this repo, so this PR does some basic maintenance:
WPCS:
comments with the standardphpcs:ignore/disable/enable
syntaxThis PR also adds
composer test
andcomposer test:all
as shortcuts for running PHPUnit with just the "plugin" test suite or all test suites, respectively.Changing the way WooCommerce is installed
Perhaps the biggest change is the way that WooCommerce core is being installed: recent versions of WooCommerce have started splitting off portions into separate packages, which are then loaded by Composer and processed on a
post-install-cmd
hook. However, only the Composer scripts defined in the root package (read: this) are fired, so test runs would end up with errors like the following:Instead of trying to keep up with every change in WooCommerce's build process, I wrote
tests/bin/install-woocommerce.sh
which does a shallow checkout of woocommerce/woocommerce at eithermaster
orrelease/{version}
, installs it tovendor/woocommerce/woocommerce-src-{version}
, then builds the plugin in-place there.While this goes a bit outside of Composer, it lets a single development environment have multiple versions of WooCommerce available for testing at once, toggled via the
WC_VERSION
environment variable.For example, I can run the tests against WooCommerce 3.7, 3.8, 3.9, and master with the following commands:
Each version will be cached in my
vendor/
directory, so subsequent runs will be much quicker.Dynamic PHPUnit test suites
The next challenge comes in the form of the "core" test suite.
Remember: we have two test suites for the plugin: "plugin", which is for tests specific to the plugin, and "core" which runs the WooCommerce core test suite with the WooCommerce Custom Orders Table plugin activated.
Unfortunately, PHPUnit doesn't support variables in
phpunit.xml(.dist)
files, so I had to get sneaky with reflection (and abuse the heck out of the Singleton pattern) to hijack the in-memory instance of the PHPUnit configuration file and dynamically rewrite "%WC_VERSION%" placeholders.For more details on that, please see the commit message for dfe822a.