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:
parent
7b6fcd18b5
commit
8b62d5b06e
|
@ -25,11 +25,12 @@ class WC_Helper_Product {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
* @return WC_Product_Simple
|
* @return WC_Product_Simple
|
||||||
*/
|
*/
|
||||||
public static function create_simple_product() {
|
public static function create_simple_product( $save = true ) {
|
||||||
$product = new WC_Product_Simple();
|
$product = new WC_Product_Simple();
|
||||||
$product->set_props( array(
|
$product->set_props( array(
|
||||||
'name' => 'Dummy Product',
|
'name' => 'Dummy Product',
|
||||||
'regular_price' => 10,
|
'regular_price' => 10,
|
||||||
|
'price' => 10,
|
||||||
'sku' => 'DUMMY SKU',
|
'sku' => 'DUMMY SKU',
|
||||||
'manage_stock' => false,
|
'manage_stock' => false,
|
||||||
'tax_status' => 'taxable',
|
'tax_status' => 'taxable',
|
||||||
|
@ -38,9 +39,13 @@ class WC_Helper_Product {
|
||||||
'stock_status' => 'instock',
|
'stock_status' => 'instock',
|
||||||
'weight' => '1.1',
|
'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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,7 +28,7 @@ class WC_Tests_Paypal_Gateway_Request extends WC_Unit_Test_Case {
|
||||||
protected function create_products( $product_count = 30 ) {
|
protected function create_products( $product_count = 30 ) {
|
||||||
$this->products = array();
|
$this->products = array();
|
||||||
for ( $i = 0; $i < $product_count; $i++ ) {
|
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 );
|
$product->set_name( 'Dummy Product ' . $i );
|
||||||
$this->products[] = $product;
|
$this->products[] = $product;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue