Commit 53b138bbd71 for woocommerce

commit 53b138bbd714982b7a7032e5ae3661f18788439c
Author: Néstor Soriano <konamiman@konamiman.com>
Date:   Wed Jul 1 10:01:37 2026 +0200

    Stabilize non-UTC refund sales report test (#66113)

    test: stabilize non-UTC refund sales report test

    WC_REST_Report_Sales_Controller_Tests::test_refunds_bucketed_by_local_time_in_non_utc_site
    failed intermittently in CI (e.g. the PHP 7.4 job) with "Failed asserting
    that an array has the key '...'".

    The test forced the site timezone with date_default_timezone_set(), which
    breaks WordPress's invariant that PHP's default timezone is always UTC. The
    legacy sales report computes its date range via
    date( 'Y-m-d', current_time( 'timestamp' ) ), so the +12h offset was applied
    twice and the report's "today" bucket drifted one day ahead whenever the job
    ran while UTC was between 00:00 and 12:00.

    Configure the non-UTC site the realistic way — via the timezone_string
    option only — and compute the expected day with current_datetime(). The
    refund's post_date (local) and post_date_gmt (UTC) still fall on different
    days, so the local-vs-UTC bucketing regression remains covered.

diff --git a/plugins/woocommerce/changelog/fix-flaky-non-utc-refund-report-test b/plugins/woocommerce/changelog/fix-flaky-non-utc-refund-report-test
new file mode 100644
index 00000000000..f5f3c1e1ec6
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-flaky-non-utc-refund-report-test
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Stabilize the non-UTC refund sales report unit test so it no longer fails depending on the time of day CI runs; test-only, no changes to shipped code.
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-report-sales-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-report-sales-controller-tests.php
index d4bfbb5fd50..ccf01ea4201 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-report-sales-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-report-sales-controller-tests.php
@@ -164,14 +164,13 @@ class WC_REST_Report_Sales_Controller_Tests extends WC_REST_Unit_Test_Case {
 	 * per-row net sales (sales - refunds) wrong.
 	 */
 	public function test_refunds_bucketed_by_local_time_in_non_utc_site(): void {
-		$previous_php_tz = date_default_timezone_get();
-		$previous_wp_tz  = get_option( 'timezone_string' );
+		$previous_wp_tz = get_option( 'timezone_string' );

-		// Pacific/Auckland is UTC+12 (or +13 in DST) — large enough that a local-time-of-02:00
-		// is the previous calendar day in UTC, surfacing any date()/gmdate() mismatch.
+		// Pacific/Auckland is UTC+12 (or +13 in DST). Configure the non-UTC site the
+		// way WordPress actually does (via the timezone_string option, leaving PHP's
+		// default timezone at UTC) so the legacy report range math (which assumes the
+		// WordPress UTC invariant) is exercised as it runs in production.
 		update_option( 'timezone_string', 'Pacific/Auckland' );
-		// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set -- Need to change the PHP timezone to exercise local-vs-UTC date bucketing.
-		date_default_timezone_set( 'Pacific/Auckland' );

 		try {
 			$order = WC_Helper_Order::create_order();
@@ -185,8 +184,10 @@ class WC_REST_Report_Sales_Controller_Tests extends WC_REST_Unit_Test_Case {
 				)
 			);

-			// phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- Need local-zone date for the assertion.
-			$local_today     = date( 'Y-m-d' );
+			// Local time of 02:00 is still the previous calendar day in UTC, so the
+			// refund's post_date (local) and post_date_gmt (UTC) land on different days.
+			// Bucketing by UTC instead of local time would put the refund in the wrong row.
+			$local_today     = current_datetime()->format( 'Y-m-d' );
 			$local_post_date = $local_today . ' 02:00:00';
 			wp_update_post(
 				array(
@@ -208,8 +209,6 @@ class WC_REST_Report_Sales_Controller_Tests extends WC_REST_Unit_Test_Case {
 				'Refund must bucket by local time so it lines up with sales/orders in the same row.'
 			);
 		} finally {
-			// phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set -- Restore the original PHP timezone.
-			date_default_timezone_set( $previous_php_tz );
 			update_option( 'timezone_string', $previous_wp_tz );
 		}
 	}