Test Failed
Push — master ( 44764d...6dc399 )
by Mike
04:21
created
unit-tests/Tests/Version4/Reports/Products.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	public function test_register_routes() {
40 40
 		$routes = $this->server->get_routes();
41 41
 
42
-		$this->assertArrayHasKey( $this->endpoint, $routes );
42
+		$this->assertArrayHasKey($this->endpoint, $routes);
43 43
 	}
44 44
 
45 45
 	/**
@@ -50,30 +50,30 @@  discard block
 block discarded – undo
50 50
 	public function test_get_reports() {
51 51
 		// Populate all of the data.
52 52
 		$product = new \WC_Product_Simple();
53
-		$product->set_name( 'Test Product' );
54
-		$product->set_regular_price( 25 );
53
+		$product->set_name('Test Product');
54
+		$product->set_regular_price(25);
55 55
 		$product->save();
56 56
 
57
-		$order = OrderHelper::create_order( 1, $product );
58
-		$order->set_status( 'completed' );
59
-		$order->set_total( 100 ); // $25 x 4.
57
+		$order = OrderHelper::create_order(1, $product);
58
+		$order->set_status('completed');
59
+		$order->set_total(100); // $25 x 4.
60 60
 		$order->save();
61 61
 
62 62
 		QueueHelper::run_all_pending();
63 63
 
64
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
64
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
65 65
 		$reports  = $response->get_data();
66 66
 
67
-		$this->assertEquals( 200, $response->get_status() );
68
-		$this->assertEquals( 1, count( $reports ) );
67
+		$this->assertEquals(200, $response->get_status());
68
+		$this->assertEquals(1, count($reports));
69 69
 
70
-		$product_report = reset( $reports );
70
+		$product_report = reset($reports);
71 71
 
72
-		$this->assertEquals( $product->get_id(), $product_report['product_id'] );
73
-		$this->assertEquals( 4, $product_report['items_sold'] );
74
-		$this->assertEquals( 1, $product_report['orders_count'] );
75
-		$this->assertArrayHasKey( '_links', $product_report );
76
-		$this->assertArrayHasKey( 'product', $product_report['_links'] );
72
+		$this->assertEquals($product->get_id(), $product_report['product_id']);
73
+		$this->assertEquals(4, $product_report['items_sold']);
74
+		$this->assertEquals(1, $product_report['orders_count']);
75
+		$this->assertArrayHasKey('_links', $product_report);
76
+		$this->assertArrayHasKey('product', $product_report['_links']);
77 77
 	}
78 78
 
79 79
 	/**
@@ -84,49 +84,49 @@  discard block
 block discarded – undo
84 84
 	public function test_get_reports_products_param() {
85 85
 		// Populate all of the data.
86 86
 		$product = new \WC_Product_Simple();
87
-		$product->set_name( 'Test Product' );
88
-		$product->set_regular_price( 25 );
87
+		$product->set_name('Test Product');
88
+		$product->set_regular_price(25);
89 89
 		$product->save();
90 90
 
91 91
 		$product_2 = new \WC_Product_Simple();
92
-		$product_2->set_name( 'Test Product 2' );
93
-		$product_2->set_regular_price( 25 );
92
+		$product_2->set_name('Test Product 2');
93
+		$product_2->set_regular_price(25);
94 94
 		$product_2->save();
95 95
 
96
-		$order = OrderHelper::create_order( 1, $product );
97
-		$order->set_status( 'completed' );
98
-		$order->set_total( 100 ); // $25 x 4.
96
+		$order = OrderHelper::create_order(1, $product);
97
+		$order->set_status('completed');
98
+		$order->set_total(100); // $25 x 4.
99 99
 		$order->save();
100 100
 
101 101
 		QueueHelper::run_all_pending();
102 102
 
103
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
103
+		$request = new WP_REST_Request('GET', $this->endpoint);
104 104
 		$request->set_query_params(
105 105
 			array(
106 106
 				'products' => $product->get_id() . ',' . $product_2->get_id(),
107 107
 			)
108 108
 		);
109
-		$response = $this->server->dispatch( $request );
109
+		$response = $this->server->dispatch($request);
110 110
 		$reports  = $response->get_data();
111 111
 
112
-		$this->assertEquals( 200, $response->get_status() );
113
-		$this->assertEquals( 2, count( $reports ) );
112
+		$this->assertEquals(200, $response->get_status());
113
+		$this->assertEquals(2, count($reports));
114 114
 
115
-		$product_report = reset( $reports );
115
+		$product_report = reset($reports);
116 116
 
117
-		$this->assertEquals( $product->get_id(), $product_report['product_id'] );
118
-		$this->assertEquals( 4, $product_report['items_sold'] );
119
-		$this->assertEquals( 1, $product_report['orders_count'] );
120
-		$this->assertArrayHasKey( '_links', $product_report );
121
-		$this->assertArrayHasKey( 'product', $product_report['_links'] );
117
+		$this->assertEquals($product->get_id(), $product_report['product_id']);
118
+		$this->assertEquals(4, $product_report['items_sold']);
119
+		$this->assertEquals(1, $product_report['orders_count']);
120
+		$this->assertArrayHasKey('_links', $product_report);
121
+		$this->assertArrayHasKey('product', $product_report['_links']);
122 122
 
123
-		$product_report = next( $reports );
123
+		$product_report = next($reports);
124 124
 
125
-		$this->assertEquals( $product_2->get_id(), $product_report['product_id'] );
126
-		$this->assertEquals( null, $product_report['items_sold'] );
127
-		$this->assertEquals( null, $product_report['orders_count'] );
128
-		$this->assertArrayHasKey( '_links', $product_report );
129
-		$this->assertArrayHasKey( 'product', $product_report['_links'] );
125
+		$this->assertEquals($product_2->get_id(), $product_report['product_id']);
126
+		$this->assertEquals(null, $product_report['items_sold']);
127
+		$this->assertEquals(null, $product_report['orders_count']);
128
+		$this->assertArrayHasKey('_links', $product_report);
129
+		$this->assertArrayHasKey('product', $product_report['_links']);
130 130
 	}
131 131
 
132 132
 	/**
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 	 * @since 3.5.0
136 136
 	 */
137 137
 	public function test_get_reports_without_permission() {
138
-		wp_set_current_user( 0 );
139
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
140
-		$this->assertEquals( 401, $response->get_status() );
138
+		wp_set_current_user(0);
139
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
140
+		$this->assertEquals(401, $response->get_status());
141 141
 	}
142 142
 
143 143
 	/**
@@ -146,16 +146,16 @@  discard block
 block discarded – undo
146 146
 	 * @since 3.5.0
147 147
 	 */
148 148
 	public function test_reports_schema() {
149
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
150
-		$response   = $this->server->dispatch( $request );
149
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
150
+		$response   = $this->server->dispatch($request);
151 151
 		$data       = $response->get_data();
152 152
 		$properties = $data['schema']['properties'];
153 153
 
154
-		$this->assertEquals( 5, count( $properties ) );
155
-		$this->assertArrayHasKey( 'product_id', $properties );
156
-		$this->assertArrayHasKey( 'items_sold', $properties );
157
-		$this->assertArrayHasKey( 'net_revenue', $properties );
158
-		$this->assertArrayHasKey( 'orders_count', $properties );
159
-		$this->assertArrayHasKey( 'extended_info', $properties );
154
+		$this->assertEquals(5, count($properties));
155
+		$this->assertArrayHasKey('product_id', $properties);
156
+		$this->assertArrayHasKey('items_sold', $properties);
157
+		$this->assertArrayHasKey('net_revenue', $properties);
158
+		$this->assertArrayHasKey('orders_count', $properties);
159
+		$this->assertArrayHasKey('extended_info', $properties);
160 160
 	}
161 161
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/Categories.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	public function test_register_routes() {
37 37
 		$routes = $this->server->get_routes();
38 38
 
39
-		$this->assertArrayHasKey( $this->endpoint, $routes );
39
+		$this->assertArrayHasKey($this->endpoint, $routes);
40 40
 	}
41 41
 
42 42
 	/**
@@ -47,33 +47,33 @@  discard block
 block discarded – undo
47 47
 	public function test_get_reports() {
48 48
 		// Populate all of the data.
49 49
 		$product = new \WC_Product_Simple();
50
-		$product->set_name( 'Test Product' );
51
-		$product->set_regular_price( 25 );
50
+		$product->set_name('Test Product');
51
+		$product->set_regular_price(25);
52 52
 		$product->save();
53 53
 
54
-		$order = OrderHelper::create_order( 1, $product );
55
-		$order->set_status( 'completed' );
56
-		$order->set_total( 100 ); // $25 x 4.
54
+		$order = OrderHelper::create_order(1, $product);
55
+		$order->set_status('completed');
56
+		$order->set_total(100); // $25 x 4.
57 57
 		$order->save();
58 58
 
59 59
 		QueueHelper::run_all_pending();
60 60
 
61
-		$uncategorized_term = get_term_by( 'slug', 'uncategorized', 'product_cat' );
61
+		$uncategorized_term = get_term_by('slug', 'uncategorized', 'product_cat');
62 62
 
63
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
63
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
64 64
 		$reports  = $response->get_data();
65 65
 
66
-		$this->assertEquals( 200, $response->get_status() );
67
-		$this->assertEquals( 1, count( $reports ) );
66
+		$this->assertEquals(200, $response->get_status());
67
+		$this->assertEquals(1, count($reports));
68 68
 
69
-		$category_report = reset( $reports );
69
+		$category_report = reset($reports);
70 70
 
71
-		$this->assertEquals( $uncategorized_term->term_id, $category_report['category_id'] );
72
-		$this->assertEquals( 4, $category_report['items_sold'] );
73
-		$this->assertEquals( 1, $category_report['orders_count'] );
74
-		$this->assertEquals( 1, $category_report['products_count'] );
75
-		$this->assertArrayHasKey( '_links', $category_report );
76
-		$this->assertArrayHasKey( 'category', $category_report['_links'] );
71
+		$this->assertEquals($uncategorized_term->term_id, $category_report['category_id']);
72
+		$this->assertEquals(4, $category_report['items_sold']);
73
+		$this->assertEquals(1, $category_report['orders_count']);
74
+		$this->assertEquals(1, $category_report['products_count']);
75
+		$this->assertArrayHasKey('_links', $category_report);
76
+		$this->assertArrayHasKey('category', $category_report['_links']);
77 77
 	}
78 78
 
79 79
 	/**
@@ -84,56 +84,56 @@  discard block
 block discarded – undo
84 84
 	public function test_get_reports_categories_param() {
85 85
 		// Populate all of the data.
86 86
 		$product = new \WC_Product_Simple();
87
-		$product->set_name( 'Test Product' );
88
-		$product->set_regular_price( 25 );
87
+		$product->set_name('Test Product');
88
+		$product->set_regular_price(25);
89 89
 		$product->save();
90 90
 
91
-		$order = OrderHelper::create_order( 1, $product );
92
-		$order->set_status( 'completed' );
93
-		$order->set_total( 100 ); // $25 x 4.
91
+		$order = OrderHelper::create_order(1, $product);
92
+		$order->set_status('completed');
93
+		$order->set_total(100); // $25 x 4.
94 94
 		$order->save();
95 95
 
96 96
 		// Populate all of the data.
97 97
 		$product = new \WC_Product_Simple();
98
-		$product->set_name( 'Test Product 2' );
99
-		$product->set_regular_price( 100 );
100
-		$second_category_id = wp_create_category( 'Second Category' );
101
-		$product->set_category_ids( array( $second_category_id ) );
98
+		$product->set_name('Test Product 2');
99
+		$product->set_regular_price(100);
100
+		$second_category_id = wp_create_category('Second Category');
101
+		$product->set_category_ids(array($second_category_id));
102 102
 		$product->save();
103 103
 
104 104
 		QueueHelper::run_all_pending();
105 105
 
106
-		$uncategorized_term = get_term_by( 'slug', 'uncategorized', 'product_cat' );
106
+		$uncategorized_term = get_term_by('slug', 'uncategorized', 'product_cat');
107 107
 
108
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
108
+		$request = new WP_REST_Request('GET', $this->endpoint);
109 109
 		$request->set_query_params(
110 110
 			array(
111 111
 				'categories' => $uncategorized_term->term_id . ',' . $second_category_id,
112 112
 			)
113 113
 		);
114
-		$response = $this->server->dispatch( $request );
114
+		$response = $this->server->dispatch($request);
115 115
 		$reports  = $response->get_data();
116 116
 
117
-		$this->assertEquals( 200, $response->get_status() );
118
-		$this->assertEquals( 2, count( $reports ) );
117
+		$this->assertEquals(200, $response->get_status());
118
+		$this->assertEquals(2, count($reports));
119 119
 
120
-		$category_report = reset( $reports );
120
+		$category_report = reset($reports);
121 121
 
122
-		$this->assertEquals( $second_category_id, $category_report['category_id'] );
123
-		$this->assertEquals( 0, $category_report['items_sold'] );
124
-		$this->assertEquals( 0, $category_report['orders_count'] );
125
-		$this->assertEquals( 0, $category_report['products_count'] );
126
-		$this->assertArrayHasKey( '_links', $category_report );
127
-		$this->assertArrayHasKey( 'category', $category_report['_links'] );
122
+		$this->assertEquals($second_category_id, $category_report['category_id']);
123
+		$this->assertEquals(0, $category_report['items_sold']);
124
+		$this->assertEquals(0, $category_report['orders_count']);
125
+		$this->assertEquals(0, $category_report['products_count']);
126
+		$this->assertArrayHasKey('_links', $category_report);
127
+		$this->assertArrayHasKey('category', $category_report['_links']);
128 128
 
129
-		$category_report = next( $reports );
129
+		$category_report = next($reports);
130 130
 
131
-		$this->assertEquals( $uncategorized_term->term_id, $category_report['category_id'] );
132
-		$this->assertEquals( 4, $category_report['items_sold'] );
133
-		$this->assertEquals( 1, $category_report['orders_count'] );
134
-		$this->assertEquals( 1, $category_report['products_count'] );
135
-		$this->assertArrayHasKey( '_links', $category_report );
136
-		$this->assertArrayHasKey( 'category', $category_report['_links'] );
131
+		$this->assertEquals($uncategorized_term->term_id, $category_report['category_id']);
132
+		$this->assertEquals(4, $category_report['items_sold']);
133
+		$this->assertEquals(1, $category_report['orders_count']);
134
+		$this->assertEquals(1, $category_report['products_count']);
135
+		$this->assertArrayHasKey('_links', $category_report);
136
+		$this->assertArrayHasKey('category', $category_report['_links']);
137 137
 	}
138 138
 
139 139
 	/**
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 	 * @since 3.5.0
143 143
 	 */
144 144
 	public function test_get_reports_without_permission() {
145
-		wp_set_current_user( 0 );
146
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
147
-		$this->assertEquals( 401, $response->get_status() );
145
+		wp_set_current_user(0);
146
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
147
+		$this->assertEquals(401, $response->get_status());
148 148
 	}
149 149
 
150 150
 	/**
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
 	 * @since 3.5.0
154 154
 	 */
