Skip to content

Commit

Permalink
Fix test interdependency (#13)
Browse files Browse the repository at this point in the history
* Fix test interdependency

Fix test interdependency

* Fix wctestcase.
  • Loading branch information
NielsdeBlaauw authored Mar 18, 2024
1 parent fd236bd commit 6166166
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
22 changes: 22 additions & 0 deletions src/WCAjaxTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Codeception\TestCase\WPAjaxTestCase;

class WCAjaxTestCase extends WPAjaxTestCase {
private $original_acf_stores;

/**
* @return WC_UnitTest_Factory
*/
Expand All @@ -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);
}
}
24 changes: 12 additions & 12 deletions src/WCTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

0 comments on commit 6166166

Please sign in to comment.