Reduce WC_Tests_Paypal_Gateway_Request::test_request_url() execution time

This commits reduces the execution time of the test WC_Tests_Paypal_Gateway_Request::test_request_url() from about 30s to about 6s (which is still super slow and even after this change this test is still the slowest in our test suite). This test creates several products that are needed to test different scenarios. To make it run faster, the code was changed to create the WC_Product objects without saving them to the database. Just interacting with the objects is enough to this test and skipping the database makes it run much faster. Other tests might benefit from the same technique.
This commit is contained in:
Rodrigo Primo 2018-08-27 18:58:49 -03:00
parent 7b6fcd18b5
commit 8b62d5b06e
2 changed files with 9 additions and 4 deletions

View File

@ -25,11 +25,12 @@ class WC_Helper_Product {
* @since 2.3
* @return WC_Product_Simple
*/
public static function create_simple_product() {
public static function create_simple_product( $save = true ) {
$product = new WC_Product_Simple();
$product->set_props( array(
'name' => 'Dummy Product',
'regular_price' => 10,
'price' => 10,
'sku' => 'DUMMY SKU',
'manage_stock' => false,
'tax_status' => 'taxable',
@ -38,9 +39,13 @@ class WC_Helper_Product {
'stock_status' => 'instock',
'weight' => '1.1',
) );
$product->save();
return wc_get_product( $product->get_id() );
if ( $save ) {
$product->save();
return wc_get_product( $product->get_id() );
} else {
return $product;
}
}
/**

View File

@ -28,7 +28,7 @@ class WC_Tests_Paypal_Gateway_Request extends WC_Unit_Test_Case {
protected function create_products( $product_count = 30 ) {
$this->products = array();
for ( $i = 0; $i < $product_count; $i++ ) {
$product = WC_Helper_Product::create_simple_product();
$product = WC_Helper_Product::create_simple_product( false );
$product->set_name( 'Dummy Product ' . $i );
$this->products[] = $product;