155 155
 	public function test_reports_schema() {
156
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
157
-		$response   = $this->server->dispatch( $request );
156
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
157
+		$response   = $this->server->dispatch($request);
158 158
 		$data       = $response->get_data();
159 159
 		$properties = $data['schema']['properties'];
160 160
 
161
-		$this->assertEquals( 6, count( $properties ) );
162
-		$this->assertArrayHasKey( 'category_id', $properties );
163
-		$this->assertArrayHasKey( 'items_sold', $properties );
164
-		$this->assertArrayHasKey( 'net_revenue', $properties );
165
-		$this->assertArrayHasKey( 'orders_count', $properties );
166
-		$this->assertArrayHasKey( 'products_count', $properties );
167
-		$this->assertArrayHasKey( 'extended_info', $properties );
161
+		$this->assertEquals(6, count($properties));
162
+		$this->assertArrayHasKey('category_id', $properties);
163
+		$this->assertArrayHasKey('items_sold', $properties);
164
+		$this->assertArrayHasKey('net_revenue', $properties);
165
+		$this->assertArrayHasKey('orders_count', $properties);
166
+		$this->assertArrayHasKey('products_count', $properties);
167
+		$this->assertArrayHasKey('extended_info', $properties);
168 168
 	}
169 169
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/DownloadStats.php 1 patch
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
13 13
 use \WP_REST_Request;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	public function test_register_routes() {
37 37
 		$routes = $this->server->get_routes();
38 38
 
39
-		$this->assertArrayHasKey( $this->endpoint, $routes );
39
+		$this->assertArrayHasKey($this->endpoint, $routes);
40 40
 	}
41 41
 
42 42
 	/**
@@ -47,79 +47,79 @@  discard block
 block discarded – undo
47 47
 
48 48
 		// Populate all of the data.
49 49
 		$prod_download = new \WC_Product_Download();
50
-		$prod_download->set_file( plugin_dir_url( __FILE__ ) . '/assets/images/help.png' );
51
-		$prod_download->set_id( 1 );
50
+		$prod_download->set_file(plugin_dir_url(__FILE__) . '/assets/images/help.png');
51
+		$prod_download->set_id(1);
52 52
 
53 53
 		$product = new \WC_Product_Simple();
54
-		$product->set_name( 'Test Product' );
55
-		$product->set_downloadable( 'yes' );
56
-		$product->set_downloads( array( $prod_download ) );
57
-		$product->set_regular_price( 25 );
54
+		$product->set_name('Test Product');
55
+		$product->set_downloadable('yes');
56
+		$product->set_downloads(array($prod_download));
57
+		$product->set_regular_price(25);
58 58
 		$product->save();
59 59
 
60
-		$order = OrderHelper::create_order( 1, $product );
61
-		$order->set_status( 'completed' );
62
-		$order->set_total( 100 );
60
+		$order = OrderHelper::create_order(1, $product);
61
+		$order->set_status('completed');
62
+		$order->set_total(100);
63 63
 		$order->save();
64 64
 
65 65
 		$download = new \WC_Customer_Download();
66
-		$download->set_user_id( $this->user );
67
-		$download->set_order_id( $order->get_id() );
68
-		$download->set_product_id( $product->get_id() );
69
-		$download->set_download_id( $prod_download->get_id() );
66
+		$download->set_user_id($this->user);
67
+		$download->set_order_id($order->get_id());
68
+		$download->set_product_id($product->get_id());
69
+		$download->set_download_id($prod_download->get_id());
70 70
 		$download->save();
71 71
 
72 72
 		$object = new \WC_Customer_Download_Log();
73
-		$object->set_permission_id( $download->get_id() );
74
-		$object->set_user_id( $this->user );
75
-		$object->set_user_ip_address( '1.2.3.4' );
73
+		$object->set_permission_id($download->get_id());
74
+		$object->set_user_id($this->user);
75
+		$object->set_user_ip_address('1.2.3.4');
76 76
 		$id = $object->save();
77 77
 
78 78
 		$time    = time();
79
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
79
+		$request = new WP_REST_Request('GET', $this->endpoint);
80 80
 		$request->set_query_params(
81 81
 			array(
82
-				'before'   => date( 'Y-m-d 23:59:59', $time ),
83
-				'after'    => date( 'Y-m-d H:00:00', $time - ( 7 * DAY_IN_SECONDS ) ),
82
+				'before'   => date('Y-m-d 23:59:59', $time),
83
+				'after'    => date('Y-m-d H:00:00', $time - (7 * DAY_IN_SECONDS)),
84 84
 				'interval' => 'day',
85 85
 			)
86 86
 		);
87
-		$response = $this->server->dispatch( $request );
87
+		$response = $this->server->dispatch($request);
88 88
 		$reports  = $response->get_data();
89 89
 
90
-		$this->assertEquals( 200, $response->get_status() );
90
+		$this->assertEquals(200, $response->get_status());
91 91
 
92 92
 		$totals = array(
93 93
 			'download_count' => 1,
94 94
 		);
95
-		$this->assertEquals( $totals, $reports['totals'] );
95
+		$this->assertEquals($totals, $reports['totals']);
96 96
 
97 97
 		$today_interval = array(
98
-			'interval'       => date( 'Y-m-d', $time ),
99
-			'date_start'     => date( 'Y-m-d 00:00:00', $time ),
100
-			'date_start_gmt' => date( 'Y-m-d 00:00:00', $time ),
101
-			'date_end'       => date( 'Y-m-d 23:59:59', $time ),
102
-			'date_end_gmt'   => date( 'Y-m-d 23:59:59', $time ),
98
+			'interval'       => date('Y-m-d', $time),
99
+			'date_start'     => date('Y-m-d 00:00:00', $time),
100
+			'date_start_gmt' => date('Y-m-d 00:00:00', $time),
101
+			'date_end'       => date('Y-m-d 23:59:59', $time),
102
+			'date_end_gmt'   => date('Y-m-d 23:59:59', $time),
103 103
 			'subtotals'      => (object) array(
104 104
 				'download_count' => 1,
105 105
 			),
106 106
 		);
107
-		$this->assertEquals( $today_interval, $reports['intervals'][0] );
107
+		$this->assertEquals($today_interval, $reports['intervals'][0]);
108 108
 
109
-		$this->assertEquals( 8, count( $reports['intervals'] ) );
110
-		$this->assertEquals( 0, $reports['intervals'][1]['subtotals']->download_count );
109
+		$this->assertEquals(8, count($reports['intervals']));
110
+		$this->assertEquals(0, $reports['intervals'][1]['subtotals']->download_count);
111 111
 
112 112
 		// Test sorting by download_count.
113
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
113
+		$request = new WP_REST_Request('GET', $this->endpoint);
114 114
 		$request->set_query_params(
115 115
 			array(
116
-				'before'   => date( 'Y-m-d 23:59:59', $time ),
117
-				'after'    => date( 'Y-m-d H:00:00', $time - ( 7 * DAY_IN_SECONDS ) ),
116
+				'before'   => date('Y-m-d 23:59:59', $time),
117
+				'after'    => date('Y-m-d H:00:00', $time - (7 * DAY_IN_SECONDS)),
118 118
 				'interval' => 'day',
119 119
 				'orderby'  => 'download_count',
120 120
 			)
121 121
 		);
122
-		$response = $this->server->dispatch( $request );
122
+		$response = $this->server->dispatch($request);
123 123
 		$reports  = $response->get_data();
124 124
 	}
125 125
 
@@ -133,53 +133,53 @@  discard block
 block discarded – undo
133 133
 
134 134
 		// First set of data.
135 135
 		$prod_download = new \WC_Product_Download();
136
-		$prod_download->set_file( plugin_dir_url( __FILE__ ) . '/assets/images/help.png' );
137
-		$prod_download->set_id( 1 );
136
+		$prod_download->set_file(plugin_dir_url(__FILE__) . '/assets/images/help.png');
137
+		$prod_download->set_id(1);
138 138
 
139 139
 		$product = new \WC_Product_Simple();
140
-		$product->set_name( 'Test Product' );
141
-		$product->set_downloadable( 'yes' );
142
-		$product->set_downloads( array( $prod_download ) );
143
-		$product->set_regular_price( 25 );
140
+		$product->set_name('Test Product');
141
+		$product->set_downloadable('yes');
142
+		$product->set_downloads(array($prod_download));
143
+		$product->set_regular_price(25);
144 144
 		$product->save();
145 145
 
146
-		$order = OrderHelper::create_order( 1, $product );
147
-		$order->set_status( 'completed' );
148
-		$order->set_total( 25 );
146
+		$order = OrderHelper::create_order(1, $product);
147
+		$order->set_status('completed');
148
+		$order->set_total(25);
149 149
 		$order->save();
150 150
 		$order_1 = $order->get_id();
151 151
 
152 152
 		$download = new \WC_Customer_Download();
153
-		$download->set_user_id( 1 );
154
-		$download->set_order_id( $order->get_id() );
155
-		$download->set_product_id( $product->get_id() );
156
-		$download->set_download_id( $prod_download->get_id() );
153
+		$download->set_user_id(1);
154
+		$download->set_order_id($order->get_id());
155
+		$download->set_product_id($product->get_id());
156
+		$download->set_download_id($prod_download->get_id());
157 157
 		$download->save();
158 158
 
159
-		for ( $i = 1; $i < 3; $i++ ) {
159
+		for ($i = 1; $i < 3; $i++) {
160 160
 			$object = new \WC_Customer_Download_Log();
161
-			$object->set_permission_id( $download->get_id() );
162
-			$object->set_user_id( 1 );
163
-			$object->set_user_ip_address( '1.2.3.4' );
161
+			$object->set_permission_id($download->get_id());
162
+			$object->set_user_id(1);
163
+			$object->set_user_ip_address('1.2.3.4');
164 164
 			$id = $object->save();
165 165
 		}
166 166
 
167
-		$order = OrderHelper::create_order( 2, $product );
168
-		$order->set_status( 'completed' );
169
-		$order->set_total( 10 );
167
+		$order = OrderHelper::create_order(2, $product);
168
+		$order->set_status('completed');
169
+		$order->set_total(10);
170 170
 		$order->save();
171 171
 
172 172
 		$download = new \WC_Customer_Download();
173
-		$download->set_user_id( 2 );
174
-		$download->set_order_id( $order->get_id() );
175
-		$download->set_product_id( $product->get_id() );
176
-		$download->set_download_id( $prod_download->get_id() );
173
+		$download->set_user_id(2);
174
+		$download->set_order_id($order->get_id());
175
+		$download->set_product_id($product->get_id());
176
+		$download->set_download_id($prod_download->get_id());
177 177
 		$download->save();
178 178
 
179 179
 		$object = new \WC_Customer_Download_Log();
180
-		$object->set_permission_id( $download->get_id() );
181
-		$object->set_user_id( 2 );
182
-		$object->set_user_ip_address( '5.4.3.2.1' );
180
+		$object->set_permission_id($download->get_id());
181
+		$object->set_user_id(2);
182
+		$object->set_user_ip_address('5.4.3.2.1');
183 183
 		$object->save();
184 184
 
185 185
 		$customer_id = $wpdb->get_col(
@@ -190,30 +190,30 @@  discard block
 block discarded – undo
190 190
 		);
191 191
 
192 192
 		// Test includes filtering.
193
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
193
+		$request = new WP_REST_Request('GET', $this->endpoint);
194 194
 		$request->set_query_params(
195 195
 			array(
196 196
 				'customer_includes' => $customer_id,
197 197
 			)
198 198
 		);
199
-		$response = $this->server->dispatch( $request );
199
+		$response = $this->server->dispatch($request);
200 200
 		$reports  = $response->get_data();
201 201
 
202
-		$this->assertEquals( 200, $response->get_status() );
203
-		$this->assertEquals( 2, $reports['totals']['download_count'] );
202
+		$this->assertEquals(200, $response->get_status());
203
+		$this->assertEquals(2, $reports['totals']['download_count']);
204 204
 
205 205
 		// Test excludes filtering.
206
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
206
+		$request = new WP_REST_Request('GET', $this->endpoint);
207 207
 		$request->set_query_params(
208 208
 			array(
209 209
 				'customer_excludes' => $customer_id,
210 210
 			)
211 211
 		);
212
-		$response = $this->server->dispatch( $request );
212
+		$response = $this->server->dispatch($request);
213 213
 		$reports  = $response->get_data();
214 214
 
215
-		$this->assertEquals( 200, $response->get_status() );
216
-		$this->assertEquals( 1, $reports['totals']['download_count'] );
215
+		$this->assertEquals(200, $response->get_status());
216
+		$this->assertEquals(1, $reports['totals']['download_count']);
217 217
 	}
218 218
 
219 219
 	/**
@@ -224,135 +224,135 @@  discard block
 block discarded – undo
224 224
 
225 225
 		// Populate all of the data.
226 226
 		$prod_download = new \WC_Product_Download();
227
-		$prod_download->set_file( plugin_dir_url( __FILE__ ) . '/assets/images/help.png' );
228
-		$prod_download->set_id( 1 );
227
+		$prod_download->set_file(plugin_dir_url(__FILE__) . '/assets/images/help.png');
228
+		$prod_download->set_id(1);
229 229
 
230 230
 		$product = new \WC_Product_Simple();
231
-		$product->set_name( 'Test Product' );
232
-		$product->set_downloadable( 'yes' );
233
-		$product->set_downloads( array( $prod_download ) );
234
-		$product->set_regular_price( 25 );
231
+		$product->set_name('Test Product');
232
+		$product->set_downloadable('yes');
233
+		$product->set_downloads(array($prod_download));
234
+		$product->set_regular_price(25);
235 235
 		$product->save();
236 236
 
237
-		$order = OrderHelper::create_order( 1, $product );
238
-		$order->set_status( 'completed' );
239
-		$order->set_total( 100 );
237
+		$order = OrderHelper::create_order(1, $product);
238
+		$order->set_status('completed');
239
+		$order->set_total(100);
240 240
 		$order->save();
241 241
 
242 242
 		$download = new \WC_Customer_Download();
243
-		$download->set_user_id( $this->user );
244
-		$download->set_order_id( $order->get_id() );
245
-		$download->set_product_id( $product->get_id() );
246
-		$download->set_download_id( $prod_download->get_id() );
243
+		$download->set_user_id($this->user);
244
+		$download->set_order_id($order->get_id());
245
+		$download->set_product_id($product->get_id());
246
+		$download->set_download_id($prod_download->get_id());
247 247
 		$download->save();
248 248
 
249 249
 		$object = new \WC_Customer_Download_Log();
250
-		$object->set_permission_id( $download->get_id() );
251
-		$object->set_user_id( $this->user );
252
-		$object->set_user_ip_address( '1.2.3.4' );
250
+		$object->set_permission_id($download->get_id());
251
+		$object->set_user_id($this->user);
252
+		$object->set_user_ip_address('1.2.3.4');
253 253
 		$object->save();
254 254
 
255 255
 		$object = new \WC_Customer_Download_Log();
256
-		$object->set_permission_id( $download->get_id() );
257
-		$object->set_user_id( $this->user );
258
-		$object->set_user_ip_address( '1.2.3.4' );
256
+		$object->set_permission_id($download->get_id());
257
+		$object->set_user_id($this->user);
258
+		$object->set_user_ip_address('1.2.3.4');
259 259
 		$object->save();
260 260
 
261 261
 		$object = new \WC_Customer_Download_Log();
262
-		$object->set_permission_id( $download->get_id() );
263
-		$object->set_user_id( $this->user );
264
-		$object->set_user_ip_address( '1.2.3.4' );
262
+		$object->set_permission_id($download->get_id());
263
+		$object->set_user_id($this->user);
264
+		$object->set_user_ip_address('1.2.3.4');
265 265
 		$object->save();
266 266
 
267
-		$three_days_from_now = current_time( 'timestamp', true ) - ( 3 * DAY_IN_SECONDS );
267
+		$three_days_from_now = current_time('timestamp', true) - (3 * DAY_IN_SECONDS);
268 268
 
269 269
 		$object = new \WC_Customer_Download_Log();
270
-		$object->set_permission_id( $download->get_id() );
271
-		$object->set_user_id( $this->user );
272
-		$object->set_user_ip_address( '1.2.3.4' );
273
-		$object->set_timestamp( $three_days_from_now );
270
+		$object->set_permission_id($download->get_id());
271
+		$object->set_user_id($this->user);
272
+		$object->set_user_ip_address('1.2.3.4');
273
+		$object->set_timestamp($three_days_from_now);
274 274
 		$object->save();
275 275
 
276 276
 		$time           = time();
277
-		$seven_days_ago = $time - ( 7 * DAY_IN_SECONDS );
277
+		$seven_days_ago = $time - (7 * DAY_IN_SECONDS);
278 278
 
279 279
 		// Test sorting by download_count.
280
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
280
+		$request = new WP_REST_Request('GET', $this->endpoint);
281 281
 		$request->set_query_params(
282 282
 			array(
283
-				'before'   => date( 'Y-m-d 23:59:59', $time ),
284
-				'after'    => date( 'Y-m-d H:00:00', $seven_days_ago ),
283
+				'before'   => date('Y-m-d 23:59:59', $time),
284
+				'after'    => date('Y-m-d H:00:00', $seven_days_ago),
285 285
 				'interval' => 'day',
286 286
 				'orderby'  => 'download_count',
287 287
 			)
288 288
 		);
289
-		$response = $this->server->dispatch( $request );
289
+		$response = $this->server->dispatch($request);
290 290
 		$reports  = $response->get_data();
291 291
 
292
-		$this->assertEquals( 3, $reports['intervals'][0]['subtotals']->download_count );
293
-		$this->assertEquals( date( 'Y-m-d', $time ), $reports['intervals'][0]['interval'] );
292
+		$this->assertEquals(3, $reports['intervals'][0]['subtotals']->download_count);
293
+		$this->assertEquals(date('Y-m-d', $time), $reports['intervals'][0]['interval']);
294 294
 
295
-		$this->assertEquals( 1, $reports['intervals'][1]['subtotals']->download_count );
296
-		$this->assertEquals( date( 'Y-m-d', $three_days_from_now ), $reports['intervals'][1]['interval'] );
295
+		$this->assertEquals(1, $reports['intervals'][1]['subtotals']->download_count);
296
+		$this->assertEquals(date('Y-m-d', $three_days_from_now), $reports['intervals'][1]['interval']);
297 297
 
298 298
 		// Test sorting by date.
299
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
299
+		$request = new WP_REST_Request('GET', $this->endpoint);
300 300
 		$request->set_query_params(
301 301
 			array(
302
-				'before'   => date( 'Y-m-d 23:59:59', $time ),
303
-				'after'    => date( 'Y-m-d H:00:00', $seven_days_ago ),
302
+				'before'   => date('Y-m-d 23:59:59', $time),
303
+				'after'    => date('Y-m-d H:00:00', $seven_days_ago),
304 304
 				'interval' => 'day',
305 305
 				'orderby'  => 'date',
306 306
 				'order'    => 'asc',
307 307
 			)
308 308
 		);
309
-		$response = $this->server->dispatch( $request );
309
+		$response = $this->server->dispatch($request);
310 310
 		$reports  = $response->get_data();
311 311
 
312
-		$this->assertEquals( 0, $reports['intervals'][0]['subtotals']->download_count );
313
-		$this->assertEquals( date( 'Y-m-d', $seven_days_ago ), $reports['intervals'][0]['interval'] );
312
+		$this->assertEquals(0, $reports['intervals'][0]['subtotals']->download_count);
313
+		$this->assertEquals(date('Y-m-d', $seven_days_ago), $reports['intervals'][0]['interval']);
314 314
 
315
-		$this->assertEquals( 3, $reports['intervals'][7]['subtotals']->download_count );
316
-		$this->assertEquals( date( 'Y-m-d', $time ), $reports['intervals'][7]['interval'] );
315
+		$this->assertEquals(3, $reports['intervals'][7]['subtotals']->download_count);
316
+		$this->assertEquals(date('Y-m-d', $time), $reports['intervals'][7]['interval']);
317 317
 	}
318 318
 
319 319
 	/**
320 320
 	 * Test getting reports without valid permissions.
321 321
 	 */
