Commit ad52fb2910b for woocommerce
commit ad52fb2910b3206d0f97d97ac51ffc5b87729afd
Author: Taha Paksu <3295+tpaksu@users.noreply.github.com>
Date: Thu May 14 16:46:55 2026 +0300
Make WC_Email_Customer_Review_Request_Test self-contained for the feature gate (#64906)
* Make WC_Email_Customer_Review_Request_Test self-contained for the feature gate
`WC_Emails::init()` only registers the review-request email class when
the `customer_review_request` feature flag is on. The previous setUp
didn't enable the flag, so `test_is_registered_with_wc_emails` (which
asserts the class is in `WC()->mailer()->get_emails()`) was flaky: it
only passed when an earlier OrderReviews suite (SchedulerTest etc.)
had happened to enable the flag and re-init the mailer first.
Enable the flag in setUp, re-init the mailer so the gated registration
picks up the change, and reset the option in tearDown so the suite
doesn't leak the enabled state into unrelated test classes.
Surfaced as a CI failure on the release/10.8 backport PR #64895 when
PHPUnit picked up the email test before any flag-enabling suite; the
same flake reproduces on trunk when the test is run in isolation.
* Add changefile(s) from automation for the following project(s): woocommerce
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/64906-wooplug-fix-email-test-flag-isolation b/plugins/woocommerce/changelog/64906-wooplug-fix-email-test-flag-isolation
new file mode 100644
index 00000000000..9a3e95447b3
--- /dev/null
+++ b/plugins/woocommerce/changelog/64906-wooplug-fix-email-test-flag-isolation
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Make `WC_Email_Customer_Review_Request_Test` self-contained for the `customer_review_request` feature gate so `test_is_registered_with_wc_emails` doesn't depend on incidental test ordering.
\ No newline at end of file
diff --git a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
index abfab4e7ab9..6bb0ed461d9 100644
--- a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
+++ b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
@@ -17,19 +17,40 @@ class WC_Email_Customer_Review_Request_Test extends \WC_Unit_Test_Case {
/**
* Load up the email classes since they aren't loaded by default.
+ *
+ * `WC_Emails::init()` only registers the review-request email class
+ * when the `customer_review_request` feature flag is on, so the suite
+ * has to enable the option (and re-init the mailer to pick up the
+ * flag change) before exercising the mailer-level registration. Doing
+ * it here makes every test self-contained rather than relying on the
+ * incidental order of other OrderReviews suites that also flip the flag.
*/
public function setUp(): void {
parent::setUp();
+ update_option( 'woocommerce_feature_customer_review_request_enabled', 'yes' );
+
$bootstrap = \WC_Unit_Tests_Bootstrap::instance();
require_once $bootstrap->plugin_dir . '/includes/emails/class-wc-email.php';
require_once $bootstrap->plugin_dir . '/includes/emails/class-wc-email-customer-review-request.php';
$this->ensure_review_order_page();
+ WC()->mailer()->init();
+
$this->sut = new WC_Email_Customer_Review_Request();
}
+ /**
+ * Reset the feature flag between tests so the suite doesn't leak the
+ * enabled state into unrelated test classes that assume the default.
+ */
+ public function tearDown(): void {
+ delete_option( 'woocommerce_feature_customer_review_request_enabled' );
+
+ parent::tearDown();
+ }
+
/**
* Make sure the WC-managed Review Order page exists for tests that build a
* URL through the endpoint. The bootstrap install seeds the page, but the