From 8b62d5b06efcfd0fdb1df40648cda9931407144b Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Mon, 27 Aug 2018 18:58:49 -0300 Subject: [PATCH] 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. --- tests/framework/helpers/class-wc-helper-product.php | 11 ++++++++--- tests/unit-tests/gateways/paypal/request.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/framework/helpers/class-wc-helper-product.php b/tests/framework/helpers/class-wc-helper-product.php index acea76c592e..4dd7d996c24 100644 --- a/tests/framework/helpers/class-wc-helper-product.php +++ b/tests/framework/helpers/class-wc-helper-product.php @@ -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; + } } /** diff --git a/tests/unit-tests/gateways/paypal/request.php b/tests/unit-tests/gateways/paypal/request.php index 94615d2b988..384b86e4e22 100644 --- a/tests/unit-tests/gateways/paypal/request.php +++ b/tests/unit-tests/gateways/paypal/request.php @@ -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;