Commit 1ce1f532d54 for woocommerce
commit 1ce1f532d54a74f0e5734b72c4459ee129fd9148
Author: Taha Paksu <3295+tpaksu@users.noreply.github.com>
Date: Tue Feb 24 14:01:11 2026 +0300
Fix PHP unit test failures on WP 7.0-beta1 (#63425)
* Fix PHP unit test failures on WP 7.0-beta1
Replace stdClass screen mocks with proper WP_Screen instances in
WC_Orders_Tracking_Test and ReviewsCommentsOverridesTest. WP 7.0
requires $current_screen to be a WP_Screen instance for
get_current_screen() to return it (instanceof check).
* 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/63425-fix-wp70-beta-php-unit-test-flakiness b/plugins/woocommerce/changelog/63425-fix-wp70-beta-php-unit-test-flakiness
new file mode 100644
index 00000000000..762cb26d975
--- /dev/null
+++ b/plugins/woocommerce/changelog/63425-fix-wp70-beta-php-unit-test-flakiness
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Adjust tests for WP 7.0-beta.1 compatibility
\ No newline at end of file
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-orders-tracking-test.php b/plugins/woocommerce/tests/php/includes/class-wc-orders-tracking-test.php
index befb07a9157..0eb5c8810b1 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-orders-tracking-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-orders-tracking-test.php
@@ -143,18 +143,12 @@ class WC_Orders_Tracking_Test extends \WC_Unit_Test_Case {
}
/**
- * Returns an object mocking what we need from `\WP_Screen`.
+ * Returns a WP_Screen instance for use in tests.
*
- * @return object
+ * @return \WP_Screen
*/
private function get_screen_mock() {
- $screen_mock = $this->getMockBuilder( stdClass::class )->setMethods( array( 'in_admin', 'add_option' ) )->getMock();
- $screen_mock->method( 'in_admin' )->willReturn( true );
- foreach ( array( 'id', 'base', 'action', 'post_type' ) as $key ) {
- $screen_mock->{$key} = '';
- }
-
- return $screen_mock;
+ return \WP_Screen::get( '' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsCommentsOverridesTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsCommentsOverridesTest.php
index e0ef8fa4e53..c2098e02767 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsCommentsOverridesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsCommentsOverridesTest.php
@@ -53,10 +53,7 @@ class ReviewsCommentsOverridesTest extends WC_Unit_Test_Case {
public function test_display_notices( string $current_screen_base, bool $should_display_notices ) : void {
global $current_screen;
- $screen = new \stdClass();
- $screen->base = $current_screen_base;
-
- $current_screen = $screen; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+ $current_screen = \WP_Screen::get( $current_screen_base ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
// phpcs:disable Squiz.Commenting
$instance = new class() extends ReviewsCommentsOverrides {