Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP unit tests: Activate WC in the bootstrap rather than just loading files #47336

Draft
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

coreymckrill
Copy link
Collaborator

@coreymckrill coreymckrill commented May 9, 2024

Changes proposed in this Pull Request:

Recently this test started failing for all PRs. Investigating, I noticed that the plugin used in the test, Facebook for WooCommerce, had released a new version two days before with this changelog entry:

Tweak – Adds WooCommerce as a dependency to the plugin header.

After checking the internal state of things during the course of the unit test, I determined that the plugin was, in fact, installed, but that the activation call was failing with the message "The requested plugin facebook-for-woocommerce could not be activated." Looking further, I realized that in our unit test environment, we have been loading all the code for the WooCommerce plugin directly, and it is not actually considered "activated" by WordPress.

The main benefits of activating the plugin in this context are that the plugin slug will be included in the active_plugins option in wp_options, and the activation process will produce an error if any unexpected output is generated (meaning error messages or other content gets printed to the output buffer).

This PR is a bit of an experiment to see how the entire test suite fairs if we actually activate the WooCommerce plugin rather than just loading its code directly.

How to test the changes in this Pull Request:

See if all the tests still pass.

@coreymckrill coreymckrill self-assigned this May 9, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 9, 2024
@moon0326 moon0326 mentioned this pull request May 9, 2024
11 tasks
@coreymckrill coreymckrill added the focus: unit tests Related to PHP unit testing. label May 9, 2024
@coreymckrill
Copy link
Collaborator Author

Here's an interesting issue: this test is failing because the WooCommerce plugin is failing to activate when running on "WP: latest - 2" (two versions behind current WP version). This is because on trunk, we update the Requires at least plugin header right after we release a version to reflect what minimum version will be when we release the next version. Meaning, as soon as we released WC 6.5, the minimum version on trunk became 6.4 instead of 6.3.

This isn't a problem unless we do what this PR attempts, and have WooCommerce actually activated in WordPress during unit testing. But it's kind of ironic that we run unit tests in an environment that the code doesn't technically support...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: unit tests Related to PHP unit testing. plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant