Skip to content
This repository was archived by the owner on Jun 15, 2022. It is now read-only.

Commit be25b32

Browse files
committed
Replace instances of a method being immediately invoked upon a newly-created object with explicit instantiation and storage to a variable.
For example, `( new WC_order_Data_Store_Custom_Table() )->method();` becomes `$instance = new WC_Order_Data_Store_Custom_Table(); $instance->method();` Thanks, PHP 5.3!
1 parent 55d94df commit be25b32

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

tests/test-data-store.php

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ public function test_create() {
4141
}
4242

4343
public function test_get_order_count() {
44-
$orders = $this->factory()->order->create_many( 5, array(
44+
$instance = new WC_Order_Data_Store_Custom_Table();
45+
$orders = $this->factory()->order->create_many( 5, array(
4546
'post_status' => 'wc-pending',
4647
) );
4748

4849
$this->assertEquals(
4950
count( $orders ),
50-
( new WC_Order_Data_Store_Custom_Table() )->get_order_count( 'wc-pending' )
51+
$instance->get_order_count( 'wc-pending' )
5152
);
5253
}
5354

@@ -64,11 +65,11 @@ public function test_get_order_count_filters_by_status() {
6465
}
6566

6667
public function test_get_unpaid_orders() {
67-
$order = $this->factory()->order->create( array(
68+
$instance = new WC_Order_Data_Store_Custom_Table();
69+
$order = $this->factory()->order->create( array(
6870
'post_status' => 'wc-pending',
6971
) );
70-
$pending = ( new WC_Order_Data_Store_Custom_Table() )
71-
->get_unpaid_orders( time() + DAY_IN_SECONDS );
72+
$pending = $instance->get_unpaid_orders( time() + DAY_IN_SECONDS );
7273

7374
$this->assertCount( 1, $pending, 'There should be only one unpaid order.' );
7475
$this->assertEquals(
@@ -79,11 +80,11 @@ public function test_get_unpaid_orders() {
7980
}
8081

8182
public function test_get_unpaid_orders_uses_date_filtering() {
82-
$order = $this->factory()->order->create( array(
83+
$instance = new WC_Order_Data_Store_Custom_Table();
84+
$order = $this->factory()->order->create( array(
8385
'post_status' => 'wc-pending',
8486
) );
85-
$pending = ( new WC_Order_Data_Store_Custom_Table() )
86-
->get_unpaid_orders( time() - HOUR_IN_SECONDS );
87+
$pending = $instance->get_unpaid_orders( time() - HOUR_IN_SECONDS );
8788

8889
$this->assertEmpty( $pending, 'No unpaid orders should match the time window.' );
8990
}
@@ -97,8 +98,9 @@ public function test_search_orders_can_search_by_order_id() {
9798
}
9899

99100
public function test_search_orders_can_check_post_meta() {
100-
$order = $this->factory()->order->create();
101-
$term = uniqid( 'search term ' );
101+
$instance = new WC_Order_Data_Store_Custom_Table();
102+
$order = $this->factory()->order->create();
103+
$term = uniqid( 'search term ' );
102104

103105
add_post_meta( $order, 'some_custom_meta_key', $term );
104106

@@ -108,7 +110,7 @@ public function test_search_orders_can_check_post_meta() {
108110

109111
$this->assertEquals(
110112
array( $order ),
111-
( new WC_Order_Data_Store_Custom_Table() )->search_orders( $term ),
113+
$instance->search_orders( $term ),
112114
'If post meta keys are specified, they should also be searched.'
113115
);
114116
}
@@ -117,41 +119,44 @@ public function test_search_orders_can_check_post_meta() {
117119
* Same as test_search_orders_can_check_post_meta(), but the filter is never added.
118120
*/
119121
public function test_search_orders_only_checks_post_meta_if_specified() {
120-
$order = $this->factory()->order->create();
121-
$term = uniqid( 'search term ' );
122+
$instance = new WC_Order_Data_Store_Custom_Table();
123+
$order = $this->factory()->order->create();
124+
$term = uniqid( 'search term ' );
122125

123126
add_post_meta( $order, 'some_custom_meta_key', $term );
124127

125128
$this->assertEmpty(
126-
( new WC_Order_Data_Store_Custom_Table() )->search_orders( $term ),
129+
$instance->search_orders( $term ),
127130
'Only search post meta if keys are provided.'
128131
);
129132
}
130133

131134
public function test_search_orders_checks_table_for_product_item_matches() {
132-
$product = $this->factory()->product->create_and_get();
133-
$order = $this->factory()->order->create_and_get();
135+
$instance = new WC_Order_Data_Store_Custom_Table();
136+
$product = $this->factory()->product->create_and_get();
137+
$order = $this->factory()->order->create_and_get();
134138
$order->add_product( $product );
135139
$order->save();
136140

137141
$this->assertEquals(
138142
array( $order->get_id() ),
139-
( new WC_Order_Data_Store_Custom_Table() )->search_orders( $product->get_name() ),
143+
$instance->search_orders( $product->get_name() ),
140144
'Order searches should extend to the names of product items.'
141145
);
142146
}
143147

144148
public function test_search_orders_checks_table_for_product_item_matches_with_like_comparison() {
145-
$product = $this->factory()->product->create_and_get( array(
149+
$instance = new WC_Order_Data_Store_Custom_Table();
150+
$product = $this->factory()->product->create_and_get( array(
146151
'post_title' => 'foo bar baz',
147152
) );
148-
$order = $this->factory()->order->create_and_get();
153+
$order = $this->factory()->order->create_and_get();
149154
$order->add_product( $product );
150155
$order->save();
151156

152157
$this->assertEquals(
153158
array( $order->get_id() ),
154-
( new WC_Order_Data_Store_Custom_Table() )->search_orders( 'bar' ),
159+
$instance->search_orders( 'bar' ),
155160
'Product items should be searched using a LIKE comparison and wildcards.'
156161
);
157162
}
@@ -160,13 +165,14 @@ public function test_search_orders_checks_table_for_product_item_matches_with_li
160165
* @dataProvider order_type_provider()
161166
*/
162167
public function test_get_order_type( $order_type ) {
163-
$order = $this->factory()->order->create( array(
168+
$instance = new WC_Order_Data_Store_Custom_Table();
169+
$order = $this->factory()->order->create( array(
164170
'post_type' => $order_type,
165171
) );
166172

167173
$this->assertEquals(
168174
$order_type,
169-
( new WC_Order_Data_Store_Custom_Table() )->get_order_type( $order )
175+
$instance->get_order_type( $order )
170176
);
171177
}
172178

0 commit comments

Comments
 (0)