From 616616628465c9f209a988d2c334213bc115c2cc Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Mon, 18 Mar 2024 16:27:32 +0100 Subject: [PATCH] Fix test interdependency (#13) * Fix test interdependency Fix test interdependency * Fix wctestcase. --- src/WCAjaxTestCase.php | 22 ++++++++++++++++++++++ src/WCTestCase.php | 24 ++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/WCAjaxTestCase.php b/src/WCAjaxTestCase.php index 088efc2..527f67e 100644 --- a/src/WCAjaxTestCase.php +++ b/src/WCAjaxTestCase.php @@ -5,6 +5,8 @@ use Codeception\TestCase\WPAjaxTestCase; class WCAjaxTestCase extends WPAjaxTestCase { + private $original_acf_stores; + /** * @return WC_UnitTest_Factory */ @@ -15,4 +17,24 @@ protected static function factory() { } return $factory; } + + public function _setUp() + { + parent::_setUp(); + global $acf_stores; + $this->original_acf_stores = serialize( $acf_stores ); + WC()->shipping()->unregister_shipping_methods(); + WC()->shipping()->reset_shipping(); + WC()->cart = null; + WC()->session = null; + WC()->customer = null; + wc_load_cart(); + } + + public function _tearDown() + { + parent::_tearDown(); + global $acf_stores; + $acf_stores = unserialize($this->original_acf_stores); + } } diff --git a/src/WCTestCase.php b/src/WCTestCase.php index 8828757..c29159c 100644 --- a/src/WCTestCase.php +++ b/src/WCTestCase.php @@ -5,10 +5,7 @@ use Codeception\TestCase\WPTestCase; class WCTestCase extends WPTestCase { - private $original_cart; - private $original_session; - private $original_customer; - private $original_query; + private $original_acf_stores; /** * @return WC_UnitTest_Factory @@ -24,18 +21,21 @@ protected static function factory() { public function _setUp() { parent::_setUp(); - $this->original_cart = WC()->cart; - $this->original_session = WC()->session; - $this->original_customer = WC()->customer; - $this->original_query = WC()->query; + global $acf_stores; + $this->original_acf_stores = serialize( $acf_stores ); + WC()->shipping()->unregister_shipping_methods(); + WC()->shipping()->reset_shipping(); + WC()->cart = null; + WC()->session = null; + WC()->customer = null; + wc_load_cart(); } public function _tearDown() { parent::_tearDown(); - WC()->cart = $this->original_cart; - WC()->session = $this->original_session; - WC()->customer = $this->original_customer; - WC()->query = $this->original_query; + wc_clear_notices(); + global $acf_stores; + $acf_stores = unserialize($this->original_acf_stores); } }