Skip to content

Commit 6166166

Browse files
Fix test interdependency (#13)
* Fix test interdependency Fix test interdependency * Fix wctestcase.
1 parent fd236bd commit 6166166

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

src/WCAjaxTestCase.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Codeception\TestCase\WPAjaxTestCase;
66

77
class WCAjaxTestCase extends WPAjaxTestCase {
8+
private $original_acf_stores;
9+
810
/**
911
* @return WC_UnitTest_Factory
1012
*/
@@ -15,4 +17,24 @@ protected static function factory() {
1517
}
1618
return $factory;
1719
}
20+
21+
public function _setUp()
22+
{
23+
parent::_setUp();
24+
global $acf_stores;
25+
$this->original_acf_stores = serialize( $acf_stores );
26+
WC()->shipping()->unregister_shipping_methods();
27+
WC()->shipping()->reset_shipping();
28+
WC()->cart = null;
29+
WC()->session = null;
30+
WC()->customer = null;
31+
wc_load_cart();
32+
}
33+
34+
public function _tearDown()
35+
{
36+
parent::_tearDown();
37+
global $acf_stores;
38+
$acf_stores = unserialize($this->original_acf_stores);
39+
}
1840
}

src/WCTestCase.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
use Codeception\TestCase\WPTestCase;
66

77
class WCTestCase extends WPTestCase {
8-
private $original_cart;
9-
private $original_session;
10-
private $original_customer;
11-
private $original_query;
8+
private $original_acf_stores;
129

1310
/**
1411
* @return WC_UnitTest_Factory
@@ -24,18 +21,21 @@ protected static function factory() {
2421
public function _setUp()
2522
{
2623
parent::_setUp();
27-
$this->original_cart = WC()->cart;
28-
$this->original_session = WC()->session;
29-
$this->original_customer = WC()->customer;
30-
$this->original_query = WC()->query;
24+
global $acf_stores;
25+
$this->original_acf_stores = serialize( $acf_stores );
26+
WC()->shipping()->unregister_shipping_methods();
27+
WC()->shipping()->reset_shipping();
28+
WC()->cart = null;
29+
WC()->session = null;
30+
WC()->customer = null;
31+
wc_load_cart();
3132
}
3233

3334
public function _tearDown()
3435
{
3536
parent::_tearDown();
36-
WC()->cart = $this->original_cart;
37-
WC()->session = $this->original_session;
38-
WC()->customer = $this->original_customer;
39-
WC()->query = $this->original_query;
37+
wc_clear_notices();
38+
global $acf_stores;
39+
$acf_stores = unserialize($this->original_acf_stores);
4040
}
4141
}

0 commit comments

Comments
 (0)