322 322
 	public function test_get_reports_without_permission() {
323
-		wp_set_current_user( 0 );
324
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
325
-		$this->assertEquals( 401, $response->get_status() );
323
+		wp_set_current_user(0);
324
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
325
+		$this->assertEquals(401, $response->get_status());
326 326
 	}
327 327
 
328 328
 	/**
329 329
 	 * Test reports schema.
330 330
 	 */
331 331
 	public function test_reports_schema() {
332
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
333
-		$response   = $this->server->dispatch( $request );
332
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
333
+		$response   = $this->server->dispatch($request);
334 334
 		$data       = $response->get_data();
335 335
 		$properties = $data['schema']['properties'];
336 336
 
337
-		$this->assertEquals( 2, count( $properties ) );
338
-		$this->assertArrayHasKey( 'totals', $properties );
339
-		$this->assertArrayHasKey( 'intervals', $properties );
337
+		$this->assertEquals(2, count($properties));
338
+		$this->assertArrayHasKey('totals', $properties);
339
+		$this->assertArrayHasKey('intervals', $properties);
340 340
 
341 341
 		$totals = $properties['totals']['properties'];
342
-		$this->assertEquals( 1, count( $totals ) );
343
-		$this->assertArrayHasKey( 'download_count', $totals );
342
+		$this->assertEquals(1, count($totals));
343
+		$this->assertArrayHasKey('download_count', $totals);
344 344
 
345 345
 		$intervals = $properties['intervals']['items']['properties'];
346
-		$this->assertEquals( 6, count( $intervals ) );
347
-		$this->assertArrayHasKey( 'interval', $intervals );
348
-		$this->assertArrayHasKey( 'date_start', $intervals );
349
-		$this->assertArrayHasKey( 'date_start_gmt', $intervals );
350
-		$this->assertArrayHasKey( 'date_end', $intervals );
351
-		$this->assertArrayHasKey( 'date_end_gmt', $intervals );
352
-		$this->assertArrayHasKey( 'subtotals', $intervals );
346
+		$this->assertEquals(6, count($intervals));
347
+		$this->assertArrayHasKey('interval', $intervals);
348
+		$this->assertArrayHasKey('date_start', $intervals);
349
+		$this->assertArrayHasKey('date_start_gmt', $intervals);
350
+		$this->assertArrayHasKey('date_end', $intervals);
351
+		$this->assertArrayHasKey('date_end_gmt', $intervals);
352
+		$this->assertArrayHasKey('subtotals', $intervals);
353 353
 
354 354
 		$subtotals = $properties['intervals']['items']['properties']['subtotals']['properties'];
355
-		$this->assertEquals( 1, count( $subtotals ) );
356
-		$this->assertArrayHasKey( 'download_count', $subtotals );
355
+		$this->assertEquals(1, count($subtotals));
356
+		$this->assertArrayHasKey('download_count', $subtotals);
357 357
 	}
358 358
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/CouponsStats.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
13 13
 use \WP_REST_Request;
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	public function test_register_routes() {
35 35
 		$routes = $this->server->get_routes();
36 36
 
37
-		$this->assertArrayHasKey( $this->endpoint, $routes );
37
+		$this->assertArrayHasKey($this->endpoint, $routes);
38 38
 	}
39 39
 
40 40
 	/**
@@ -44,56 +44,56 @@  discard block
 block discarded – undo
44 44
 		// Populate all of the data.
45 45
 		// Simple product.
46 46
 		$product = new \WC_Product_Simple();
47
-		$product->set_name( 'Test Product' );
48
-		$product->set_regular_price( 25 );
47
+		$product->set_name('Test Product');
48
+		$product->set_regular_price(25);
49 49
 		$product->save();
50 50
 
51 51
 		// Coupons.
52 52
 		$coupon_1_amount = 1; // by default in create_coupon.
53
-		$coupon_1        = CouponHelper::create_coupon( 'coupon_1' );
53
+		$coupon_1        = CouponHelper::create_coupon('coupon_1');
54 54
 
55 55
 		$coupon_2_amount = 2;
56
-		$coupon_2        = CouponHelper::create_coupon( 'coupon_2' );
57
-		$coupon_2->set_amount( $coupon_2_amount );
56
+		$coupon_2        = CouponHelper::create_coupon('coupon_2');
57
+		$coupon_2->set_amount($coupon_2_amount);
58 58
 		$coupon_2->save();
59 59
 
60 60
 		// Order without coupon.
61
-		$order = OrderHelper::create_order( 1, $product );
62
-		$order->set_status( 'completed' );
63
-		$order->set_total( 100 ); // $25 x 4.
61
+		$order = OrderHelper::create_order(1, $product);
62
+		$order->set_status('completed');
63
+		$order->set_total(100); // $25 x 4.
64 64
 		$order->save();
65 65
 
66 66
 		$time = time();
67 67
 
68 68
 		// Order with 1 coupon.
69
-		$order_1c = OrderHelper::create_order( 1, $product );
70
-		$order_1c->set_status( 'completed' );
71
-		$order_1c->apply_coupon( $coupon_1 );
69
+		$order_1c = OrderHelper::create_order(1, $product);
70
+		$order_1c->set_status('completed');
71
+		$order_1c->apply_coupon($coupon_1);
72 72
 		$order_1c->calculate_totals();
73
-		$order_1c->set_date_created( $time );
73
+		$order_1c->set_date_created($time);
74 74
 		$order_1c->save();
75 75
 
76 76
 		// Order with 2 coupons.
77
-		$order_2c = OrderHelper::create_order( 1, $product );
78
-		$order_2c->set_status( 'completed' );
79
-		$order_2c->apply_coupon( $coupon_1 );
80
-		$order_2c->apply_coupon( $coupon_2 );
77
+		$order_2c = OrderHelper::create_order(1, $product);
78
+		$order_2c->set_status('completed');
79
+		$order_2c->apply_coupon($coupon_1);
80
+		$order_2c->apply_coupon($coupon_2);
81 81
 		$order_2c->calculate_totals();
82
-		$order_2c->set_date_created( $time );
82
+		$order_2c->set_date_created($time);
83 83
 		$order_2c->save();
84 84
 
85 85
 		QueueHelper::run_all_pending();
86 86
 
87
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
87
+		$request = new WP_REST_Request('GET', $this->endpoint);
88 88
 		$request->set_query_params(
89 89
 			array(
90
-				'before'   => date( 'Y-m-d 23:59:59', $time ),
91
-				'after'    => date( 'Y-m-d 00:00:00', $time ),
90
+				'before'   => date('Y-m-d 23:59:59', $time),
91
+				'after'    => date('Y-m-d 00:00:00', $time),
92 92
 				'interval' => 'day',
93 93
 			)
94 94
 		);
95 95
 
96
-		$response = $this->server->dispatch( $request );
96
+		$response = $this->server->dispatch($request);
97 97
 		$reports  = $response->get_data();
98 98
 
99 99
 		$expected_reports = array(
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
 			),
106 106
 			'intervals' => array(
107 107
 				array(
108
-					'interval'       => date( 'Y-m-d', $time ),
109
-					'date_start'     => date( 'Y-m-d 00:00:00', $time ),
110
-					'date_start_gmt' => date( 'Y-m-d 00:00:00', $time ),
111
-					'date_end'       => date( 'Y-m-d 23:59:59', $time ),
112
-					'date_end_gmt'   => date( 'Y-m-d 23:59:59', $time ),
108
+					'interval'       => date('Y-m-d', $time),
109
+					'date_start'     => date('Y-m-d 00:00:00', $time),
110
+					'date_start_gmt' => date('Y-m-d 00:00:00', $time),
111
+					'date_end'       => date('Y-m-d 23:59:59', $time),
112
+					'date_end_gmt'   => date('Y-m-d 23:59:59', $time),
113 113
 					'subtotals'      => (object) array(
114 114
 						'amount'        => 4.0,
115 115
 						'coupons_count' => 2,
@@ -120,54 +120,54 @@  discard block
 block discarded – undo
120 120
 			),
121 121
 		);
122 122
 
123
-		$this->assertEquals( 200, $response->get_status() );
124
-		$this->assertEquals( $expected_reports, $reports );
123
+		$this->assertEquals(200, $response->get_status());
124
+		$this->assertEquals($expected_reports, $reports);
125 125
 	}
126 126
 
127 127
 	/**
128 128
 	 * Test getting reports without valid permissions.
129 129
 	 */
130 130
 	public function test_get_reports_without_permission() {
131
-		wp_set_current_user( 0 );
132
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
133
-		$this->assertEquals( 401, $response->get_status() );
131
+		wp_set_current_user(0);
132
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
133
+		$this->assertEquals(401, $response->get_status());
134 134
 	}
135 135
 
136 136
 	/**
137 137
 	 * Test reports schema.
138 138
 	 */
