From c411a021715c42a3cc06298af9e39084fc2398e4 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 26 Sep 2023 16:47:41 -0300 Subject: [PATCH] Do not extend a Test class --- .../features/WooCommerce/TestWooCommerce.php | 40 ++-------------- .../WooCommerce/TestWooCommerceOrders.php | 4 +- .../WooCommerce/TestWooCommerceProduct.php | 4 +- .../WooCommerce/WooCommerceBaseTestCase.php | 47 +++++++++++++++++++ 4 files changed, 56 insertions(+), 39 deletions(-) create mode 100644 tests/php/features/WooCommerce/WooCommerceBaseTestCase.php diff --git a/tests/php/features/WooCommerce/TestWooCommerce.php b/tests/php/features/WooCommerce/TestWooCommerce.php index 886f90ba68..aa91fdd9fb 100644 --- a/tests/php/features/WooCommerce/TestWooCommerce.php +++ b/tests/php/features/WooCommerce/TestWooCommerce.php @@ -9,46 +9,12 @@ use ElasticPress; +require_once __DIR__ . '/WooCommerceBaseTestCase.php'; + /** * WC test class */ -class TestWooCommerce extends BaseTestCase { - - /** - * Setup each test. - * - * @since 2.1 - * @group woocommerce - */ - public function set_up() { - global $wpdb; - parent::set_up(); - $wpdb->suppress_errors(); - - $admin_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); - - wp_set_current_user( $admin_id ); - - ElasticPress\Elasticsearch::factory()->delete_all_indices(); - ElasticPress\Indexables::factory()->get( 'post' )->put_mapping(); - - ElasticPress\Indexables::factory()->get( 'post' )->sync_manager->sync_queue = []; - - $this->setup_test_post_type(); - } - - /** - * Clean up after each test. Reset our mocks - * - * @since 2.1 - * @group woocommerce - */ - public function tear_down() { - parent::tear_down(); - - $this->fired_actions = array(); - } - +class TestWooCommerce extends WooCommerceBaseTestCase { /** * Test search integration is on in general for product searches * diff --git a/tests/php/features/WooCommerce/TestWooCommerceOrders.php b/tests/php/features/WooCommerce/TestWooCommerceOrders.php index 9c1eff486e..3b157d2ff6 100644 --- a/tests/php/features/WooCommerce/TestWooCommerceOrders.php +++ b/tests/php/features/WooCommerce/TestWooCommerceOrders.php @@ -10,10 +10,12 @@ use ElasticPress; +require_once __DIR__ . '/WooCommerceBaseTestCase.php'; + /** * WC orders test class */ -class TestWooCommerceOrders extends TestWooCommerce { +class TestWooCommerceOrders extends WooCommerceBaseTestCase { /** * Orders instance * diff --git a/tests/php/features/WooCommerce/TestWooCommerceProduct.php b/tests/php/features/WooCommerce/TestWooCommerceProduct.php index b5e887f653..a3fa5acfaa 100644 --- a/tests/php/features/WooCommerce/TestWooCommerceProduct.php +++ b/tests/php/features/WooCommerce/TestWooCommerceProduct.php @@ -10,10 +10,12 @@ use ElasticPress; +require_once __DIR__ . '/WooCommerceBaseTestCase.php'; + /** * WC products test class */ -class TestWooCommerceProduct extends TestWooCommerce { +class TestWooCommerceProduct extends WooCommerceBaseTestCase { /** * Products instance * diff --git a/tests/php/features/WooCommerce/WooCommerceBaseTestCase.php b/tests/php/features/WooCommerce/WooCommerceBaseTestCase.php new file mode 100644 index 0000000000..b035496e28 --- /dev/null +++ b/tests/php/features/WooCommerce/WooCommerceBaseTestCase.php @@ -0,0 +1,47 @@ +suppress_errors(); + + $admin_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + + wp_set_current_user( $admin_id ); + + \ElasticPress\Elasticsearch::factory()->delete_all_indices(); + \ElasticPress\Indexables::factory()->get( 'post' )->put_mapping(); + + \ElasticPress\Indexables::factory()->get( 'post' )->sync_manager->sync_queue = []; + + $this->setup_test_post_type(); + } + + /** + * Clean up after each test. Reset our mocks + * + * @group woocommerce + */ + public function tear_down() { + parent::tear_down(); + + $this->fired_actions = array(); + } +}