Test setup methods should call parent setup method

This commits adds a call to `parent::setUp()` inside WC_Tests_Product_CSV_Importer::setUp(). This is necessary to make sure transactions are used on database calls and thus tests don't have to worry about cleaning inserted data.

I found this issue while debugging https://github.com/woocommerce/woocommerce-product-tables-feature-plugin/issues/81. Turns out this test was failing because WC_Tests_Product_CSV_Importer::test_import() was leaving one post in the database due to a bug in the custom product tables plugin.
This commit is contained in:
Rodrigo Primo 2018-04-20 14:54:02 -03:00
parent c7c82a2335
commit 4a8f34f2ee
1 changed files with 2 additions and 17 deletions

View File

@ -17,6 +17,8 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
* Load up the importer classes since they aren't loaded by default.
*/
public function setUp() {
parent::setUp();
$this->csv_file = dirname( __FILE__ ) . '/sample.csv';
$bootstrap = WC_Unit_Tests_Bootstrap::instance();
@ -97,11 +99,6 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
$this->assertEquals( 0, count( $results['failed'] ) );
$this->assertEquals( 0, count( $results['updated'] ) );
$this->assertEquals( 0, count( $results['skipped'] ) );
// Exclude imported products.
foreach ( $results['imported'] as $id ) {
wp_delete_post( $id, true );
}
}
/**
@ -575,17 +572,5 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
}
$this->assertEquals( $items, $parsed_data );
// Remove temporary products.
$temp_products = get_posts(
array(
'post_status' => 'importing',
'post_type' => 'product',
'fields' => 'ids',
)
);
foreach ( $temp_products as $id ) {
wp_delete_post( $id, true );
}
}
}