139 139
 	public function test_reports_schema() {
140
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
141
-		$response   = $this->server->dispatch( $request );
140
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
141
+		$response   = $this->server->dispatch($request);
142 142
 		$data       = $response->get_data();
143 143
 		$properties = $data['schema']['properties'];
144 144
 
145
-		$this->assertEquals( 2, count( $properties ) );
146
-		$this->assertArrayHasKey( 'totals', $properties );
147
-		$this->assertArrayHasKey( 'intervals', $properties );
145
+		$this->assertEquals(2, count($properties));
146
+		$this->assertArrayHasKey('totals', $properties);
147
+		$this->assertArrayHasKey('intervals', $properties);
148 148
 
149 149
 		$totals = $properties['totals']['properties'];
150
-		$this->assertEquals( 4, count( $totals ) );
151
-		$this->assertArrayHasKey( 'amount', $totals );
152
-		$this->assertArrayHasKey( 'coupons_count', $totals );
153
-		$this->assertArrayHasKey( 'orders_count', $totals );
154
-		$this->assertArrayHasKey( 'segments', $totals );
150
+		$this->assertEquals(4, count($totals));
151
+		$this->assertArrayHasKey('amount', $totals);
152
+		$this->assertArrayHasKey('coupons_count', $totals);
153
+		$this->assertArrayHasKey('orders_count', $totals);
154
+		$this->assertArrayHasKey('segments', $totals);
155 155
 
156 156
 		$intervals = $properties['intervals']['items']['properties'];
157
-		$this->assertEquals( 6, count( $intervals ) );
158
-		$this->assertArrayHasKey( 'interval', $intervals );
159
-		$this->assertArrayHasKey( 'date_start', $intervals );
160
-		$this->assertArrayHasKey( 'date_start_gmt', $intervals );
161
-		$this->assertArrayHasKey( 'date_end', $intervals );
162
-		$this->assertArrayHasKey( 'date_end_gmt', $intervals );
163
-		$this->assertArrayHasKey( 'subtotals', $intervals );
157
+		$this->assertEquals(6, count($intervals));
158
+		$this->assertArrayHasKey('interval', $intervals);
159
+		$this->assertArrayHasKey('date_start', $intervals);
160
+		$this->assertArrayHasKey('date_start_gmt', $intervals);
161
+		$this->assertArrayHasKey('date_end', $intervals);
162
+		$this->assertArrayHasKey('date_end_gmt', $intervals);
163
+		$this->assertArrayHasKey('subtotals', $intervals);
164 164
 
165 165
 		$subtotals = $properties['intervals']['items']['properties']['subtotals']['properties'];
166
-		$this->assertEquals( 4, count( $subtotals ) );
167
-		$this->assertArrayHasKey( 'amount', $subtotals );
168
-		$this->assertArrayHasKey( 'coupons_count', $subtotals );
169
-		$this->assertArrayHasKey( 'orders_count', $subtotals );
170
-		$this->assertArrayHasKey( 'segments', $subtotals );
166
+		$this->assertEquals(4, count($subtotals));
167
+		$this->assertArrayHasKey('amount', $subtotals);
168
+		$this->assertArrayHasKey('coupons_count', $subtotals);
169
+		$this->assertArrayHasKey('orders_count', $subtotals);
170
+		$this->assertArrayHasKey('segments', $subtotals);
171 171
 
172 172
 	}
173 173
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/StockStats.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
13 13
 use \WP_REST_Request;
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	public function test_register_routes() {
34 34
 		$routes = $this->server->get_routes();
35 35
 
36
-		$this->assertArrayHasKey( $this->endpoint, $routes );
36
+		$this->assertArrayHasKey($this->endpoint, $routes);
37 37
 	}
38 38
 
39 39
 	/**
@@ -41,91 +41,91 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function test_get_reports() {
43 43
 		$number_of_low_stock = 3;
44
-		for ( $i = 1; $i <= $number_of_low_stock; $i++ ) {
44
+		for ($i = 1; $i <= $number_of_low_stock; $i++) {
45 45
 			$low_stock = new \WC_Product_Simple();
46
-			$low_stock->set_name( "Test low stock {$i}" );
47
-			$low_stock->set_regular_price( 5 );
48
-			$low_stock->set_manage_stock( true );
49
-			$low_stock->set_stock_quantity( 1 );
50
-			$low_stock->set_stock_status( 'instock' );
46
+			$low_stock->set_name("Test low stock {$i}");
47
+			$low_stock->set_regular_price(5);
48
+			$low_stock->set_manage_stock(true);
49
+			$low_stock->set_stock_quantity(1);
50
+			$low_stock->set_stock_status('instock');
51 51
 			$low_stock->save();
52 52
 		}
53 53
 
54 54
 		$number_of_out_of_stock = 6;
55
-		for ( $i = 1; $i <= $number_of_out_of_stock; $i++ ) {
55
+		for ($i = 1; $i <= $number_of_out_of_stock; $i++) {
56 56
 			$out_of_stock = new \WC_Product_Simple();
57
-			$out_of_stock->set_name( "Test out of stock {$i}" );
58
-			$out_of_stock->set_regular_price( 5 );
59
-			$out_of_stock->set_stock_status( 'outofstock' );
57
+			$out_of_stock->set_name("Test out of stock {$i}");
58
+			$out_of_stock->set_regular_price(5);
59
+			$out_of_stock->set_stock_status('outofstock');
60 60
 			$out_of_stock->save();
61 61
 		}
62 62
 
63 63
 		$number_of_in_stock = 10;
64
-		for ( $i = 1; $i <= $number_of_in_stock; $i++ ) {
64
+		for ($i = 1; $i <= $number_of_in_stock; $i++) {
65 65
 			$in_stock = new \WC_Product_Simple();
66
-			$in_stock->set_name( "Test in stock {$i}" );
67
-			$in_stock->set_regular_price( 25 );
66
+			$in_stock->set_name("Test in stock {$i}");
67
+			$in_stock->set_regular_price(25);
68 68
 			$in_stock->save();
69 69
 		}
70 70
 
71
-		$request  = new WP_REST_Request( 'GET', $this->endpoint );
72
-		$response = $this->server->dispatch( $request );
71
+		$request  = new WP_REST_Request('GET', $this->endpoint);
72
+		$response = $this->server->dispatch($request);
73 73
 		$reports  = $response->get_data();
74 74
 
75
-		$this->assertEquals( 200, $response->get_status() );
75
+		$this->assertEquals(200, $response->get_status());
76 76
 
77
-		$this->assertArrayHasKey( 'totals', $reports );
78
-		$this->assertEquals( 19, $reports['totals']['products'] );
79
-		$this->assertEquals( 6, $reports['totals']['outofstock'] );
80
-		$this->assertEquals( 0, $reports['totals']['onbackorder'] );
81
-		$this->assertEquals( 3, $reports['totals']['lowstock'] );
82
-		$this->assertEquals( 13, $reports['totals']['instock'] );
77
+		$this->assertArrayHasKey('totals', $reports);
78
+		$this->assertEquals(19, $reports['totals']['products']);
79
+		$this->assertEquals(6, $reports['totals']['outofstock']);
80
+		$this->assertEquals(0, $reports['totals']['onbackorder']);
81
+		$this->assertEquals(3, $reports['totals']['lowstock']);
82
+		$this->assertEquals(13, $reports['totals']['instock']);
83 83
 
84 84
 		// Test backorder and cache update.
85 85
 		$backorder_stock = new \WC_Product_Simple();
86
-		$backorder_stock->set_name( 'Test backorder' );
87
-		$backorder_stock->set_regular_price( 5 );
88
-		$backorder_stock->set_stock_status( 'onbackorder' );
86
+		$backorder_stock->set_name('Test backorder');
87
+		$backorder_stock->set_regular_price(5);
88
+		$backorder_stock->set_stock_status('onbackorder');
89 89
 		$backorder_stock->save();
90 90
 
91
-		$request  = new WP_REST_Request( 'GET', $this->endpoint );
92
-		$response = $this->server->dispatch( $request );
91
+		$request  = new WP_REST_Request('GET', $this->endpoint);
92
+		$response = $this->server->dispatch($request);
93 93
 		$reports  = $response->get_data();
94 94
 
95
-		$this->assertEquals( 200, $response->get_status() );
95
+		$this->assertEquals(200, $response->get_status());
96 96
 
97
-		$this->assertEquals( 20, $reports['totals']['products'] );
98
-		$this->assertEquals( 6, $reports['totals']['outofstock'] );
99
-		$this->assertEquals( 1, $reports['totals']['onbackorder'] );
100
-		$this->assertEquals( 3, $reports['totals']['lowstock'] );
101
-		$this->assertEquals( 13, $reports['totals']['instock'] );
97
+		$this->assertEquals(20, $reports['totals']['products']);
98
+		$this->assertEquals(6, $reports['totals']['outofstock']);
99
+		$this->assertEquals(1, $reports['totals']['onbackorder']);
100
+		$this->assertEquals(3, $reports['totals']['lowstock']);
101
+		$this->assertEquals(13, $reports['totals']['instock']);
102 102
 	}
103 103
 
104 104
 	/**
105 105
 	 * Test getting reports without valid permissions.
106 106
 	 */
107 107
 	public function test_get_reports_without_permission() {
108
-		wp_set_current_user( 0 );
109
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
110
-		$this->assertEquals( 401, $response->get_status() );
108
+		wp_set_current_user(0);
109
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
110
+		$this->assertEquals(401, $response->get_status());
111 111
 	}
112 112
 
113 113
 	/**
114 114
 	 * Test reports schema.
115 115
 	 */
116 116
 	public function test_reports_schema() {
117
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
118
-		$response   = $this->server->dispatch( $request );
117
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
118
+		$response   = $this->server->dispatch($request);
119 119
 		$data       = $response->get_data();
120 120
 		$properties = $data['schema']['properties'];
121 121
 
122
-		$this->assertCount( 1, $properties );
123
-		$this->assertArrayHasKey( 'totals', $properties );
124
-		$this->assertCount( 5, $properties['totals']['properties'] );
125
-		$this->assertArrayHasKey( 'products', $properties['totals']['properties'] );
126
-		$this->assertArrayHasKey( 'outofstock', $properties['totals']['properties'] );
127
-		$this->assertArrayHasKey( 'onbackorder', $properties['totals']['properties'] );
128
-		$this->assertArrayHasKey( 'lowstock', $properties['totals']['properties'] );
129
-		$this->assertArrayHasKey( 'instock', $properties['totals']['properties'] );
122
+		$this->assertCount(1, $properties);
123
+		$this->assertArrayHasKey('totals', $properties);
124
+		$this->assertCount(5, $properties['totals']['properties']);
125
+		$this->assertArrayHasKey('products', $properties['totals']['properties']);
126
+		$this->assertArrayHasKey('outofstock', $properties['totals']['properties']);
127
+		$this->assertArrayHasKey('onbackorder', $properties['totals']['properties']);
128
+		$this->assertArrayHasKey('lowstock', $properties['totals']['properties']);
129
+		$this->assertArrayHasKey('instock', $properties['totals']['properties']);
130 130
 	}
131 131
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/ProductStats.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	public function test_register_routes() {
37 37
 		$routes = $this->server->get_routes();
38 38
 
39
-		$this->assertArrayHasKey( $this->endpoint, $routes );
39
+		$this->assertArrayHasKey($this->endpoint, $routes);
40 40
 	}
41 41
 
42 42
 	/**
@@ -47,34 +47,34 @@  discard block
 block discarded – undo
47 47
 	public function test_get_reports() {
48 48
 		// Populate all of the data.
49 49
 		$product = new \WC_Product_Simple();
50
-		$product->set_name( 'Test Product' );
51
-		$product->set_regular_price( 25 );
50
+		$product->set_name('Test Product');
51
+		$product->set_regular_price(25);
52 52
 		$product->save();
53 53
 
54 54
 		$time = time();
55 55
 
56
-		$order = OrderHelper::create_order( 1, $product );
57
-		$order->set_status( 'completed' );
58
-		$order->set_shipping_total( 10 );
59
-		$order->set_discount_total( 20 );
60
-		$order->set_discount_tax( 0 );
61
-		$order->set_cart_tax( 5 );
62
-		$order->set_shipping_tax( 2 );
63
-		$order->set_total( 97 ); // $25x4 products + $10 shipping - $20 discount + $7 tax.
56
+		$order = OrderHelper::create_order(1, $product);
57
+		$order->set_status('completed');
58
+		$order->set_shipping_total(10);
59
+		$order->set_discount_total(20);
60
+		$order->set_discount_tax(0);
61
+		$order->set_cart_tax(5);
62
+		$order->set_shipping_tax(2);
63
+		$order->set_total(97); // $25x4 products + $10 shipping - $20 discount + $7 tax.
64 64
 		$order->save();
65 65
 
66 66
 		QueueHelper::run_all_pending();
67 67
 
68
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
68
+		$request = new WP_REST_Request('GET', $this->endpoint);
69 69
 		$request->set_query_params(
70 70
 			array(
71
-				'before'   => date( 'Y-m-d 23:59:59', $time ),
72
-				'after'    => date( 'Y-m-d 00:00:00', $time ),
71
+				'before'   => date('Y-m-d 23:59:59', $time),
72
+				'after'    => date('Y-m-d 00:00:00', $time),
73 73
 				'interval' => 'day',
74 74
 			)
75 75
 		);
76 76
 
77
-		$response = $this->server->dispatch( $request );
77
+		$response = $this->server->dispatch($request);
78 78
 		$reports  = $response->get_data();
79 79
 
80 80
 		$expected_reports = array(
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 			),
89 89
 			'intervals' => array(
90 90
 				array(
91
-					'interval'       => date( 'Y-m-d', $time ),
92
-					'date_start'     => date( 'Y-m-d 00:00:00', $time ),
93
-					'date_start_gmt' => date( 'Y-m-d 00:00:00', $time ),
94
-					'date_end'       => date( 'Y-m-d 23:59:59', $time ),
95
-					'date_end_gmt'   => date( 'Y-m-d 23:59:59', $time ),
91
+					'interval'       => date('Y-m-d', $time),
92
+					'date_start'     => date('Y-m-d 00:00:00', $time),
93
+					'date_start_gmt' => date('Y-m-d 00:00:00', $time),
94
+					'date_end'       => date('Y-m-d 23:59:59', $time),
95
+					'date_end_gmt'   => date('Y-m-d 23:59:59', $time),
96 96
 					'subtotals'      => (object) array(
97 97
 						'items_sold'       => 4,
98 98
 						'net_revenue'      => 100.0,
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 			),
106 106
 		);
107 107
 
108
-		$this->assertEquals( 200, $response->get_status() );
109
-		$this->assertEquals( $expected_reports, $reports );
108
+		$this->assertEquals(200, $response->get_status());
109
+		$this->assertEquals($expected_reports, $reports);
110 110
 	}
111 111
 
112 112
 	/**
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 	 * @since 3.5.0
116 116
 	 */
117 117
 	public function test_get_reports_without_permission() {
118
-		wp_set_current_user( 0 );
119
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
120
-		$this->assertEquals( 401, $response->get_status() );
118
+		wp_set_current_user(0);
119
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
120
+		$this->assertEquals(401, $response->get_status());
121 121
 	}
122 122
 
123 123
 	/**
@@ -126,36 +126,36 @@  discard block
 block discarded – undo
126 126
 	 * @since 3.5.0
127 127
 	 */
