Skip to content

Commit

Permalink
Merge pull request #3656 from 10up/chore/refactor-wc-tests
Browse files Browse the repository at this point in the history
Do not extend a Test class
  • Loading branch information
felipeelia authored Sep 27, 2023
2 parents 0daad8b + c411a02 commit fa27532
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 39 deletions.
40 changes: 3 additions & 37 deletions tests/php/features/WooCommerce/TestWooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 3 additions & 1 deletion tests/php/features/WooCommerce/TestWooCommerceOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 3 additions & 1 deletion tests/php/features/WooCommerce/TestWooCommerceProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
47 changes: 47 additions & 0 deletions tests/php/features/WooCommerce/WooCommerceBaseTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* WooCommerce Base Test Case
*
* @since 5.0.0
* @package elasticpress
*/

namespace ElasticPressTest;

/**
* WooCommerceBaseTestCase class
*/
class WooCommerceBaseTestCase extends BaseTestCase {
/**
* Setup each test.
*
* @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
*
* @group woocommerce
*/
public function tear_down() {
parent::tear_down();

$this->fired_actions = array();
}
}

0 comments on commit fa27532

Please sign in to comment.