Commit 0c5ee0da4d2 for woocommerce
commit 0c5ee0da4d26b76ba8f8039cc44fdd6dee513dff
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date: Mon Nov 16 08:17:54 2026 +0200
[tests] Stop tests writing to the database after their transaction (#70988)
* test: Drop more tearDown() hook removals that the restore undoes
WordPress's test case restores its hook snapshot inside
parent::tearDown(). #70944 deleted the removals in tearDown() that only
had other removals between them and that call. This handles the rest:
removals with other cleanup code before the parent call, and removals
inside conditions or loops.
A runtime probe marked each of the 192 removals and recorded every hook
fired between it and the restore, in full suites with HPOS on and off.
A removal changes anything only if its hook fires in that window. 188
never do, so they are deleted, with the 18 if/foreach blocks and 9
tearDown() methods left empty, and the 20 private properties that only
remembered a callback for tearDown to remove. Four stay, because their
hook fires before the restore: woocommerce_set_cookie_enabled,
woocommerce_payment_gateways, wc_payment_gateways_initialized and query.
Three of the removals #70944 kept by inspection, as hooks the base
class's cart and shipping cleanup might fire, never fire there, so they
go too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test: Drop the tearDown() hook removals that run after the restore
These nine removals run after parent::tearDown(), so after WordPress
has restored the hook snapshot. They change anything only if the hook
still has a callback at that point: the test's own callbacks are
already gone, and stripping a snapshot callback would leak into the
next test.
A temporary check logged whether each hook had a callback when the
removal ran. None ever did: not in any test, with each class run
alone, or in the full suites with HPOS on and off. Delete them, with
the three tearDown() methods left empty and the two properties that
only kept a callback for removal.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test: Commit the install tests reinstall and clear its stale lock
WC_Tests_Install runs installs inside test transactions. An install
takes the wc_installing lock, its schema changes commit the lock
mid-test, and its release is rolled back with the test, so the lock
stays. The class reinstall in tearDownAfterClass() then found a fresh
lock and did nothing, and every later install in the process did
nothing either: WC_Install_Test::test_version_check_schedules_db_auto_update
failed once nothing else happened to delete the lock.
The reinstall itself also left its last writes, including the lock
release, uncommitted, and the next class reconnects to the database,
which drops them. Clear the lock before the reinstall and commit after
it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test: Set up the email template REST test inside its transaction
setUp() wrote the block email editor flag before parent::setUp(), so
the write committed and every later test ran with the editor enabled;
its tearDown() restore ran inside the transaction and was rolled back.
Run the setup after parent::setUp(), and declare the incorrect usage
notice that firing init a second time raises when it registers the
block payment integrations again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test: Drop database writes that run after the test transaction
WordPress rolls back a test transaction inside parent::tearDown() and
leaves autocommit off, so a write after that call opens an implicit
transaction that the next test commits. Writes in setUp() before
parent::setUp() commit the same way. A query filter that logged writes
between a rollback and the next transaction found them in 33 places
across the suite; most undo changes the rollback already undoes, and
some committed the reverse of what they meant, such as deleting
options the bootstrap had set.
Delete those writes, or move them after parent::setUp(). Also delete
the ones a static scan found after the parent call that only stayed
silent because the database already held the value they restore, and
the hooks added after the restore: disable_rest_api_v4_feature() and
similar filters stayed attached for the whole next test. Remove the
helpers and properties that only fed them. In-memory resets and file
cleanup after the parent call stay.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/test-committed-teardown-writes b/plugins/woocommerce/changelog/test-committed-teardown-writes
new file mode 100644
index 00000000000..dda26631754
--- /dev/null
+++ b/plugins/woocommerce/changelog/test-committed-teardown-writes
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Stop PHPUnit tests writing to the database after their transaction rolls back; no production change.
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/core/test-wc-cancel-unpaid-orders.php b/plugins/woocommerce/tests/legacy/unit-tests/core/test-wc-cancel-unpaid-orders.php
index ddbbd01b428..b7fcc77ae63 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/core/test-wc-cancel-unpaid-orders.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/core/test-wc-cancel-unpaid-orders.php
@@ -13,20 +13,6 @@ declare(strict_types=1);
*/
class WC_Tests_Cancel_Unpaid_Orders extends WC_Unit_Test_Case {
- /**
- * Original hold stock minutes option value.
- *
- * @var int
- */
- public $original_hold_stock_minutes = 0;
-
- /**
- * Original manage stock option value.
- *
- * @var string
- */
- public $original_manage_stock_option = 'yes';
-
/**
* Set up test environment.
* @return void
@@ -36,8 +22,6 @@ class WC_Tests_Cancel_Unpaid_Orders extends WC_Unit_Test_Case {
// Don't allow actual order cancellations during tests.
add_filter( 'woocommerce_cancel_unpaid_order', '__return_false', 10, 0 );
- $this->original_hold_stock_minutes = get_option( 'woocommerce_hold_stock_minutes', 0 );
- $this->original_manage_stock_option = get_option( 'woocommerce_manage_stock', 'yes' );
}
/**
@@ -322,20 +306,4 @@ class WC_Tests_Cancel_Unpaid_Orders extends WC_Unit_Test_Case {
);
}
}
-
- /**
- * Clean up after tests.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- // Clean up scheduled actions and settings.
- if ( function_exists( 'as_unschedule_all_actions' ) ) {
- as_unschedule_all_actions( 'woocommerce_cancel_unpaid_orders' );
- }
- wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
-
- update_option( 'woocommerce_hold_stock_minutes', $this->original_hold_stock_minutes );
- update_option( 'woocommerce_manage_stock', $this->original_manage_stock_option );
- }
}
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/crud/data.php b/plugins/woocommerce/tests/legacy/unit-tests/crud/data.php
index 7e3b381c285..05e84e67a06 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/crud/data.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/crud/data.php
@@ -18,8 +18,6 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
// @codingStandardsIgnoreStart
date_default_timezone_set( 'UTC' );
// @codingStandardsIgnoreEnd
- update_option( 'gmt_offset', 0 );
- update_option( 'timezone_string', '' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/order-items/class-wc-tests-order-item-product.php b/plugins/woocommerce/tests/legacy/unit-tests/order-items/class-wc-tests-order-item-product.php
index 48f93ee3ec9..ec6beea819e 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/order-items/class-wc-tests-order-item-product.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/order-items/class-wc-tests-order-item-product.php
@@ -15,14 +15,6 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
use CogsAwareUnitTestSuiteTrait;
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_cogs_feature();
- }
-
/**
* Test generic setters and getters for WC_Order_Item_Product.
*
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/order-items/class-wc-tests-order-item.php b/plugins/woocommerce/tests/legacy/unit-tests/order-items/class-wc-tests-order-item.php
index e811e0b7fbb..7d5e5d54f58 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/order-items/class-wc-tests-order-item.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/order-items/class-wc-tests-order-item.php
@@ -49,14 +49,6 @@ class WC_Tests_Base_Order_Item extends WC_Unit_Test_Case {
// phpcs:enable Squiz.Commenting
}
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_cogs_feature();
- }
-
/**
* @testdox Order item classes don't manage Cost of Goods Sold by default.
*/
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/util/install.php b/plugins/woocommerce/tests/legacy/unit-tests/util/install.php
index 3c49527d2df..7e39de6fc40 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/util/install.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/util/install.php
@@ -18,8 +18,17 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
public static function tearDownAfterClass(): void {
parent::tearDownAfterClass();
- // Reinstall WooCommerce to ensure test environment is clean.
+ // The tests run installs inside their transaction. An install's schema changes commit the
+ // install lock it took, while its release is rolled back with the test, so the lock can
+ // still be there. Clear it, or this reinstall and every later one would do nothing.
+ delete_transient( 'wc_installing' );
+ delete_option( 'wc_installing' );
+
+ // Reinstall WooCommerce to ensure test environment is clean, and commit it: the next class
+ // reconnects to the database, which would drop the writes the install made after its last
+ // schema change, including the release of its lock.
WC_Install::install();
+ self::commit_transaction();
// Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374.
if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-taxes.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-taxes.php
index ecb6e76d726..4ee01fd328c 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-taxes.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-taxes.php
@@ -20,13 +20,6 @@ class WC_Admin_Tests_API_Reports_Taxes extends WC_REST_Unit_Test_Case {
*/
protected $endpoint = '/wc-analytics/reports/taxes';
- /**
- * Tax option.
- *
- * @var string
- */
- protected $original_tax_option;
-
/**
* Setup test reports taxes data.
*
@@ -35,7 +28,6 @@ class WC_Admin_Tests_API_Reports_Taxes extends WC_REST_Unit_Test_Case {
public function setUp(): void {
parent::setUp();
- $this->original_tax_option = get_option( 'woocommerce_calc_taxes' );
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->user = $this->factory->user->create(
array(
@@ -44,15 +36,6 @@ class WC_Admin_Tests_API_Reports_Taxes extends WC_REST_Unit_Test_Case {
);
}
- /**
- * Clean up after each test. DB changes are reverted in parent::tearDown().
- */
- public function tearDown(): void {
- parent::tearDown();
-
- update_option( 'woocommerce_calc_taxes', $this->original_tax_option );
- }
-
/**
* Test route registration.
*
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/category-lookup.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/category-lookup.php
index a6fbf16c814..8c8f5acd34e 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/category-lookup.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/category-lookup.php
@@ -26,10 +26,11 @@ class WC_Admin_Tests_Category_Lookup extends WP_UnitTestCase {
*/
public function setUp(): void {
+ parent::setUp();
+
delete_transient( 'wc_installing' );
delete_option( 'wc_installing' );
- parent::setUp();
$parent = wp_insert_term( 'test_parent', 'product_cat' );
$parent2 = wp_insert_term( 'test_parent_2', 'product_cat' );
$child = wp_insert_term(
@@ -45,16 +46,6 @@ class WC_Admin_Tests_Category_Lookup extends WP_UnitTestCase {
CategoryLookup::instance()->init();
}
- /**
- * Tear Down
- */
- public function tearDown(): void {
- parent::tearDown();
- wp_delete_term( $this->parent_term_id, 'product_cat' );
- wp_delete_term( $this->parent2_term_id, 'product_cat' );
- wp_delete_term( $this->child_term_id, 'product_cat' );
- }
-
/**
* @param int $category_id category id.
* @return int[] list of category tree ids
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/class-wc-tests-ces-tracks.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/class-wc-tests-ces-tracks.php
index 0a1fa3a1b0c..e33dbf57e00 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/class-wc-tests-ces-tracks.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/class-wc-tests-ces-tracks.php
@@ -54,7 +54,6 @@ class WC_Admin_Tests_CES_Tracks extends WC_Unit_Test_Case {
if ( $this->current_screen_backup ) {
$GLOBALS['current_screen'] = $this->current_screen_backup;
}
- update_option( 'woocommerce_allow_tracking', 'no' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/shipping.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/shipping.php
index e042010bb13..c70809a8395 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/shipping.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/tasks/shipping.php
@@ -41,16 +41,6 @@ class WC_Admin_Tests_OnboardingTasks_Task_Shipping extends WC_Unit_Test_Case {
}
- /**
- * Tear down.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- delete_option( OnboardingProfile::DATA_OPTION );
- }
-
-
/**
* Filter to enable shipping-smart-defaults feature.
*
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes-data-store.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes-data-store.php
index 04ebbbfea54..ee00063c491 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes-data-store.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes-data-store.php
@@ -494,14 +494,4 @@ class WC_Admin_Tests_Notes_Data_Store extends WC_Unit_Test_Case {
// When not explicitly passed, context should default to WC_ADMIN_NOTE_OPER_GLOBAL.
$this->assertEquals( $global_context, $global_context_received );
}
-
- /**
- * Delete notes created by this class's tests.
- */
- public function tearDown(): void {
- global $wpdb;
-
- parent::tearDown();
- $wpdb->query( $wpdb->prepare( 'DELETE n.*, a.* FROM ' . $wpdb->prefix . 'wc_admin_notes n JOIN ' . $wpdb->prefix . 'wc_admin_note_actions a ON n.note_id = a.note_id WHERE n.source = %s', 'PHPUNIT_TEST' ) );
- }
}
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/remote-inbox-notifications-engine.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/remote-inbox-notifications-engine.php
index d0af9632d95..24d0245762a 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/remote-inbox-notifications-engine.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/remote-inbox-notifications-engine.php
@@ -58,14 +58,6 @@ class WC_Admin_Tests_RemoteInboxNotifications_RemoteInboxNotificationsEngine ext
);
}
- /**
- * Tear down.
- */
- public function tearDown(): void {
- parent::tearDown();
- delete_transient( 'woocommerce_admin_' . RemoteInboxNotificationsDataSourcePoller::ID . '_specs' );
- }
-
/**
* Tests get_note_from_db function with a invalid note.
diff --git a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php
index b3c0c761e4e..f32410fd931 100644
--- a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php
+++ b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php
@@ -402,7 +402,6 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
$this->registered_order_statuses = array();
parent::tearDown();
- $this->disable_cogs_feature();
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-product-test.php b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-product-test.php
index f8e0be26056..70056844033 100644
--- a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-product-test.php
+++ b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-product-test.php
@@ -16,7 +16,6 @@ class WC_Abstract_Product_Test extends WC_Unit_Test_Case {
*/
public function tearDown(): void {
parent::tearDown();
- $this->disable_cogs_feature();
self::disable_direct_product_attribute_lookup_updates();
}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-brands-test.php b/plugins/woocommerce/tests/php/includes/class-wc-brands-test.php
index 2242722b269..691cd095271 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-brands-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-brands-test.php
@@ -58,9 +58,6 @@ class WC_Brands_Test extends WC_Unit_Test_Case {
public function tearDown(): void {
$this->remove_added_uploads();
parent::tearDown();
-
- // Clear term cache to prevent interference between tests.
- clean_term_cache( array(), 'product_brand' );
}
/**
* Test that `product_brand_thumbnails` shortcode's `show_empty` argument works as expected.
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-frontend-scripts-test.php b/plugins/woocommerce/tests/php/includes/class-wc-frontend-scripts-test.php
index 222c7a5a42f..5d4c38ae8be 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-frontend-scripts-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-frontend-scripts-test.php
@@ -30,8 +30,6 @@ class WC_Frontend_Scripts_Test extends WC_Unit_Test_Case {
// Reinitialize payment gateways to clean state.
WC()->payment_gateways()->init();
-
- delete_option( 'jetpack_activation_source' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-order-item-product-test.php b/plugins/woocommerce/tests/php/includes/class-wc-order-item-product-test.php
index de1722093b6..253291e0104 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-order-item-product-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-order-item-product-test.php
@@ -56,14 +56,6 @@ class WC_Order_Item_Product_Test extends WC_Unit_Test_Case {
$this->order->save();
}
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_cogs_feature();
- }
-
/**
* @testdox Formatting metadata preserves raw keys and values across repeated calls and saves.
* @testWith ["Finish%20type", "Black%2520White", "Finish type", "Black%20White"]
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-payment-gateways-test.php b/plugins/woocommerce/tests/php/includes/class-wc-payment-gateways-test.php
index 7a43f657ebe..820df3ac3b8 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-payment-gateways-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-payment-gateways-test.php
@@ -29,14 +29,6 @@ class WC_Payment_Gateways_Test extends WC_Unit_Test_Case {
$this->sut = new WC_Payment_Gateways();
}
- /**
- * Tear down test fixtures.
- */
- public function tearDown(): void {
- parent::tearDown();
- delete_option( 'jetpack_activation_source' );
- }
-
/**
* @testdox Gateway settings option changes use gateway defaults for malformed transition values.
* @dataProvider provider_malformed_gateway_settings_transitions
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-product-variation-test.php b/plugins/woocommerce/tests/php/includes/class-wc-product-variation-test.php
index 29c6918b560..cc06d4795be 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-product-variation-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-product-variation-test.php
@@ -31,14 +31,6 @@ class WC_Product_Variation_Test extends WC_Unit_Test_Case {
$this->variation = wc_get_product( $this->parent_product->get_children()[0] );
}
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_cogs_feature();
- }
-
/**
* @testdox By default the defined Cost of Goods Sold is null, and the value is absolute.
*/
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-shipping-test.php b/plugins/woocommerce/tests/php/includes/class-wc-shipping-test.php
index d96f3a39c6b..0648515a02d 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-shipping-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-shipping-test.php
@@ -33,7 +33,7 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
}
/**
- * Restore options.
+ * Restore the customer shipping address.
*/
public function tearDown(): void {
foreach ( $this->previous_shipping_address as $key => $value ) {
@@ -41,9 +41,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
}
parent::tearDown();
-
- update_option( 'woocommerce_shipping_debug_mode', 'no' );
- update_option( 'woocommerce_shipping_hide_rates_when_free', 'no' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-shipping-zones-test.php b/plugins/woocommerce/tests/php/includes/class-wc-shipping-zones-test.php
index 46b4308a055..11b8365d319 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-shipping-zones-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-shipping-zones-test.php
@@ -21,15 +21,6 @@ class WC_Shipping_Zones_Test extends WC_Unit_Test_Case {
WC_Helper_Shipping_Zones::remove_mock_zones();
}
- /**
- * Clean up after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- WC_Helper_Shipping_Zones::remove_mock_zones();
- }
-
/**
* @testdox Should warn when a postcode zone is below a broader state zone.
*/
diff --git a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-customer-download-data-store-test.php b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-customer-download-data-store-test.php
index 56903475ad6..d211cd3a774 100644
--- a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-customer-download-data-store-test.php
+++ b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-customer-download-data-store-test.php
@@ -124,11 +124,6 @@ class WC_Customer_Download_Data_Store_Test extends WC_Unit_Test_Case {
public function tearDown(): void {
parent::tearDown();
- // Clean up Customer Downloads.
- foreach ( $this->downloads as $download ) {
- $download->delete();
- }
-
// Clear temp instance variables.
$this->customers = array();
$this->downloads = array();
diff --git a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-order-item-data-store-test.php b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-order-item-data-store-test.php
index 4c3f7f6f107..f38817e7fc7 100644
--- a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-order-item-data-store-test.php
+++ b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-order-item-data-store-test.php
@@ -29,14 +29,6 @@ class WC_Order_Item_Data_Store_Test extends WC_Unit_Test_Case {
self::$order_item_data_store = WC_Data_Store::load( 'order-item' );
}
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_cogs_feature();
- }
-
/**
* @testdox The Cost of Goods Sold value for order items is not persisted when the item is saved if the feature is disabled.
*/
diff --git a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-data-store-cpt-test.php b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-data-store-cpt-test.php
index b03f49db272..173cb910172 100644
--- a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-data-store-cpt-test.php
+++ b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-data-store-cpt-test.php
@@ -8,14 +8,6 @@ use Automattic\WooCommerce\Internal\CostOfGoodsSold\CogsAwareUnitTestSuiteTrait;
class WC_Product_Data_Store_CPT_Test extends WC_Unit_Test_Case {
use CogsAwareUnitTestSuiteTrait;
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_cogs_feature();
- }
-
/**
* @testdox Variations should appear when searching for parent product's SKU.
*/
diff --git a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-variations-data-store-cpt-test.php b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-variations-data-store-cpt-test.php
index 54cdb6087d2..c328d74344a 100644
--- a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-variations-data-store-cpt-test.php
+++ b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-variations-data-store-cpt-test.php
@@ -26,14 +26,6 @@ class WC_Product_Variation_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$this->data_store = new WC_Product_Variation_Data_Store_CPT();
}
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_cogs_feature();
- }
-
/**
* Test that read_product_data loads basic variation properties correctly
*/
diff --git a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-header-template-test.php b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-header-template-test.php
index dc1b96a1498..de0566e6e31 100644
--- a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-header-template-test.php
+++ b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-header-template-test.php
@@ -8,15 +8,6 @@ declare( strict_types = 1 );
*/
class WC_Email_Header_Template_Test extends \WC_Unit_Test_Case {
- /**
- * Tear down after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- delete_option( 'woocommerce_email_header_image' );
- update_option( 'woocommerce_feature_email_improvements_enabled', 'no' );
- }
-
/**
* @testdox Email header template includes blog name when store name is not set.
*/
diff --git a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-order-details-rtl-test.php b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-order-details-rtl-test.php
index 0558c5078a8..0a898747e8e 100644
--- a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-order-details-rtl-test.php
+++ b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-order-details-rtl-test.php
@@ -13,7 +13,6 @@ class WC_Email_Order_Details_RTL_Test extends \WC_Unit_Test_Case {
*/
public function tearDown(): void {
parent::tearDown();
- update_option( 'woocommerce_feature_email_improvements_enabled', 'no' );
$GLOBALS['wp_locale']->text_direction = 'ltr';
}
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller-tests.php
index e1461af9627..d836a765e85 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller-tests.php
@@ -112,7 +112,6 @@ class WC_REST_Product_Variations_Controller_Tests extends WC_Unit_Test_Case {
parent::tearDown();
$this->clear_rest_server();
unset( $this->server, $this->controller );
- $this->disable_cogs_feature();
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller-tests.php
index 146ff34720e..df2b9b2409b 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller-tests.php
@@ -41,12 +41,6 @@ class WC_REST_Products_Controller_Tests extends WC_Unit_Test_Case {
*/
protected static $fixture_user;
- /**
- * Saves the `woocommerce_hide_out_of_stock_items` option value for restoration after tests that modify it.
- * @var mixed
- */
- protected $original_hid_out_of_stock_value;
-
/**
* Runs after each test.
*/
@@ -54,8 +48,6 @@ class WC_REST_Products_Controller_Tests extends WC_Unit_Test_Case {
parent::tearDown();
$this->clear_rest_server();
unset( $this->server, $this->endpoint );
- $this->disable_cogs_feature();
- update_option( 'woocommerce_hide_out_of_stock_items', $this->original_hid_out_of_stock_value );
}
/**
@@ -149,8 +141,6 @@ class WC_REST_Products_Controller_Tests extends WC_Unit_Test_Case {
);
$this->user = self::$fixture_user;
wp_set_current_user( $this->user );
-
- $this->original_hid_out_of_stock_value = get_option( 'woocommerce_hide_out_of_stock_items' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Customers/class-wc-rest-customers-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Customers/class-wc-rest-customers-v4-controller-tests.php
index 513f6e66d57..9280437fa69 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Customers/class-wc-rest-customers-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Customers/class-wc-rest-customers-v4-controller-tests.php
@@ -17,13 +17,6 @@ use Automattic\WooCommerce\RestApi\UnitTests\HPOSToggleTrait;
class WC_REST_Customers_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
use HPOSToggleTrait;
- /**
- * Created customers for cleanup.
- *
- * @var array
- */
- private $created_customers = array();
-
/**
* Endpoint instance.
*
@@ -58,15 +51,6 @@ class WC_REST_Customers_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
);
}
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->cleanup_test_customers();
- $this->disable_rest_api_v4_feature();
- }
-
/**
* Enable the REST API v4 feature.
*/
@@ -80,19 +64,6 @@ class WC_REST_Customers_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
);
}
- /**
- * Disable the REST API v4 feature.
- */
- public static function disable_rest_api_v4_feature() {
- add_filter(
- 'woocommerce_admin_features',
- function ( $features ) {
- $features = array_diff( $features, array( 'rest-api-v4' ) );
- return $features;
- }
- );
- }
-
/**
* Setup our test server, endpoints, and user info.
*/
@@ -113,18 +84,6 @@ class WC_REST_Customers_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
wp_set_current_user( self::$administrator_id );
}
- /**
- * Clean up customers created during tests.
- */
- private function cleanup_test_customers(): void {
- foreach ( $this->created_customers as $customer_id ) {
- if ( $customer_id && get_userdata( $customer_id ) ) {
- wp_delete_user( $customer_id );
- }
- }
- $this->created_customers = array();
- }
-
/**
* Helper method to create a test customer.
*
@@ -168,11 +127,7 @@ class WC_REST_Customers_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
$this->assertEquals( 201, $response->get_status() );
$data = $response->get_data();
- $customer = new WC_Customer( $data['id'] );
-
- $this->created_customers[] = $customer->get_id();
-
- return $customer;
+ return new WC_Customer( $data['id'] );
}
/**
@@ -1129,8 +1084,6 @@ class WC_REST_Customers_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
$response_data = $response->get_data();
$this->assertNotEmpty( $response_data['username'] );
$this->assertEquals( 'nousernameorpassword@example.com', $response_data['email'] );
-
- $this->created_customers[] = $response_data['id'];
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/OrderNotes/class-wc-rest-order-notes-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/OrderNotes/class-wc-rest-order-notes-v4-controller-tests.php
index e153cb2b5d6..dbd251eac53 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/OrderNotes/class-wc-rest-order-notes-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/OrderNotes/class-wc-rest-order-notes-v4-controller-tests.php
@@ -26,14 +26,6 @@ class WC_REST_Order_Notes_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
*/
protected static $user;
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_rest_api_v4_feature();
- }
-
/**
* Enable the REST API v4 feature.
*/
@@ -47,19 +39,6 @@ class WC_REST_Order_Notes_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
);
}
- /**
- * Disable the REST API v4 feature.
- */
- public static function disable_rest_api_v4_feature() {
- add_filter(
- 'woocommerce_admin_features',
- function ( $features ) {
- $features = array_diff( $features, array( 'rest-api-v4' ) );
- return $features;
- }
- );
- }
-
/**
* Create the shared admin user once for the whole class.
*
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-can-be-refunded-test.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-can-be-refunded-test.php
index 45ea7915f58..a847f63f318 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-can-be-refunded-test.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-can-be-refunded-test.php
@@ -25,16 +25,6 @@ class WC_REST_Orders_V4_Can_Be_Refunded_Test extends WC_REST_Unit_Test_Case {
);
}
- /**
- * Disable the REST API v4 feature.
- */
- private static function disable_rest_api_v4_feature(): void {
- remove_filter(
- 'woocommerce_admin_features',
- array( __CLASS__, 'add_v4_feature' ),
- );
- }
-
/**
* Filter callback to add the rest-api-v4 feature.
*
@@ -65,14 +55,6 @@ class WC_REST_Orders_V4_Can_Be_Refunded_Test extends WC_REST_Unit_Test_Case {
wp_set_current_user( self::$user_id );
}
- /**
- * Tear down test fixtures.
- */
- public function tearDown(): void {
- parent::tearDown();
- self::disable_rest_api_v4_feature();
- }
-
/**
* Helper to get a single order via the v4 API.
*
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-controller-tests.php
index b292682eb0f..25b79f97d73 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-controller-tests.php
@@ -43,14 +43,6 @@ class WC_REST_Orders_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
*/
private $order_schema;
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
- $this->disable_rest_api_v4_feature();
- }
-
/**
* Enable the REST API v4 feature.
*/
@@ -64,19 +56,6 @@ class WC_REST_Orders_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
);
}
- /**
- * Disable the REST API v4 feature.
- */
- public static function disable_rest_api_v4_feature() {
- add_filter(
- 'woocommerce_admin_features',
- function ( $features ) {
- $features = array_diff( $features, array( 'rest-api-v4' ) );
- return $features;
- }
- );
- }
-
/**
* Create the shared admin user once for the whole class.
*
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-controller-tests.php
index 9264182e799..1a1a12ab787 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-controller-tests.php
@@ -108,7 +108,6 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
self::disable_direct_product_attribute_lookup_updates();
parent::tearDown();
- $this->disable_rest_api_v4_feature();
}
/**
@@ -124,19 +123,6 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
);
}
- /**
- * Disable the REST API v4 feature.
- */
- public static function disable_rest_api_v4_feature() {
- add_filter(
- 'woocommerce_admin_features',
- function ( $features ) {
- $features = array_diff( $features, array( 'rest-api-v4' ) );
- return $features;
- }
- );
- }
-
/**
* Setup our test server, endpoints, and user info.
*/
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-preview-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-preview-tests.php
index 204578c828d..60bbea6d39f 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-preview-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-preview-tests.php
@@ -38,19 +38,6 @@ class WC_REST_Refunds_V4_Preview_Tests extends WC_REST_Unit_Test_Case {
);
}
- /**
- * Disable the REST API v4 feature.
- */
- public static function disable_rest_api_v4_feature() {
- add_filter(
- 'woocommerce_admin_features',
- function ( $features ) {
- $features = array_diff( $features, array( 'rest-api-v4' ) );
- return $features;
- }
- );
- }
-
/**
* Create the shared admin user once per class.
*/
@@ -99,7 +86,6 @@ class WC_REST_Refunds_V4_Preview_Tests extends WC_REST_Unit_Test_Case {
$this->created_orders = array();
parent::tearDown();
- $this->disable_rest_api_v4_feature();
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/AssetsController.php b/plugins/woocommerce/tests/php/src/Blocks/AssetsController.php
index d49820f0c6f..0a5274e4f8c 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/AssetsController.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/AssetsController.php
@@ -65,16 +65,13 @@ class AssetsController extends \WP_UnitTestCase {
}
/**
- * Clean up mock dependencies and pages after each test.
+ * Clean up mock dependencies and the cart after each test.
*
* @return void
*/
public function tearDown(): void {
parent::tearDown();
- wp_delete_post( get_option( 'woocommerce_checkout_page_id' ), true );
- delete_option( 'woocommerce_checkout_page_id' );
-
wc()->cart->empty_cart();
global $wp_scripts;
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
index 06dff1217b2..08d8f5944d0 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
@@ -48,14 +48,6 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
new WC_Emails();
}
- /**
- * Tear down.
- */
- public function tearDown(): void {
- parent::tearDown();
- update_option( 'woocommerce_feature_email_improvements_enabled', 'no' );
- }
-
/**
* Tests that it returns processing order email preview.
*/
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/FullRefundFixDataToolNoticeTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/FullRefundFixDataToolNoticeTest.php
index 1249f970b51..3cbd666f607 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/FullRefundFixDataToolNoticeTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/FullRefundFixDataToolNoticeTest.php
@@ -142,26 +142,4 @@ class FullRefundFixDataToolNoticeTest extends WC_Unit_Test_Case {
$this->assertEmpty( $note_ids, 'Note should be removed once the store no longer has legacy refund data' );
}
-
- /**
- * Clean up after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- $data_store = \WC_Data_Store::load( 'admin-note' );
- $note_ids = $data_store->get_notes_with_name( FullRefundFixDataToolNotice::NOTE_NAME );
-
- foreach ( $note_ids as $note_id ) {
- $note = \Automattic\WooCommerce\Admin\Notes\Notes::get_note( $note_id );
- if ( $note ) {
- $note->delete();
- }
- }
-
- delete_option( 'woocommerce_analytics_enabled' );
- delete_option( 'woocommerce_db_version' );
- delete_option( 'woocommerce_analytics_uses_old_full_refund_data' );
- delete_option( 'woocommerce_analytics_show_old_refund_data_tool' );
- }
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/ScheduledUpdatesPromotionTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/ScheduledUpdatesPromotionTest.php
index 50e2fbdab1d..536b32885ac 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/ScheduledUpdatesPromotionTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Notes/ScheduledUpdatesPromotionTest.php
@@ -139,25 +139,4 @@ class ScheduledUpdatesPromotionTest extends WC_Unit_Test_Case {
// Verify option was NOT updated (still null/doesn't exist).
$this->assertFalse( get_option( 'woocommerce_analytics_scheduled_import' ), 'Option should not exist' );
}
-
- /**
- * Clean up after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- // Delete all test notes.
- $data_store = \WC_Data_Store::load( 'admin-note' );
- $note_ids = $data_store->get_notes_with_name( ScheduledUpdatesPromotion::NOTE_NAME );
-
- foreach ( $note_ids as $note_id ) {
- $note = \Automattic\WooCommerce\Admin\Notes\Notes::get_note( $note_id );
- if ( $note ) {
- $note->delete();
- }
- }
-
- // Reset options.
- delete_option( 'woocommerce_analytics_scheduled_import' );
- }
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php
index df1e908a917..783c05825bf 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php
@@ -15,13 +15,6 @@ use WC_Unit_Test_Case;
* @covers \Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\Init
*/
class InitTest extends WC_Unit_Test_Case {
- /**
- * Raw option states before the test fixture mutates them.
- *
- * @var array<string, array{exists: bool, value: string|null, autoload: string|null}>
- */
- private array $initial_option_states = array();
-
/** @var callable|null Filter used to provide local remote-extension specs. */
private $specs_transient_filter;
@@ -34,12 +27,9 @@ class InitTest extends WC_Unit_Test_Case {
public function setUp(): void {
parent::setUp();
- $this->assertFalse( (bool) wp_using_ext_object_cache(), 'This test requires database-backed transients for exact restoration.' );
+ $this->assertFalse( (bool) wp_using_ext_object_cache(), 'This test requires database-backed transients so that the rollback removes them.' );
$this->assert_option_cache_matches_raw_state( 'woocommerce_default_country' );
$this->assert_option_cache_matches_raw_state( 'woocommerce_show_marketplace_suggestions' );
- foreach ( $this->get_restored_option_names() as $option_name ) {
- $this->initial_option_states[ $option_name ] = $this->get_raw_option_state( $option_name );
- }
$this->fixture_setup_started = true;
$this->user = $this->factory->user->create(
@@ -99,33 +89,10 @@ class InitTest extends WC_Unit_Test_Case {
RemoteFreeExtensions::delete_specs_transient();
}
} finally {
- try {
- parent::tearDown();
- } finally {
- if ( $this->fixture_setup_started ) {
- $failures = $this->restore_initial_option_states();
- $this->assert_initial_option_states_restored( $failures );
- }
- }
+ parent::tearDown();
}
}
- /**
- * Get option rows that must survive each fixture scope exactly.
- *
- * @return string[]
- */
- private function get_restored_option_names(): array {
- $transient_name = $this->get_specs_transient_name();
-
- return array(
- 'woocommerce_default_country',
- 'woocommerce_show_marketplace_suggestions',
- '_transient_' . $transient_name,
- '_transient_timeout_' . $transient_name,
- );
- }
-
/**
* Get the specs transient name.
*
@@ -179,93 +146,6 @@ class InitTest extends WC_Unit_Test_Case {
$this->assertSame( $expected, get_option( $option_name ) );
}
- /**
- * Restore every captured option and invalidate its caches.
- *
- * @return string[] Restoration failures.
- */
- private function restore_initial_option_states(): array {
- $failures = array();
- foreach ( $this->initial_option_states as $option_name => $state ) {
- try {
- if ( ! $this->restore_raw_option_state( $option_name, $state ) ) {
- $failures[] = "Database write failed for {$option_name}.";
- }
- } catch ( \Throwable $error ) {
- $failures[] = $error->getMessage();
- }
- }
-
- return $failures;
- }
-
- /**
- * Verify raw rows and option caches after parent teardown and restoration.
- *
- * @param string[] $failures Existing restoration failures.
- */
- private function assert_initial_option_states_restored( array $failures ): void {
- foreach ( $this->initial_option_states as $option_name => $state ) {
- try {
- if ( $state !== $this->get_raw_option_state( $option_name ) ) {
- $failures[] = "Restored row does not match the captured state for {$option_name}.";
- }
- $expected = $state['exists'] ? maybe_unserialize( $state['value'] ) : false;
- if ( maybe_serialize( get_option( $option_name ) ) !== maybe_serialize( $expected ) ) {
- $failures[] = "Option cache does not match the captured state for {$option_name}.";
- }
- } catch ( \Throwable $error ) {
- $failures[] = $error->getMessage();
- }
- }
-
- $this->assertSame( array(), $failures, implode( ' ', $failures ) );
- }
-
- /**
- * Restore an option without invoking setting sanitizers.
- *
- * @param string $option_name Option name.
- * @param array{exists: bool, value: string|null, autoload: string|null} $state Raw option state.
- * @return bool Whether the database operation succeeded.
- */
- private function restore_raw_option_state( string $option_name, array $state ): bool {
- global $wpdb;
-
- try {
- if ( ! $state['exists'] ) {
- $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option_name ) );
- } elseif ( $this->get_raw_option_state( $option_name )['exists'] ) {
- $result = $wpdb->update(
- $wpdb->options,
- array(
- 'option_value' => $state['value'],
- 'autoload' => $state['autoload'],
- ),
- array( 'option_name' => $option_name )
- );
- } else {
- $result = $wpdb->insert(
- $wpdb->options,
- array(
- 'option_name' => $option_name,
- 'option_value' => $state['value'],
- 'autoload' => $state['autoload'],
- )
- );
- }
-
- return false !== $result;
- } finally {
- wp_cache_delete( $option_name, 'options' );
- wp_cache_delete( 'alloptions', 'options' );
- wp_cache_delete( 'notoptions', 'options' );
- if ( 0 === strpos( $option_name, '_transient_' ) ) {
- wp_cache_delete( substr( $option_name, strlen( '_transient_' ) ), 'transient' );
- }
- }
- }
-
/**
* Test that default extensions are provided when remote sources don't exist.
*/
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
index 9059ffbb4bd..1320ddd7adc 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
@@ -29,25 +29,6 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
update_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION, 'yes' );
}
- /**
- * Tear down the test environment.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- // Clean up options.
- delete_option( OrdersScheduler::LAST_PROCESSED_ORDER_DATE_OPTION );
- delete_option( OrdersScheduler::LAST_PROCESSED_ORDER_ID_OPTION );
- delete_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION );
- delete_option( OrdersScheduler::LEGACY_IMMEDIATE_IMPORT_OPTION );
- delete_option( OrdersScheduler::FAILED_ORDER_IMPORTS_OPTION );
-
- // Clean up any scheduled actions.
- $this->clear_scheduled_batch_processor();
-
- delete_option( OrdersScheduler::SCHEDULED_IMPORT_OPTION );
- }
-
/**
* Hook the import filter that keeps child orders out of Analytics, for the active order storage.
*/
diff --git a/plugins/woocommerce/tests/php/src/Internal/Email/EmailStyleSyncTest.php b/plugins/woocommerce/tests/php/src/Internal/Email/EmailStyleSyncTest.php
index 07e89bcc649..b4c6ea58b9a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Email/EmailStyleSyncTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Email/EmailStyleSyncTest.php
@@ -19,13 +19,6 @@ class EmailStyleSyncTest extends WC_Unit_Test_Case {
*/
private $sut;
- /**
- * Original option values to restore after tests.
- *
- * @var array
- */
- private $original_options;
-
/**
* Set up.
*/
@@ -33,36 +26,10 @@ class EmailStyleSyncTest extends WC_Unit_Test_Case {
parent::setUp();
$this->sut = new EmailStyleSync();
- // Store original option values.
- $this->original_options = array(
- EmailStyleSync::AUTO_SYNC_OPTION => get_option( EmailStyleSync::AUTO_SYNC_OPTION, false ),
- 'woocommerce_email_base_color' => get_option( 'woocommerce_email_base_color', '' ),
- 'woocommerce_email_background_color' => get_option( 'woocommerce_email_background_color', '' ),
- 'woocommerce_email_body_background_color' => get_option( 'woocommerce_email_body_background_color', '' ),
- 'woocommerce_email_text_color' => get_option( 'woocommerce_email_text_color', '' ),
- 'woocommerce_email_footer_text_color' => get_option( 'woocommerce_email_footer_text_color', '' ),
- );
-
// Ensure we have a clean state for each test.
delete_option( EmailStyleSync::AUTO_SYNC_OPTION );
}
- /**
- * Tear down.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- // Restore original option values.
- foreach ( $this->original_options as $option_name => $option_value ) {
- if ( $option_value ) {
- update_option( $option_name, $option_value );
- } else {
- delete_option( $option_name );
- }
- }
- }
-
/**
* Test auto-sync is disabled by default.
*/
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/BlockEmailRendererTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/BlockEmailRendererTest.php
index 12c3b6926be..58f421d5042 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/BlockEmailRendererTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/BlockEmailRendererTest.php
@@ -419,7 +419,6 @@ class BlockEmailRendererTest extends \WC_Unit_Test_Case {
public function tearDown(): void {
parent::tearDown();
WCTransactionalEmailPostsManager::get_instance()->clear_caches();
- update_option( 'woocommerce_feature_block_email_editor_enabled', 'no' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/EmailApiControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/EmailApiControllerTest.php
index d6c72e5364b..816d5cb600d 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/EmailApiControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/EmailApiControllerTest.php
@@ -65,8 +65,6 @@ class EmailApiControllerTest extends \WC_Unit_Test_Case {
*/
public function tearDown(): void {
parent::tearDown();
- update_option( 'woocommerce_feature_block_email_editor_enabled', 'no' );
- delete_option( 'woocommerce_' . $this->email_type . '_settings' );
WCEmailTemplateSyncRegistry::reset_cache();
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateMetaRestExposureTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateMetaRestExposureTest.php
index 0e98ab34ad5..fda7f6d27ae 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateMetaRestExposureTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateMetaRestExposureTest.php
@@ -29,26 +29,19 @@ use WP_REST_Request;
*/
class WCEmailTemplateMetaRestExposureTest extends \WC_REST_Unit_Test_Case {
- /**
- * Previous value of the email editor feature flag, captured in setUp() so we
- * can deterministically restore the original state in tearDown() and avoid
- * order-dependent failures when other tests touch the same option.
- *
- * @var string|false|null Either the previous option value (string), `false`
- * when the option did not exist, or `null` before setUp() runs.
- */
- private $previous_feature_flag_value = null;
-
/**
* Setup test case.
*
- * The bootstrap order matters: WC_REST_Unit_Test_Case::setUp() fires
- * `rest_api_init` after `parent::setUp()`, so the woo_email post type and its
- * meta must be registered before the parent setup runs — otherwise the post
- * type's REST routes never get registered and GET wp/v2/woo_email returns 404.
+ * Everything runs after `parent::setUp()` so the option write and the `init` side effects
+ * stay inside the test transaction. The woo_email post type and its meta are registered
+ * before the first request, which is when the lazy REST server fires `rest_api_init`.
*/
public function setUp(): void {
- $this->previous_feature_flag_value = get_option( 'woocommerce_feature_block_email_editor_enabled', false );
+ parent::setUp();
+
+ // Firing init again registers the block payment integrations a second time.
+ $this->setExpectedIncorrectUsage( 'Automattic\\WooCommerce\\Blocks\\Integrations\\IntegrationRegistry::register' );
+
update_option( 'woocommerce_feature_block_email_editor_enabled', 'yes' );
wc_get_container()->get( Package::class )->init();
wc_get_container()->get( Integration::class )->initialize();
@@ -60,20 +53,6 @@ class WCEmailTemplateMetaRestExposureTest extends \WC_REST_Unit_Test_Case {
* @since 1.5.0
*/
do_action( 'init' );
-
- parent::setUp();
- }
-
- /**
- * Cleanup after test.
- */
- public function tearDown(): void {
- if ( false === $this->previous_feature_flag_value ) {
- delete_option( 'woocommerce_feature_block_email_editor_enabled' );
- } else {
- update_option( 'woocommerce_feature_block_email_editor_enabled', $this->previous_feature_flag_value );
- }
- parent::tearDown();
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailPostsManagerTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailPostsManagerTest.php
index fb04138bee9..c5de3a6c304 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailPostsManagerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailPostsManagerTest.php
@@ -466,6 +466,5 @@ class WCTransactionalEmailPostsManagerTest extends \WC_Unit_Test_Case {
public function tearDown(): void {
parent::tearDown();
$this->template_manager->clear_caches();
- update_option( 'woocommerce_feature_block_email_editor_enabled', 'no' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailsTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailsTest.php
index f97fc8d51ed..6e054e03df2 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCTransactionalEmailsTest.php
@@ -77,12 +77,4 @@ class WCTransactionalEmailsTest extends \WC_Unit_Test_Case {
( new WCTransactionalEmails() )->init_email_templates();
}
-
- /**
- * Cleanup after test.
- */
- public function tearDown(): void {
- parent::tearDown();
- update_option( 'woocommerce_feature_block_email_editor_enabled', 'no' );
- }
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/AsyncGeneratorTest.php b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/AsyncGeneratorTest.php
index ac2a05810a8..c9d923ab9b9 100644
--- a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/AsyncGeneratorTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/AsyncGeneratorTest.php
@@ -64,9 +64,6 @@ class AsyncGeneratorTest extends \WC_Unit_Test_Case {
*/
public function tearDown(): void {
parent::tearDown();
-
- delete_option( self::OPTION_KEY );
- delete_option( self::OPTION_KEY . '_chunk_size' );
$this->test_container->reset_all_replacements();
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsAddToCartTest.php b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsAddToCartTest.php
index 4bc5bb69dde..66bdf6da3a4 100644
--- a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsAddToCartTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsAddToCartTest.php
@@ -49,22 +49,6 @@ class ProductsAddToCartTest extends WC_REST_Unit_Test_Case {
wp_set_current_user( self::$user );
}
- /**
- * Runs after each test.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- // Disable the REST API v4 feature.
- add_filter(
- 'woocommerce_admin_features',
- function ( $features ) {
- $features = array_diff( $features, array( 'rest-api-v4' ) );
- return $features;
- }
- );
- }
-
/**
* Test that add_to_cart data is correctly populated in product responses.
*
diff --git a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsControllerTest.php
index b95b9e532c6..ea0922ff8b6 100644
--- a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsControllerTest.php
@@ -40,8 +40,6 @@ class ProductsControllerTest extends WC_Unit_Test_Case {
unset( $this->server );
parent::tearDown();
- $this->disable_cogs_feature();
- $this->disable_rest_api_v4_feature();
}
/**
@@ -57,19 +55,6 @@ class ProductsControllerTest extends WC_Unit_Test_Case {
);
}
- /**
- * Disable the REST API v4 feature.
- */
- public static function disable_rest_api_v4_feature() {
- add_filter(
- 'woocommerce_admin_features',
- function ( $features ) {
- $features = array_diff( $features, array( 'rest-api-v4' ) );
- return $features;
- }
- );
- }
-
/**
* @var WC_Product_Simple[]
*/
diff --git a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Settings/Emails/EmailsSettingsControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Settings/Emails/EmailsSettingsControllerTest.php
index 986c114c724..fc152ad0ed1 100644
--- a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Settings/Emails/EmailsSettingsControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Settings/Emails/EmailsSettingsControllerTest.php
@@ -110,8 +110,6 @@ class EmailsSettingsControllerTest extends WC_Unit_Test_Case {
$this->previous_emails_instance = $instance_property->getValue();
$this->previous_emails = $this->previous_emails_instance ? $this->previous_emails_instance->emails : array();
- $this->prev_options['woocommerce_feature_block_email_editor_enabled'] = get_option( 'woocommerce_feature_block_email_editor_enabled', null );
-
parent::setUp();
// Enable the v4 REST API feature.
@@ -168,9 +166,6 @@ class EmailsSettingsControllerTest extends WC_Unit_Test_Case {
* Tear down.
*/
public function tearDown(): void {
- $block_email_editor_option = $this->prev_options['woocommerce_feature_block_email_editor_enabled'];
- unset( $this->prev_options['woocommerce_feature_block_email_editor_enabled'] );
-
try {
// Restore previous option values.
foreach ( $this->prev_options as $key => $value ) {
@@ -198,11 +193,6 @@ class EmailsSettingsControllerTest extends WC_Unit_Test_Case {
$instance_property->setAccessible( true );
$instance_property->setValue( null, $this->previous_emails_instance );
} finally {
- if ( null === $block_email_editor_option ) {
- delete_option( 'woocommerce_feature_block_email_editor_enabled' );
- } else {
- update_option( 'woocommerce_feature_block_email_editor_enabled', $block_email_editor_option );
- }
$this->previous_emails = array();
$this->previous_emails_instance = null;
$this->prev_options = array();