128 128
 	public function test_reports_schema() {
129
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
130
-		$response   = $this->server->dispatch( $request );
129
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
130
+		$response   = $this->server->dispatch($request);
131 131
 		$data       = $response->get_data();
132 132
 		$properties = $data['schema']['properties'];
133 133
 
134
-		$this->assertEquals( 2, count( $properties ) );
135
-		$this->assertArrayHasKey( 'totals', $properties );
136
-		$this->assertArrayHasKey( 'intervals', $properties );
134
+		$this->assertEquals(2, count($properties));
135
+		$this->assertArrayHasKey('totals', $properties);
136
+		$this->assertArrayHasKey('intervals', $properties);
137 137
 
138 138
 		$totals = $properties['totals']['properties'];
139
-		$this->assertEquals( 4, count( $totals ) );
140
-		$this->assertArrayHasKey( 'net_revenue', $totals );
141
-		$this->assertArrayHasKey( 'items_sold', $totals );
142
-		$this->assertArrayHasKey( 'orders_count', $totals );
143
-		$this->assertArrayHasKey( 'segments', $totals );
139
+		$this->assertEquals(4, count($totals));
140
+		$this->assertArrayHasKey('net_revenue', $totals);
141
+		$this->assertArrayHasKey('items_sold', $totals);
142
+		$this->assertArrayHasKey('orders_count', $totals);
143
+		$this->assertArrayHasKey('segments', $totals);
144 144
 
145 145
 		$intervals = $properties['intervals']['items']['properties'];
146
-		$this->assertEquals( 6, count( $intervals ) );
147
-		$this->assertArrayHasKey( 'interval', $intervals );
148
-		$this->assertArrayHasKey( 'date_start', $intervals );
149
-		$this->assertArrayHasKey( 'date_start_gmt', $intervals );
150
-		$this->assertArrayHasKey( 'date_end', $intervals );
151
-		$this->assertArrayHasKey( 'date_end_gmt', $intervals );
152
-		$this->assertArrayHasKey( 'subtotals', $intervals );
146
+		$this->assertEquals(6, count($intervals));
147
+		$this->assertArrayHasKey('interval', $intervals);
148
+		$this->assertArrayHasKey('date_start', $intervals);
149
+		$this->assertArrayHasKey('date_start_gmt', $intervals);
150
+		$this->assertArrayHasKey('date_end', $intervals);
151
+		$this->assertArrayHasKey('date_end_gmt', $intervals);
152
+		$this->assertArrayHasKey('subtotals', $intervals);
153 153
 
154 154
 		$subtotals = $properties['intervals']['items']['properties']['subtotals']['properties'];
155
-		$this->assertEquals( 4, count( $subtotals ) );
156
-		$this->assertArrayHasKey( 'net_revenue', $subtotals );
157
-		$this->assertArrayHasKey( 'items_sold', $subtotals );
158
-		$this->assertArrayHasKey( 'orders_count', $subtotals );
159
-		$this->assertArrayHasKey( 'segments', $subtotals );
155
+		$this->assertEquals(4, count($subtotals));
156
+		$this->assertArrayHasKey('net_revenue', $subtotals);
157
+		$this->assertArrayHasKey('items_sold', $subtotals);
158
+		$this->assertArrayHasKey('orders_count', $subtotals);
159
+		$this->assertArrayHasKey('segments', $subtotals);
160 160
 	}
161 161
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/Import.php 1 patch
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
13 13
 use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	public function test_register_routes() {
51 51
 		$routes = $this->server->get_routes();
52 52
 
53
-		$this->assertArrayHasKey( $this->endpoint, $routes );
53
+		$this->assertArrayHasKey($this->endpoint, $routes);
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,31 +58,31 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @param array $schema Item to check schema.
60 60
 	 */
61
-	public function assert_report_item_schema( $schema ) {
62
-		$this->assertArrayHasKey( 'status', $schema );
63
-		$this->assertArrayHasKey( 'message', $schema );
61
+	public function assert_report_item_schema($schema) {
62
+		$this->assertArrayHasKey('status', $schema);
63
+		$this->assertArrayHasKey('message', $schema);
64 64
 	}
65 65
 
66 66
 	/**
67 67
 	 * Test reports schema.
68 68
 	 */
69 69
 	public function test_reports_schema() {
70
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
71
-		$response   = $this->server->dispatch( $request );
70
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
71
+		$response   = $this->server->dispatch($request);
72 72
 		$data       = $response->get_data();
73 73
 		$properties = $data['schema']['properties'];
74 74
 
75
-		$this->assertCount( 2, $properties );
76
-		$this->assert_report_item_schema( $properties );
75
+		$this->assertCount(2, $properties);
76
+		$this->assert_report_item_schema($properties);
77 77
 	}
78 78
 
79 79
 	/**
80 80
 	 * Test getting reports without valid permissions.
81 81
 	 */
82 82
 	public function test_get_reports_without_permission() {
83
-		wp_set_current_user( 0 );
84
-		$response = $this->server->dispatch( new WP_REST_Request( 'POST', $this->endpoint ) );
85
-		$this->assertEquals( 401, $response->get_status() );
83
+		wp_set_current_user(0);
84
+		$response = $this->server->dispatch(new WP_REST_Request('POST', $this->endpoint));
85
+		$this->assertEquals(401, $response->get_status());
86 86
 	}
87 87
 
88 88
 	/**
@@ -92,56 +92,56 @@  discard block
 block discarded – undo
92 92
 		global $wpdb;
93 93
 		// Populate all of the data.
94 94
 		$product = new \WC_Product_Simple();
95
-		$product->set_name( 'Test Product' );
96
-		$product->set_regular_price( 25 );
95
+		$product->set_name('Test Product');
96
+		$product->set_regular_price(25);
97 97
 		$product->save();
98 98
 
99
-		$order_1 = OrderHelper::create_order( 1, $product );
100
-		$order_1->set_status( 'completed' );
101
-		$order_1->set_date_created( time() - ( 3 * DAY_IN_SECONDS ) );
99
+		$order_1 = OrderHelper::create_order(1, $product);
100
+		$order_1->set_status('completed');
101
+		$order_1->set_date_created(time() - (3 * DAY_IN_SECONDS));
102 102
 		$order_1->save();
103
-		$order_2 = OrderHelper::create_order( 1, $product );
104
-		$order_2->set_total( 100 );
105
-		$order_2->set_status( 'completed' );
103
+		$order_2 = OrderHelper::create_order(1, $product);
104
+		$order_2->set_total(100);
105
+		$order_2->set_status('completed');
106 106
 		$order_2->save();
107 107
 
108 108
 		// Delete order stats so we can test import API.
109
-		$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type = 'scheduled-action'" );
110
-		$wpdb->query( "DELETE FROM {$wpdb->prefix}wc_order_stats" );
109
+		$wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type = 'scheduled-action'");
110
+		$wpdb->query("DELETE FROM {$wpdb->prefix}wc_order_stats");
111 111
 
112 112
 		// Use the days param to only process orders in the last day.
113
-		$request = new WP_REST_Request( 'POST', $this->endpoint );
114
-		$request->set_query_params( array( 'days' => '1' ) );
115
-		$response = $this->server->dispatch( $request );
113
+		$request = new WP_REST_Request('POST', $this->endpoint);
114
+		$request->set_query_params(array('days' => '1'));
115
+		$response = $this->server->dispatch($request);
116 116
 		$report   = $response->get_data();
117 117
 
118
-		$this->assertEquals( 200, $response->get_status() );
119
-		$this->assertEquals( 'success', $report['status'] );
118
+		$this->assertEquals(200, $response->get_status());
119
+		$this->assertEquals('success', $report['status']);
120 120
 
121 121
 		// Run pending thrice to process batch and order.
122 122
 		QueueHelper::run_all_pending();
123 123
 		QueueHelper::run_all_pending();
124 124
 		QueueHelper::run_all_pending();
125 125
 
126
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/reports/customers' );
127
-		$response = $this->server->dispatch( $request );
126
+		$request  = new WP_REST_Request('GET', '/wc/v4/reports/customers');
127
+		$response = $this->server->dispatch($request);
128 128
 		$reports  = $response->get_data();
129 129
 
130
-		$this->assertEquals( 200, $response->get_status() );
131
-		$this->assertCount( 2, $reports );
132
-		$this->assertEquals( $this->customer, $reports[0]['user_id'] );
130
+		$this->assertEquals(200, $response->get_status());
131
+		$this->assertCount(2, $reports);
132
+		$this->assertEquals($this->customer, $reports[0]['user_id']);
133 133
 
134
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/reports/orders' );
135
-		$response = $this->server->dispatch( $request );
134
+		$request  = new WP_REST_Request('GET', '/wc/v4/reports/orders');
135
+		$response = $this->server->dispatch($request);
136 136
 		$reports  = $response->get_data();
137 137
 
138
-		$this->assertEquals( 200, $response->get_status() );
139
-		$this->assertCount( 1, $reports );
140
-		$this->assertEquals( $order_2->get_id(), $reports[0]['order_id'] );
138
+		$this->assertEquals(200, $response->get_status());
139
+		$this->assertCount(1, $reports);
140
+		$this->assertEquals($order_2->get_id(), $reports[0]['order_id']);
141 141
 
142 142
 		// Use the skip existing params to skip processing customers/orders.
143 143
 		// Compare against order status to make sure previously imported order was skipped.
144
-		$order_2->set_status( 'processing' );
144
+		$order_2->set_status('processing');
145 145
 		$order_2->save();
146 146
 
147 147
 		// Compare against name to make sure previously imported customer was skipped.
@@ -153,37 +153,37 @@  discard block
 block discarded – undo
153 153
 		);
154 154
 
155 155
 		// Delete scheduled actions to avoid default order processing.
156
-		$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type = 'scheduled-action'" );
156
+		$wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type = 'scheduled-action'");
157 157
 
158
-		$request = new WP_REST_Request( 'POST', $this->endpoint );
159
-		$request->set_query_params( array( 'skip_existing' => '1' ) );
160
-		$response = $this->server->dispatch( $request );
158
+		$request = new WP_REST_Request('POST', $this->endpoint);
159
+		$request->set_query_params(array('skip_existing' => '1'));
160
+		$response = $this->server->dispatch($request);
161 161
 		$report   = $response->get_data();
162 162
 
163
-		$this->assertEquals( 200, $response->get_status() );
164
-		$this->assertEquals( 'success', $report['status'] );
163
+		$this->assertEquals(200, $response->get_status());
164
+		$this->assertEquals('success', $report['status']);
165 165
 
166 166
 		// Run pending thrice to process batch and order.
167 167
 		QueueHelper::run_all_pending();
168 168
 		QueueHelper::run_all_pending();
169 169
 		QueueHelper::run_all_pending();
170 170
 
171
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/reports/customers' );
172
-		$response = $this->server->dispatch( $request );
171
+		$request  = new WP_REST_Request('GET', '/wc/v4/reports/customers');
172
+		$response = $this->server->dispatch($request);
173 173
 		$reports  = $response->get_data();
174 174
 
175
-		$this->assertEquals( 200, $response->get_status() );
176
-		$this->assertCount( 2, $reports );
177
-		$this->assertEquals( 'Steve User', $reports[0]['name'] );
175
+		$this->assertEquals(200, $response->get_status());
176
+		$this->assertCount(2, $reports);
177
+		$this->assertEquals('Steve User', $reports[0]['name']);
178 178
 
179
-		$request = new WP_REST_Request( 'GET', '/wc/v4/reports/orders' );
180
-		$request->set_query_params( array( 'per_page' => 5 ) );
181
-		$response = $this->server->dispatch( $request );
179
+		$request = new WP_REST_Request('GET', '/wc/v4/reports/orders');
180
+		$request->set_query_params(array('per_page' => 5));
181
+		$response = $this->server->dispatch($request);
182 182
 		$reports  = $response->get_data();
183 183
 
184
-		$this->assertEquals( 200, $response->get_status() );
185
-		$this->assertCount( 2, $reports );
186
-		$this->assertEquals( 'completed', $reports[0]['status'] );
184
+		$this->assertEquals(200, $response->get_status());
185
+		$this->assertCount(2, $reports);
186
+		$this->assertEquals('completed', $reports[0]['status']);
187 187
 	}
188 188
 
189 189
 	/**
@@ -192,30 +192,30 @@  discard block
 block discarded – undo
192 192
 	public function test_cancel_import() {
193 193
 		// Populate all of the data.
194 194
 		$product = new \WC_Product_Simple();
195
-		$product->set_name( 'Test Product' );
196
-		$product->set_regular_price( 25 );
195
+		$product->set_name('Test Product');
196
+		$product->set_regular_price(25);
197 197
 		$product->save();
198 198
 
199
-		$order = OrderHelper::create_order( 1, $product );
200
-		$order->set_status( 'completed' );
201
-		$order->set_date_created( time() - ( 3 * DAY_IN_SECONDS ) );
199
+		$order = OrderHelper::create_order(1, $product);
200
+		$order->set_status('completed');
201
+		$order->set_date_created(time() - (3 * DAY_IN_SECONDS));
202 202
 		$order->save();
203 203
 
204 204
 		// Verify there are actions to cancel.
205 205
 		$pending_actions = QueueHelper::get_all_pending();
206
-		$this->assertCount( 1, $pending_actions );
206
+		$this->assertCount(1, $pending_actions);
207 207
 
208 208
 		// Cancel outstanding actions.
209
-		$request  = new WP_REST_Request( 'POST', $this->endpoint . '/cancel' );
210
-		$response = $this->server->dispatch( $request );
209
+		$request  = new WP_REST_Request('POST', $this->endpoint . '/cancel');
210
+		$response = $this->server->dispatch($request);
211 211
 		$report   = $response->get_data();
212 212
 
213
-		$this->assertEquals( 200, $response->get_status() );
214
-		$this->assertEquals( 'success', $report['status'] );
213
+		$this->assertEquals(200, $response->get_status());
214
+		$this->assertEquals('success', $report['status']);
215 215
 
216 216
 		// Verify there are no pending actions.
217 217
 		$pending_actions = QueueHelper::get_all_pending();
218
-		$this->assertCount( 0, $pending_actions );
218
+		$this->assertCount(0, $pending_actions);
219 219
 	}
220 220
 
221 221
 	/**
@@ -226,42 +226,42 @@  discard block
 block discarded – undo
226 226
 
227 227
 		// Populate all of the data.
228 228
 		$product = new \WC_Product_Simple();
229
-		$product->set_name( 'Test Product' );
230
-		$product->set_regular_price( 25 );
229
+		$product->set_name('Test Product');
230
+		$product->set_regular_price(25);
231 231
 		$product->save();
232 232
 
233
-		for ( $i = 0; $i < 25; $i++ ) {
234
-			$order = OrderHelper::create_order( 1, $product );
235
-			$order->set_status( 'completed' );
233
+		for ($i = 0; $i < 25; $i++) {
234
+			$order = OrderHelper::create_order(1, $product);
235
+			$order->set_status('completed');
236 236
 			$order->save();
237 237
 		}
238 238
 
239 239
 		// Check that stats exist before deleting.
240 240
 		QueueHelper::run_all_pending();
241 241
 
242
-		$request = new WP_REST_Request( 'GET', '/wc/v4/reports/orders' );
243
-		$request->set_query_params( array( 'per_page' => 25 ) );
244
-		$response = $this->server->dispatch( $request );
242
+		$request = new WP_REST_Request('GET', '/wc/v4/reports/orders');
243
+		$request->set_query_params(array('per_page' => 25));
244
+		$response = $this->server->dispatch($request);
245 245
 		$reports  = $response->get_data();
246 246
 
247
-		$this->assertEquals( 200, $response->get_status() );
248
-		$this->assertCount( 25, $reports );
247
+		$this->assertEquals(200, $response->get_status());
248
+		$this->assertCount(25, $reports);
249 249
 
250
-		$request = new WP_REST_Request( 'GET', '/wc/v4/reports/customers' );
251
-		$request->set_query_params( array( 'per_page' => 25 ) );
252
-		$response = $this->server->dispatch( $request );
250
+		$request = new WP_REST_Request('GET', '/wc/v4/reports/customers');
251
+		$request->set_query_params(array('per_page' => 25));
252
+		$response = $this->server->dispatch($request);
253 253
 		$reports  = $response->get_data();
254 254
 
255
-		$this->assertEquals( 200, $response->get_status() );
256
-		$this->assertCount( 1, $reports );
255
+		$this->assertEquals(200, $response->get_status());
256
+		$this->assertCount(1, $reports);
257 257
 
258 258
 		// Delete all stats.
259
-		$request  = new WP_REST_Request( 'POST', $this->endpoint . '/delete' );
260
-		$response = $this->server->dispatch( $request );
259
+		$request  = new WP_REST_Request('POST', $this->endpoint . '/delete');
260
+		$response = $this->server->dispatch($request);
261 261
 		$report   = $response->get_data();
262 262
 
263
-		$this->assertEquals( 200, $response->get_status() );
264
-		$this->assertEquals( 'success', $report['status'] );
263
+		$this->assertEquals(200, $response->get_status());
264
+		$this->assertEquals('success', $report['status']);
265 265
 
266 266
 		// Run pending three times to process batches and dependent actions.
267 267
 		QueueHelper::run_all_pending();
@@ -269,19 +269,19 @@  discard block
 block discarded – undo
269 269
 		QueueHelper::run_all_pending();
270 270
 
271 271
 		// Check that stats have been deleted.
272
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/reports/orders' );
273
-		$response = $this->server->dispatch( $request );
272
+		$request  = new WP_REST_Request('GET', '/wc/v4/reports/orders');
273
+		$response = $this->server->dispatch($request);
274 274
 		$reports  = $response->get_data();
275 275
 
276
-		$this->assertEquals( 200, $response->get_status() );
277
-		$this->assertCount( 0, $reports );
276
+		$this->assertEquals(200, $response->get_status());
277
+		$this->assertCount(0, $reports);
278 278
 
279
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/reports/customers' );
280
-		$response = $this->server->dispatch( $request );
279
+		$request  = new WP_REST_Request('GET', '/wc/v4/reports/customers');
280
+		$response = $this->server->dispatch($request);
281 281
 		$reports  = $response->get_data();
282 282
 
283
-		$this->assertEquals( 200, $response->get_status() );
284
-		$this->assertCount( 0, $reports );
283
+		$this->assertEquals(200, $response->get_status());
284
+		$this->assertCount(0, $reports);
285 285
 	}
286 286
 
287 287
 	/**
@@ -293,25 +293,25 @@  discard block
 block discarded – undo
293 293
 
294 294
 		// Populate all of the data.
295 295
 		$product = new \WC_Product_Simple();
296
-		$product->set_name( 'Test Product' );
297
-		$product->set_regular_price( 25 );
296
+		$product->set_name('Test Product');
297
+		$product->set_regular_price(25);
298 298
 		$product->save();
299 299
 
300 300
 		// Create 5 completed orders.
301
-		for ( $i = 0; $i < 5; $i++ ) {
302
-			$order = OrderHelper::create_order( 1, $product );
303
-			$order->set_status( 'completed' );
304
-			$order->set_date_created( time() - ( ( $i + 1 ) * DAY_IN_SECONDS ) );
301
+		for ($i = 0; $i < 5; $i++) {
302
+			$order = OrderHelper::create_order(1, $product);
303
+			$order->set_status('completed');
304
+			$order->set_date_created(time() - (($i + 1) * DAY_IN_SECONDS));
305 305
 			$order->save();
306 306
 		}
307 307
 
308 308
 		// Trash one test order - excludes it from totals.
309
-		$order->set_status( 'trash' );
309
+		$order->set_status('trash');
310 310
 		$order->save();
311 311
 
312 312
 		// Create 1 draft order - to be excluded from totals.
313
-		$order = OrderHelper::create_order( 1, $product );
314
-		$order->set_date_created( time() - ( 5 * DAY_IN_SECONDS ) );
313
+		$order = OrderHelper::create_order(1, $product);
314
+		$order->set_date_created(time() - (5 * DAY_IN_SECONDS));
315 315
 		$order->save();
316 316
 		wp_update_post(
317 317
 			array(
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
 		);
322 322
 
323 323
 		// Test totals and total params.
324
-		$request    = new WP_REST_Request( 'GET', $this->endpoint . '/totals' );
325
-		$response   = $this->server->dispatch( $request );
324
+		$request    = new WP_REST_Request('GET', $this->endpoint . '/totals');
325
+		$response   = $this->server->dispatch($request);
326 326
 		$report     = $response->get_data();
327 327
 		$user_query = new \WP_User_Query(
328 328
 			array(
@@ -331,37 +331,37 @@  discard block
 block discarded – undo
331 331
 			)
332 332
 		);
333 333
 
334
-		$this->assertEquals( 200, $response->get_status() );
335
-		$this->assertEquals( 4, $report['orders'] );
336
-		$this->assertEquals( $user_query->get_total(), $report['customers'] );
334
+		$this->assertEquals(200, $response->get_status());
335
+		$this->assertEquals(4, $report['orders']);
336
+		$this->assertEquals($user_query->get_total(), $report['customers']);
337 337
 
338 338
 		// Test totals with days param.
339
-		$request = new WP_REST_Request( 'GET', $this->endpoint . '/totals' );
340
-		$request->set_query_params( array( 'days' => 2 ) );
341
-		$response = $this->server->dispatch( $request );
339
+		$request = new WP_REST_Request('GET', $this->endpoint . '/totals');
340
+		$request->set_query_params(array('days' => 2));
341
+		$response = $this->server->dispatch($request);
342 342
 		$report   = $response->get_data();
343 343
 
344
-		$this->assertEquals( 200, $response->get_status() );
345
-		$this->assertEquals( 2, $report['orders'] );
344
+		$this->assertEquals(200, $response->get_status());
345
+		$this->assertEquals(2, $report['orders']);
346 346
 
347 347
 		// Test import status.
348
-		$request  = new WP_REST_Request( 'POST', $this->endpoint );
349
-		$response = $this->server->dispatch( $request );
348
+		$request  = new WP_REST_Request('POST', $this->endpoint);
349
+		$response = $this->server->dispatch($request);
350 350
 		$report   = $response->get_data();
351 351
 
352
-		$this->assertEquals( 200, $response->get_status() );
353
-		$this->assertEquals( 'success', $report['status'] );
352
+		$this->assertEquals(200, $response->get_status());
353
+		$this->assertEquals('success', $report['status']);
354 354
 
355
-		$request  = new WP_REST_Request( 'GET', $this->endpoint . '/status' );
356
-		$response = $this->server->dispatch( $request );
355
+		$request  = new WP_REST_Request('GET', $this->endpoint . '/status');
356
+		$response = $this->server->dispatch($request);
357 357
 		$report   = $response->get_data();
358 358
 
359
-		$this->assertEquals( 200, $response->get_status() );
360
-		$this->assertEquals( true, $report['is_importing'] );
361
-		$this->assertEquals( 0, $report['customers_count'] );
362
-		$this->assertEquals( 3, $report['customers_total'] );
363
-		$this->assertEquals( 0, $report['orders_count'] );
364
-		$this->assertEquals( 4, $report['orders_total'] );
359
+		$this->assertEquals(200, $response->get_status());
360
+		$this->assertEquals(true, $report['is_importing']);
361
+		$this->assertEquals(0, $report['customers_count']);
362
+		$this->assertEquals(3, $report['customers_total']);
363
+		$this->assertEquals(0, $report['orders_count']);
364
+		$this->assertEquals(4, $report['orders_total']);
365 365
 
366 366
 		// Run pending thrice to process batch and order.
367 367
 		QueueHelper::process_pending();
@@ -369,25 +369,25 @@  discard block
 block discarded – undo
369 369
 		QueueHelper::process_pending();
370 370
 
371 371
 		// Test import status after processing.
372
-		$request  = new WP_REST_Request( 'GET', $this->endpoint . '/status' );
373
-		$response = $this->server->dispatch( $request );
372
+		$request  = new WP_REST_Request('GET', $this->endpoint . '/status');
373
+		$response = $this->server->dispatch($request);
374 374
 		$report   = $response->get_data();
375 375
 
376
-		$this->assertEquals( 200, $response->get_status() );
377
-		$this->assertEquals( false, $report['is_importing'] );
378
-		$this->assertEquals( 1, $report['customers_count'] );
379
-		$this->assertEquals( 3, $report['customers_total'] );
380
-		$this->assertEquals( 4, $report['orders_count'] );
381
-		$this->assertEquals( 4, $report['orders_total'] );
376
+		$this->assertEquals(200, $response->get_status());
377
+		$this->assertEquals(false, $report['is_importing']);
378
+		$this->assertEquals(1, $report['customers_count']);
379
+		$this->assertEquals(3, $report['customers_total']);
380
+		$this->assertEquals(4, $report['orders_count']);
381
+		$this->assertEquals(4, $report['orders_total']);
382 382
 
383 383
 		// Test totals with skip existing param.
384
-		$request = new WP_REST_Request( 'GET', $this->endpoint . '/totals' );
385
-		$request->set_query_params( array( 'skip_existing' => 1 ) );
386
-		$response = $this->server->dispatch( $request );
384
+		$request = new WP_REST_Request('GET', $this->endpoint . '/totals');
385
+		$request->set_query_params(array('skip_existing' => 1));
386
+		$response = $this->server->dispatch($request);
387 387
 		$report   = $response->get_data();
388 388
 
389 389
 		// @todo The following line should be uncommented when https://github.com/woocommerce/woocommerce-admin/issues/2195 is resolved.
390 390
 		// $this->assertEquals( 0, $report['customers'] );
391
-		$this->assertEquals( 0, $report['orders'] );
391
+		$this->assertEquals(0, $report['orders']);
392 392
 	}
393 393
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/Taxes.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	public function test_register_routes() {
40 40
 		$routes = $this->server->get_routes();
41 41
 
42
-		$this->assertArrayHasKey( $this->endpoint, $routes );
42
+		$this->assertArrayHasKey($this->endpoint, $routes);
43 43
 	}
44 44
 
45 45
 	/**
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 
53 53
 		// Populate all of the data.
54 54
 		$product = new \WC_Product_Simple();
55
-		$product->set_name( 'Test Product' );
56
-		$product->set_regular_price( 25 );
55
+		$product->set_name('Test Product');
56
+		$product->set_regular_price(25);
57 57
 		$product->save();
58 58
 
59 59
 		$wpdb->insert(
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 			)
70 70
 		);
71 71
 
72
-		$order = OrderHelper::create_order( 1, $product );
73
-		$order->set_status( 'completed' );
74
-		$order->set_total( 100 ); // $25 x 4.
72
+		$order = OrderHelper::create_order(1, $product);
73
+		$order->set_status('completed');
74
+		$order->set_total(100); // $25 x 4.
75 75
 		$order->save();
76 76
 
77 77
 		// @todo Remove this once order data is synced to wc_order_tax_lookup
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 			array(
81 81
 				'order_id'     => $order->get_id(),
82 82
 				'tax_rate_id'  => 1,
83
-				'date_created' => date( 'Y-m-d H:i:s' ),
83
+				'date_created' => date('Y-m-d H:i:s'),
84 84
 				'shipping_tax' => 2,
85 85
 				'order_tax'    => 5,
86 86
 				'total_tax'    => 7,
@@ -89,23 +89,23 @@  discard block
 block discarded – undo
89 89
 
90 90
 		QueueHelper::run_all_pending();
91 91
 
92
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
92
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
93 93
 		$reports  = $response->get_data();
94 94
 
95
-		$this->assertEquals( 200, $response->get_status() );
96
-		$this->assertEquals( 1, count( $reports ) );
95
+		$this->assertEquals(200, $response->get_status());
96
+		$this->assertEquals(1, count($reports));
97 97
 
98
-		$tax_report = reset( $reports );
98
+		$tax_report = reset($reports);
99 99
 
100
-		$this->assertEquals( 1, $tax_report['tax_rate_id'] );
101
-		$this->assertEquals( 'TestTax', $tax_report['name'] );
102
-		$this->assertEquals( 7, $tax_report['tax_rate'] );
103
-		$this->assertEquals( 'US', $tax_report['country'] );
104
-		$this->assertEquals( 'GA', $tax_report['state'] );
105
-		$this->assertEquals( 7, $tax_report['total_tax'] );
106
-		$this->assertEquals( 5, $tax_report['order_tax'] );
107
-		$this->assertEquals( 2, $tax_report['shipping_tax'] );
108
-		$this->assertEquals( 1, $tax_report['orders_count'] );
100
+		$this->assertEquals(1, $tax_report['tax_rate_id']);
101
+		$this->assertEquals('TestTax', $tax_report['name']);
102
+		$this->assertEquals(7, $tax_report['tax_rate']);
103
+		$this->assertEquals('US', $tax_report['country']);
104
+		$this->assertEquals('GA', $tax_report['state']);
105
+		$this->assertEquals(7, $tax_report['total_tax']);
106
+		$this->assertEquals(5, $tax_report['order_tax']);
107
+		$this->assertEquals(2, $tax_report['shipping_tax']);
108
+		$this->assertEquals(1, $tax_report['orders_count']);
109 109
 	}
110 110
 
111 111
 	/**
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 
119 119
 		// Populate all of the data.
120 120
 		$product = new \WC_Product_Simple();
121
-		$product->set_name( 'Test Product' );
122
-		$product->set_regular_price( 25 );
121
+		$product->set_name('Test Product');
122
+		$product->set_regular_price(25);
123 123
 		$product->save();
124 124
 
125 125
 		$wpdb->insert(
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 			)
149 149
 		);
150 150
 
151
-		$order = OrderHelper::create_order( 1, $product );
152
-		$order->set_status( 'completed' );
153
-		$order->set_total( 100 ); // $25 x 4.
151
+		$order = OrderHelper::create_order(1, $product);
152
+		$order->set_status('completed');
153
+		$order->set_total(100); // $25 x 4.
154 154
 		$order->save();
155 155
 
156 156
 		// @todo Remove this once order data is synced to wc_order_tax_lookup
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			array(
160 160
 				'order_id'     => $order->get_id(),
161 161
 				'tax_rate_id'  => 1,
162
-				'date_created' => date( 'Y-m-d H:i:s' ),
162
+				'date_created' => date('Y-m-d H:i:s'),
163 163
 				'shipping_tax' => 2,
164 164
 				'order_tax'    => 5,
165 165
 				'total_tax'    => 7,
@@ -168,42 +168,42 @@  discard block
 block discarded – undo
168 168
 
169 169
 		QueueHelper::run_all_pending();
170 170
 
171
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
172
-		$request  = new WP_REST_Request( 'GET', $this->endpoint );
171
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
172
+		$request  = new WP_REST_Request('GET', $this->endpoint);
173 173
 		$request->set_query_params(
174 174
 			array(
175 175
 				'taxes' => '1,2',
176 176
 			)
177 177
 		);
178
-		$response = $this->server->dispatch( $request );
178
+		$response = $this->server->dispatch($request);
179 179
 		$reports  = $response->get_data();
180 180
 
181
-		$this->assertEquals( 200, $response->get_status() );
182
-		$this->assertEquals( 2, count( $reports ) );
183
-
184
-		$tax_report = reset( $reports );
185
-
186
-		$this->assertEquals( 2, $tax_report['tax_rate_id'] );
187
-		$this->assertEquals( 'TestTax 2', $tax_report['name'] );
188
-		$this->assertEquals( 8, $tax_report['tax_rate'] );
189
-		$this->assertEquals( 'CA', $tax_report['country'] );
190
-		$this->assertEquals( 'ON', $tax_report['state'] );
191
-		$this->assertEquals( 0, $tax_report['total_tax'] );
192
-		$this->assertEquals( 0, $tax_report['order_tax'] );
193
-		$this->assertEquals( 0, $tax_report['shipping_tax'] );
194
-		$this->assertEquals( 0, $tax_report['orders_count'] );
195
-
196
-		$tax_report = next( $reports );
197
-
198
-		$this->assertEquals( 1, $tax_report['tax_rate_id'] );
199
-		$this->assertEquals( 'TestTax', $tax_report['name'] );
200
-		$this->assertEquals( 7, $tax_report['tax_rate'] );
201
-		$this->assertEquals( 'US', $tax_report['country'] );
202
-		$this->assertEquals( 'GA', $tax_report['state'] );
203
-		$this->assertEquals( 7, $tax_report['total_tax'] );
204
-		$this->assertEquals( 5, $tax_report['order_tax'] );
205
-		$this->assertEquals( 2, $tax_report['shipping_tax'] );
206
-		$this->assertEquals( 1, $tax_report['orders_count'] );
181
+		$this->assertEquals(200, $response->get_status());
182
+		$this->assertEquals(2, count($reports));
183
+
184
+		$tax_report = reset($reports);
185
+
186
+		$this->assertEquals(2, $tax_report['tax_rate_id']);
187
+		$this->assertEquals('TestTax 2', $tax_report['name']);
188
+		$this->assertEquals(8, $tax_report['tax_rate']);
189
+		$this->assertEquals('CA', $tax_report['country']);
190
+		$this->assertEquals('ON', $tax_report['state']);
191
+		$this->assertEquals(0, $tax_report['total_tax']);
192
+		$this->assertEquals(0, $tax_report['order_tax']);
193
+		$this->assertEquals(0, $tax_report['shipping_tax']);
194
+		$this->assertEquals(0, $tax_report['orders_count']);
195
+
196
+		$tax_report = next($reports);
197
+
198
+		$this->assertEquals(1, $tax_report['tax_rate_id']);
199
+		$this->assertEquals('TestTax', $tax_report['name']);
200
+		$this->assertEquals(7, $tax_report['tax_rate']);
201
+		$this->assertEquals('US', $tax_report['country']);
202
+		$this->assertEquals('GA', $tax_report['state']);
203
+		$this->assertEquals(7, $tax_report['total_tax']);
204
+		$this->assertEquals(5, $tax_report['order_tax']);
205
+		$this->assertEquals(2, $tax_report['shipping_tax']);
206
+		$this->assertEquals(1, $tax_report['orders_count']);
207 207
 	}
208 208
 
209 209
 	/**
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 			)
241 241
 		);
242 242
 
243
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
243
+		$request = new WP_REST_Request('GET', $this->endpoint);
244 244
 		$request->set_query_params(
245 245
 			array(
246 246
 				'order'   => 'asc',
@@ -248,17 +248,17 @@  discard block
 block discarded – undo
248 248
 				'taxes'   => '1,2',
249 249
 			)
250 250
 		);
251
-		$response = $this->server->dispatch( $request );
251
+		$response = $this->server->dispatch($request);
252 252
 		$reports  = $response->get_data();
253 253
 
254
-		$this->assertEquals( 200, $response->get_status() );
255
-		$this->assertEquals( 2, count( $reports ) );
254
+		$this->assertEquals(200, $response->get_status());
255
+		$this->assertEquals(2, count($reports));
256 256
 
257
-		$this->assertEquals( 1, $reports[0]['tax_rate_id'] );
258
-		$this->assertEquals( 7, $reports[0]['tax_rate'] );
257
+		$this->assertEquals(1, $reports[0]['tax_rate_id']);
258
+		$this->assertEquals(7, $reports[0]['tax_rate']);
259 259
 
260
-		$this->assertEquals( 2, $reports[1]['tax_rate_id'] );
261
-		$this->assertEquals( 10, $reports[1]['tax_rate'] );
260
+		$this->assertEquals(2, $reports[1]['tax_rate_id']);
261
+		$this->assertEquals(10, $reports[1]['tax_rate']);
262 262
 	}
263 263
 
264 264
 	/**
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 			)
296 296
 		);
297 297
 
298
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
298
+		$request = new WP_REST_Request('GET', $this->endpoint);
299 299
 		$request->set_query_params(
300 300
 			array(
301 301
 				'order'   => 'asc',
@@ -303,15 +303,15 @@  discard block
 block discarded – undo
303 303
 				'taxes'   => '1,2',
304 304
 			)
305 305
 		);
306
-		$response = $this->server->dispatch( $request );
306
+		$response = $this->server->dispatch($request);
307 307
 		$reports  = $response->get_data();
308 308
 
309
-		$this->assertEquals( 200, $response->get_status() );
310
-		$this->assertEquals( 2, count( $reports ) );
309
+		$this->assertEquals(200, $response->get_status());
310
+		$this->assertEquals(2, count($reports));
311 311
 
312
-		$this->assertEquals( 2, $reports[0]['tax_rate_id'] );
312
+		$this->assertEquals(2, $reports[0]['tax_rate_id']);
313 313
 
314
-		$this->assertEquals( 1, $reports[1]['tax_rate_id'] );
314
+		$this->assertEquals(1, $reports[1]['tax_rate_id']);
315 315
 	}
316 316
 
317 317
 	/**
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 	 * @since 3.5.0
321 321
 	 */
322 322
 	public function test_get_reports_without_permission() {
323
-		wp_set_current_user( 0 );
324
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
325
-		$this->assertEquals( 401, $response->get_status() );
323
+		wp_set_current_user(0);
324
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
325
+		$this->assertEquals(401, $response->get_status());
326 326
 	}
327 327
 
328 328
 	/**
@@ -331,21 +331,21 @@  discard block
 block discarded – undo
331 331
 	 * @since 3.5.0
332 332
 	 */
333 333
 	public function test_reports_schema() {
334
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
335
-		$response   = $this->server->dispatch( $request );
334
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
335
+		$response   = $this->server->dispatch($request);
336 336
 		$data       = $response->get_data();
337 337
 		$properties = $data['schema']['properties'];
338 338
 
339
-		$this->assertEquals( 10, count( $properties ) );
340
-		$this->assertArrayHasKey( 'tax_rate_id', $properties );
341
-		$this->assertArrayHasKey( 'name', $properties );
342
-		$this->assertArrayHasKey( 'tax_rate', $properties );
343
-		$this->assertArrayHasKey( 'country', $properties );
344
-		$this->assertArrayHasKey( 'state', $properties );
345
-		$this->assertArrayHasKey( 'priority', $properties );
346
-		$this->assertArrayHasKey( 'total_tax', $properties );
347
-		$this->assertArrayHasKey( 'order_tax', $properties );
348
-		$this->assertArrayHasKey( 'shipping_tax', $properties );
349
-		$this->assertArrayHasKey( 'orders_count', $properties );
339
+		$this->assertEquals(10, count($properties));
340
+		$this->assertArrayHasKey('tax_rate_id', $properties);
341
+		$this->assertArrayHasKey('name', $properties);
342
+		$this->assertArrayHasKey('tax_rate', $properties);
343
+		$this->assertArrayHasKey('country', $properties);
344
+		$this->assertArrayHasKey('state', $properties);
345
+		$this->assertArrayHasKey('priority', $properties);
346
+		$this->assertArrayHasKey('total_tax', $properties);
347
+		$this->assertArrayHasKey('order_tax', $properties);
348
+		$this->assertArrayHasKey('shipping_tax', $properties);
349
+		$this->assertArrayHasKey('orders_count', $properties);
350 350
 	}
351 351
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/Downloads.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
13 13
 use \WP_REST_Request;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	public function test_register_routes() {
37 37
 		$routes = $this->server->get_routes();
38 38
 
39
-		$this->assertArrayHasKey( $this->endpoint, $routes );
39
+		$this->assertArrayHasKey($this->endpoint, $routes);
40 40
 	}
41 41
 
42 42
 	/**
@@ -47,50 +47,50 @@  discard block
 block discarded – undo
47 47
 
48 48
 		// Populate all of the data.
49 49
 		$prod_download = new \WC_Product_Download();
50
-		$prod_download->set_file( plugin_dir_url( __FILE__ ) . '/assets/images/help.png' );
51
-		$prod_download->set_id( 1 );
50
+		$prod_download->set_file(plugin_dir_url(__FILE__) . '/assets/images/help.png');
51
+		$prod_download->set_id(1);
52 52
 
53 53
 		$product = new \WC_Product_Simple();
54
-		$product->set_name( 'Test Product' );
55
-		$product->set_downloadable( 'yes' );
56
-		$product->set_downloads( array( $prod_download ) );
57
-		$product->set_regular_price( 25 );
54
+		$product->set_name('Test Product');
55
+		$product->set_downloadable('yes');
56
+		$product->set_downloads(array($prod_download));
57
+		$product->set_regular_price(25);
58 58
 		$product->save();
59 59
 
60
-		$order = OrderHelper::create_order( 1, $product );
61
-		$order->set_status( 'completed' );
62
-		$order->set_total( 100 );
60
+		$order = OrderHelper::create_order(1, $product);
61
+		$order->set_status('completed');
62
+		$order->set_total(100);
63 63
 		$order->save();
64 64
 
65 65
 		$download = new \WC_Customer_Download();
66
-		$download->set_user_id( $this->user );
67
-		$download->set_order_id( $order->get_id() );
68
-		$download->set_product_id( $product->get_id() );
69
-		$download->set_download_id( $prod_download->get_id() );
66
+		$download->set_user_id($this->user);
67
+		$download->set_order_id($order->get_id());
68
+		$download->set_product_id($product->get_id());
69
+		$download->set_download_id($prod_download->get_id());
70 70
 		$download->save();
71 71
 
72 72
 		$object = new \WC_Customer_Download_Log();
73
-		$object->set_permission_id( $download->get_id() );
74
-		$object->set_user_id( $this->user );
75
-		$object->set_user_ip_address( '1.2.3.4' );
73
+		$object->set_permission_id($download->get_id());
74
+		$object->set_user_id($this->user);
75
+		$object->set_user_ip_address('1.2.3.4');
76 76
 		$id = $object->save();
77 77
 
78
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
78
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
79 79
 		$reports  = $response->get_data();
80 80
 
81
-		$this->assertEquals( 200, $response->get_status() );
82
-		$this->assertEquals( 1, count( $reports ) );
81
+		$this->assertEquals(200, $response->get_status());
82
+		$this->assertEquals(1, count($reports));
83 83
 
84
-		$download_report = reset( $reports );
84
+		$download_report = reset($reports);
85 85
 
86
-		$this->assertEquals( 1, $download_report['download_id'] );
87
-		$this->assertEquals( $product->get_id(), $download_report['product_id'] );
88
-		$this->assertEquals( $order->get_id(), $download_report['order_id'] );
89
-		$this->assertEquals( $order->get_order_number(), $download_report['order_number'] );
90
-		$this->assertEquals( $this->user, $download_report['user_id'] );
91
-		$this->assertEquals( '1.2.3.4', $download_report['ip_address'] );
92
-		$this->assertEquals( 'help.png', $download_report['file_name'] );
93
-		$this->assertEquals( plugin_dir_url( __FILE__ ) . '/assets/images/help.png', $download_report['file_path'] );
86
+		$this->assertEquals(1, $download_report['download_id']);
87
+		$this->assertEquals($product->get_id(), $download_report['product_id']);
88
+		$this->assertEquals($order->get_id(), $download_report['order_id']);
89
+		$this->assertEquals($order->get_order_number(), $download_report['order_number']);
90
+		$this->assertEquals($this->user, $download_report['user_id']);
91
+		$this->assertEquals('1.2.3.4', $download_report['ip_address']);
92
+		$this->assertEquals('help.png', $download_report['file_name']);
93
+		$this->assertEquals(plugin_dir_url(__FILE__) . '/assets/images/help.png', $download_report['file_path']);
94 94
 	}
95 95
 
96 96
 	/**
@@ -103,67 +103,67 @@  discard block
 block discarded – undo
103 103
 
104 104
 		// First set of data.
105 105
 		$prod_download = new \WC_Product_Download();
106
-		$prod_download->set_file( plugin_dir_url( __FILE__ ) . '/assets/images/help.png' );
107
-		$prod_download->set_id( 1 );
106
+		$prod_download->set_file(plugin_dir_url(__FILE__) . '/assets/images/help.png');
107
+		$prod_download->set_id(1);
108 108
 
109 109
 		$product = new \WC_Product_Simple();
110
-		$product->set_name( 'Test Product' );
111
-		$product->set_downloadable( 'yes' );
112
-		$product->set_downloads( array( $prod_download ) );
113
-		$product->set_regular_price( 25 );
110
+		$product->set_name('Test Product');
111
+		$product->set_downloadable('yes');
112
+		$product->set_downloads(array($prod_download));
113
+		$product->set_regular_price(25);
114 114
 		$product->save();
115 115
 		$product_1 = $product->get_id();
116 116
 
117
-		$order = OrderHelper::create_order( 1, $product );
118
-		$order->set_status( 'completed' );
119
-		$order->set_total( 25 );
117
+		$order = OrderHelper::create_order(1, $product);
118
+		$order->set_status('completed');
119
+		$order->set_total(25);
120 120
 		$order->save();
121 121
 		$order_1 = $order->get_id();
122 122
 
123 123
 		$download = new \WC_Customer_Download();
124
-		$download->set_user_id( 1 );
125
-		$download->set_order_id( $order->get_id() );
126
-		$download->set_product_id( $product->get_id() );
127
-		$download->set_download_id( $prod_download->get_id() );
124
+		$download->set_user_id(1);
125
+		$download->set_order_id($order->get_id());
126
+		$download->set_product_id($product->get_id());
127
+		$download->set_download_id($prod_download->get_id());
128 128
 		$download->save();
129 129
 
130 130
 		$object = new \WC_Customer_Download_Log();
131
-		$object->set_permission_id( $download->get_id() );
132
-		$object->set_user_id( 1 );
133
-		$object->set_user_ip_address( '1.2.3.4' );
131
+		$object->set_permission_id($download->get_id());
132
+		$object->set_user_id(1);
133
+		$object->set_user_ip_address('1.2.3.4');
134 134
 		$id = $object->save();
135 135
 
136 136
 		// Second set of data.
137 137
 		$prod_download = new \WC_Product_Download();
138
-		$prod_download->set_file( plugin_dir_url( __FILE__ ) . '/assets/images/test.png' );
139
-		$prod_download->set_id( 2 );
138
+		$prod_download->set_file(plugin_dir_url(__FILE__) . '/assets/images/test.png');
139
+		$prod_download->set_id(2);
140 140
 
141 141
 		$product = new \WC_Product_Simple();
142
-		$product->set_name( 'Test Product 2' );
143
-		$product->set_downloadable( 'yes' );
144
-		$product->set_downloads( array( $prod_download ) );
145
-		$product->set_regular_price( 10 );
142
+		$product->set_name('Test Product 2');
143
+		$product->set_downloadable('yes');
144
+		$product->set_downloads(array($prod_download));
145
+		$product->set_regular_price(10);
146 146
 		$product->save();
147 147
 		$product_2 = $product->get_id();
148 148
 
149
-		$order = OrderHelper::create_order( 2, $product );
150
-		$order->set_status( 'completed' );
151
-		$order->set_total( 10 );
149
+		$order = OrderHelper::create_order(2, $product);
150
+		$order->set_status('completed');
151
+		$order->set_total(10);
152 152
 		$order->save();
153 153
 		$order_2 = $order->get_id();
154 154
 
155 155
 		$download = new \WC_Customer_Download();
156
-		$download->set_user_id( 2 );
157
-		$download->set_order_id( $order->get_id() );
158
-		$download->set_product_id( $product->get_id() );
159
-		$download->set_download_id( $prod_download->get_id() );
156
+		$download->set_user_id(2);
157
+		$download->set_order_id($order->get_id());
158
+		$download->set_product_id($product->get_id());
159
+		$download->set_download_id($prod_download->get_id());
160 160
 		$download->save();
161 161
 
162 162
 		$object = new \WC_Customer_Download_Log();
163
-		$object->set_permission_id( $download->get_id() );
164
-		$object->set_user_id( 2 );
165
-		$object->set_user_ip_address( '5.4.3.2.1' );
166
-		$object->set_timestamp( date( 'Y-m-d H:00:00', $time - ( 2 * DAY_IN_SECONDS ) ) );
163
+		$object->set_permission_id($download->get_id());
164
+		$object->set_user_id(2);
165
+		$object->set_user_ip_address('5.4.3.2.1');
166
+		$object->set_timestamp(date('Y-m-d H:00:00', $time - (2 * DAY_IN_SECONDS)));
167 167
 		$id = $object->save();
168 168
 
169 169
 		return array(
@@ -181,27 +181,27 @@  discard block
 block discarded – undo
181 181
 	public function test_get_report_with_date_filter() {
182 182
 		$test_info = $this->filter_setup();
183 183
 
184
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
184
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
185 185
 		$reports  = $response->get_data();
186 186
 
187
-		$this->assertEquals( 200, $response->get_status() );
188
-		$this->assertEquals( 2, count( $reports ) );
187
+		$this->assertEquals(200, $response->get_status());
188
+		$this->assertEquals(2, count($reports));
189 189
 
190 190
 		// Test date filtering.
191
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
191
+		$request = new WP_REST_Request('GET', $this->endpoint);
192 192
 		$request->set_query_params(
193 193
 			array(
194
-				'before' => date( 'Y-m-d H:00:00', $test_info['time'] + DAY_IN_SECONDS ),
195
-				'after'  => date( 'Y-m-d H:00:00', $test_info['time'] - DAY_IN_SECONDS ),
194
+				'before' => date('Y-m-d H:00:00', $test_info['time'] + DAY_IN_SECONDS),
195
+				'after'  => date('Y-m-d H:00:00', $test_info['time'] - DAY_IN_SECONDS),
196 196
 			)
197 197
 		);
198
-		$response        = $this->server->dispatch( $request );
198
+		$response        = $this->server->dispatch($request);
199 199
 		$reports         = $response->get_data();
200
-		$download_report = reset( $reports );
200
+		$download_report = reset($reports);
201 201
 
202
-		$this->assertEquals( 200, $response->get_status() );
203
-		$this->assertEquals( 1, count( $reports ) );
204
-		$this->assertEquals( 'help.png', $download_report['file_name'] );
202
+		$this->assertEquals(200, $response->get_status());
203
+		$this->assertEquals(1, count($reports));
204
+		$this->assertEquals('help.png', $download_report['file_name']);
205 205
 	}
206 206
 
207 207
 	/**
@@ -210,41 +210,41 @@  discard block
 block discarded – undo
210 210
 	public function test_get_report_with_product_filter() {
211 211
 		$test_info = $this->filter_setup();
212 212
 
213
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
213
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
214 214
 		$reports  = $response->get_data();
215 215
 
216
-		$this->assertEquals( 200, $response->get_status() );
217
-		$this->assertEquals( 2, count( $reports ) );
216
+		$this->assertEquals(200, $response->get_status());
217
+		$this->assertEquals(2, count($reports));
218 218
 
219 219
 		// Test includes filtering.
220
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
220
+		$request = new WP_REST_Request('GET', $this->endpoint);
221 221
 		$request->set_query_params(
222 222
 			array(
223 223
 				'product_includes' => $test_info['product_1'],
224 224
 			)
225 225
 		);
226
-		$response        = $this->server->dispatch( $request );
226
+		$response        = $this->server->dispatch($request);
227 227
 		$reports         = $response->get_data();
228
-		$download_report = reset( $reports );
228
+		$download_report = reset($reports);
229 229
 
230
-		$this->assertEquals( 200, $response->get_status() );
231
-		$this->assertEquals( 1, count( $reports ) );
232
-		$this->assertEquals( 'help.png', $download_report['file_name'] );
230
+		$this->assertEquals(200, $response->get_status());
231
+		$this->assertEquals(1, count($reports));
232
+		$this->assertEquals('help.png', $download_report['file_name']);
233 233
 
234 234
 		// Test excludes filtering.
235
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
235
+		$request = new WP_REST_Request('GET', $this->endpoint);
236 236
 		$request->set_query_params(
237 237
 			array(
238 238
 				'product_excludes' => $test_info['product_1'],
239 239
 			)
240 240
 		);
241
-		$response        = $this->server->dispatch( $request );
241
+		$response        = $this->server->dispatch($request);
242 242
 		$reports         = $response->get_data();
243
-		$download_report = reset( $reports );
243
+		$download_report = reset($reports);
244 244
 
245
-		$this->assertEquals( 200, $response->get_status() );
246
-		$this->assertEquals( 1, count( $reports ) );
247
-		$this->assertEquals( 'test.png', $download_report['file_name'] );
245
+		$this->assertEquals(200, $response->get_status());
246
+		$this->assertEquals(1, count($reports));
247
+		$this->assertEquals('test.png', $download_report['file_name']);
248 248
 	}
249 249
 
250 250
 	/**
@@ -253,41 +253,41 @@  discard block
 block discarded – undo
253 253
 	public function test_get_report_with_order_filter() {
254 254
 		$test_info = $this->filter_setup();
255 255
 
256
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
256
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
257 257
 		$reports  = $response->get_data();
258 258
 
259
-		$this->assertEquals( 200, $response->get_status() );
260
-		$this->assertEquals( 2, count( $reports ) );
259
+		$this->assertEquals(200, $response->get_status());
260
+		$this->assertEquals(2, count($reports));
261 261
 
262 262
 		// Test includes filtering.
263
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
263
+		$request = new WP_REST_Request('GET', $this->endpoint);
264 264
 		$request->set_query_params(
265 265
 			array(
266 266
 				'order_includes' => $test_info['order_1'],
267 267
 			)
268 268
 		);
269
-		$response        = $this->server->dispatch( $request );
269
+		$response        = $this->server->dispatch($request);
270 270
 		$reports         = $response->get_data();
271
-		$download_report = reset( $reports );
271
+		$download_report = reset($reports);
272 272
 
273
-		$this->assertEquals( 200, $response->get_status() );
274
-		$this->assertEquals( 1, count( $reports ) );
275
-		$this->assertEquals( 'help.png', $download_report['file_name'] );
273
+		$this->assertEquals(200, $response->get_status());
274
+		$this->assertEquals(1, count($reports));
275
+		$this->assertEquals('help.png', $download_report['file_name']);
276 276
 
277 277
 		// Test excludes filtering.
278
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
278
+		$request = new WP_REST_Request('GET', $this->endpoint);
279 279
 		$request->set_query_params(
280 280
 			array(
281 281
 				'order_excludes' => $test_info['order_1'],
282 282
 			)
283 283
 		);
284
-		$response        = $this->server->dispatch( $request );
284
+		$response        = $this->server->dispatch($request);
285 285
 		$reports         = $response->get_data();
286
-		$download_report = reset( $reports );
286
+		$download_report = reset($reports);
287 287
 
288
-		$this->assertEquals( 200, $response->get_status() );
289
-		$this->assertEquals( 1, count( $reports ) );
290
-		$this->assertEquals( 'test.png', $download_report['file_name'] );
288
+		$this->assertEquals(200, $response->get_status());
289
+		$this->assertEquals(1, count($reports));
290
+		$this->assertEquals('test.png', $download_report['file_name']);
291 291
 	}
292 292
 
293 293
 	/**
@@ -305,36 +305,36 @@  discard block
 block discarded – undo
305 305
 		);
306 306
 
307 307
 		// Test includes filtering.
308
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
308
+		$request = new WP_REST_Request('GET', $this->endpoint);
309 309
 		$request->set_query_params(
310 310
 			array(
311 311
 				'customer_includes' => $customer_id,
312 312
 			)
313 313
 		);
314
-		$response        = $this->server->dispatch( $request );
314
+		$response        = $this->server->dispatch($request);
315 315
 		$reports         = $response->get_data();
316
-		$download_report = reset( $reports );
316
+		$download_report = reset($reports);
317 317
 
318
-		$this->assertEquals( 200, $response->get_status() );
319
-		$this->assertEquals( 1, count( $reports ) );
320
-		$this->assertEquals( 'help.png', $download_report['file_name'] );
321
-		$this->assertEquals( 1, $download_report['user_id'] );
318
+		$this->assertEquals(200, $response->get_status());
319
+		$this->assertEquals(1, count($reports));
320
+		$this->assertEquals('help.png', $download_report['file_name']);
321
+		$this->assertEquals(1, $download_report['user_id']);
322 322
 
323 323
 		// Test excludes filtering.
324
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
324
+		$request = new WP_REST_Request('GET', $this->endpoint);
325 325
 		$request->set_query_params(
326 326
 			array(
327 327
 				'customer_excludes' => $customer_id,
328 328
 			)
329 329
 		);
330
-		$response        = $this->server->dispatch( $request );
330
+		$response        = $this->server->dispatch($request);
331 331
 		$reports         = $response->get_data();
332
-		$download_report = reset( $reports );
332
+		$download_report = reset($reports);
333 333
 
334
-		$this->assertEquals( 200, $response->get_status() );
335
-		$this->assertEquals( 1, count( $reports ) );
336
-		$this->assertEquals( 'test.png', $download_report['file_name'] );
337
-		$this->assertEquals( 2, $download_report['user_id'] );
334
+		$this->assertEquals(200, $response->get_status());
335
+		$this->assertEquals(1, count($reports));
336
+		$this->assertEquals('test.png', $download_report['file_name']);
337
+		$this->assertEquals(2, $download_report['user_id']);
338 338
 	}
339 339
 
340 340
 	/**
@@ -344,66 +344,66 @@  discard block
 block discarded – undo
344 344
 		$test_info = $this->filter_setup();
345 345
 
346 346
 		// Test includes filtering.
347
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
347
+		$request = new WP_REST_Request('GET', $this->endpoint);
348 348
 		$request->set_query_params(
349 349
 			array(
350 350
 				'ip_address_includes' => '1.2.3.4',
351 351
 			)
352 352
 		);
353
-		$response        = $this->server->dispatch( $request );
353
+		$response        = $this->server->dispatch($request);
354 354
 		$reports         = $response->get_data();
355
-		$download_report = reset( $reports );
355
+		$download_report = reset($reports);
356 356
 
357
-		$this->assertEquals( 200, $response->get_status() );
358
-		$this->assertEquals( 1, count( $reports ) );
359
-		$this->assertEquals( 'help.png', $download_report['file_name'] );
357
+		$this->assertEquals(200, $response->get_status());
358
+		$this->assertEquals(1, count($reports));
359
+		$this->assertEquals('help.png', $download_report['file_name']);
360 360
 
361 361
 		// Test excludes filtering.
362
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
362
+		$request = new WP_REST_Request('GET', $this->endpoint);
363 363
 		$request->set_query_params(
364 364
 			array(
365 365
 				'ip_address_excludes' => '1.2.3.4',
366 366
 			)
367 367
 		);
368
-		$response        = $this->server->dispatch( $request );
368
+		$response        = $this->server->dispatch($request);
369 369
 		$reports         = $response->get_data();
370
-		$download_report = reset( $reports );
370
+		$download_report = reset($reports);
371 371
 
372
-		$this->assertEquals( 200, $response->get_status() );
373
-		$this->assertEquals( 1, count( $reports ) );
374
-		$this->assertEquals( 'test.png', $download_report['file_name'] );
372
+		$this->assertEquals(200, $response->get_status());
373
+		$this->assertEquals(1, count($reports));
374
+		$this->assertEquals('test.png', $download_report['file_name']);
375 375
 	}
376 376
 
377 377
 	/**
378 378
 	 * Test getting reports without valid permissions.
379 379
 	 */
380 380
 	public function test_get_reports_without_permission() {
381
-		wp_set_current_user( 0 );
382
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
383
-		$this->assertEquals( 401, $response->get_status() );
381
+		wp_set_current_user(0);
382
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
383
+		$this->assertEquals(401, $response->get_status());
384 384
 	}
385 385
 
386 386
 	/**
387 387
 	 * Test reports schema.
388 388
 	 */
389 389
 	public function test_reports_schema() {
390
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
391
-		$response   = $this->server->dispatch( $request );
390
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
391
+		$response   = $this->server->dispatch($request);
392 392
 		$data       = $response->get_data();
393 393
 		$properties = $data['schema']['properties'];
394 394
 
395
-		$this->assertEquals( 12, count( $properties ) );
396
-		$this->assertArrayHasKey( 'id', $properties );
397
-		$this->assertArrayHasKey( 'product_id', $properties );
398
-		$this->assertArrayHasKey( 'date', $properties );
399
-		$this->assertArrayHasKey( 'date_gmt', $properties );
400
-		$this->assertArrayHasKey( 'download_id', $properties );
401
-		$this->assertArrayHasKey( 'file_name', $properties );
402
-		$this->assertArrayHasKey( 'file_path', $properties );
403
-		$this->assertArrayHasKey( 'order_id', $properties );
404
-		$this->assertArrayHasKey( 'order_number', $properties );
405
-		$this->assertArrayHasKey( 'user_id', $properties );
406
-		$this->assertArrayHasKey( 'username', $properties );
407
-		$this->assertArrayHasKey( 'ip_address', $properties );
395
+		$this->assertEquals(12, count($properties));
396
+		$this->assertArrayHasKey('id', $properties);
397
+		$this->assertArrayHasKey('product_id', $properties);
398
+		$this->assertArrayHasKey('date', $properties);
399
+		$this->assertArrayHasKey('date_gmt', $properties);
400
+		$this->assertArrayHasKey('download_id', $properties);
401
+		$this->assertArrayHasKey('file_name', $properties);
402
+		$this->assertArrayHasKey('file_path', $properties);
403
+		$this->assertArrayHasKey('order_id', $properties);
404
+		$this->assertArrayHasKey('order_number', $properties);
405
+		$this->assertArrayHasKey('user_id', $properties);
406
+		$this->assertArrayHasKey('username', $properties);
407
+		$this->assertArrayHasKey('ip_address', $properties);
408 408
 	}
409 409
 }
Please login to merge, or discard this patch.