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

Commit f0f5956

Browse files
committed
Address phpcs issues in failed Travis build
The unit tests had been excluded in phpcs.xml This should fix many issues, but there will still be more to fix.
1 parent d406eca commit f0f5956

22 files changed

+124
-106
lines changed

js/blocks/loader/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Gets the attributes for a block, based on given fields.
33
*
44
* @param {Object} fields The fields to get the attributes from.
5-
* @return {Array} attributes The attributes for the fields.
5+
* @return {Object} attributes The attributes for the fields.
66
*/
77
const getBlockAttributes = ( fields ) => {
88

js/blocks/loader/fields.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
* @return {number} Either -1, 0, or 1, depending on the comparison.
77
*/
88
const compare = ( a, b ) => {
9-
if ( a.order < b.order )
9+
if ( a.order < b.order ) {
1010
return -1;
11-
if ( a.order > b.order )
11+
}
12+
if ( a.order > b.order ) {
1213
return 1;
14+
}
1315
return 0;
1416
}
1517

@@ -21,7 +23,7 @@ const compare = ( a, b ) => {
2123
*/
2224
const simplifiedFields = ( fields ) => {
2325

24-
let fieldList = []
26+
let fieldList = [];
2527

2628
for ( let fieldName in fields ) {
2729
if ( '' === fieldName ) {

js/blocks/loader/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* WordPress dependencies
43
*/
@@ -56,6 +55,6 @@ const registerBlocks = () => {
5655
},
5756
} )
5857
}
59-
}
58+
};
6059

6160
export default registerBlocks();

phpcs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
<rule ref="WordPress" />
66

7+
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
8+
<exclude-pattern>tests/*</exclude-pattern>
9+
</rule>
10+
711
<config name="testVersion" value="5.4-"/>
812

913
<arg value="s"/>

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414

1515
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
16-
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL;
16+
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1717
exit( 1 );
1818
}
1919

tests/php/integration/test-template-output.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Test_Template_Output
44
*
5-
* @package Template_Output
5+
* @package Block_Lab
66
*/
77

88
use Block_Lab\Post_Types;
@@ -30,7 +30,7 @@ class Test_Template_Output extends \WP_UnitTestCase {
3030
public $string_fields;
3131

3232
/**
33-
* All fields that don't return a string for block_value(), other than the repeater.
33+
* All fields that return either an object or ID for block_value().
3434
*
3535
* @var array
3636
*/
@@ -301,7 +301,7 @@ public function get_block_config() {
301301
*
302302
* Every field except the Repeater is tested.
303303
* This sets mock block attributes, like those that would be saved from a block.
304-
* Then, it looks for the mock template in the theme directory's blocks/ directory,
304+
* Then, it loads the mock template in the theme's blocks/ directory,
305305
* and ensures that all of these fields appear correctly in it.
306306
*/
307307
public function test_block_template() {

tests/php/unit/admin/test-class-import.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function test_register_importer() {
8181
array(
8282
'Block Lab',
8383
'Import custom blocks created with Block Lab.',
84-
array( $this->instance, 'render_page' )
84+
array( $this->instance, 'render_page' ),
8585
),
8686
$wp_importers[ $this->instance->slug ]
8787
);
@@ -162,16 +162,19 @@ public function test_render_page() {
162162
)
163163
);
164164
$_FILES['import'] = $files_import;
165-
add_filter( 'wp_handle_upload', function( $upload ) use ( $file ) {
166-
unset( $upload );
167-
return array_merge(
168-
$file,
169-
array(
170-
'url' => 'https://example.com/foo',
171-
'type' => 'text/plain',
172-
)
173-
);
174-
} );
165+
add_filter(
166+
'wp_handle_upload',
167+
function( $upload ) use ( $file ) {
168+
unset( $upload );
169+
return array_merge(
170+
$file,
171+
array(
172+
'url' => 'https://example.com/foo',
173+
'type' => 'text/plain',
174+
)
175+
);
176+
}
177+
);
175178

176179
Monkey\Functions\expect( 'filter_input' )
177180
->twice()
@@ -222,16 +225,18 @@ function wp_handle_upload_error( $file, $message ) {
222225
$_FILES['import'] = $files_import;
223226

224227
remove_all_filters( 'wp_handle_upload' );
225-
add_filter( 'wp_handle_upload', function( $upload ) use ( $file ) {
226-
unset( $upload );
227-
return array_merge(
228-
$file,
229-
array(
230-
'url' => 'https://example.com/foo',
231-
'type' => 'text/plain',
232-
)
233-
);
234-
} );
228+
add_filter(
229+
'wp_handle_upload',
230+
function() use ( $file ) {
231+
return array_merge(
232+
$file,
233+
array(
234+
'url' => 'https://example.com/foo',
235+
'type' => 'text/plain',
236+
)
237+
);
238+
}
239+
);
235240

236241
Monkey\Functions\expect( 'is_uploaded_file' )
237242
->once()
@@ -347,7 +352,7 @@ public function test_validate_upload() {
347352
$nonexistent_file = 'does-not-exist.xml';
348353

349354
ob_start();
350-
$this->assertFalse( $this->instance->validate_upload( array( 'file' => $nonexistent_file) ) );
355+
$this->assertFalse( $this->instance->validate_upload( array( 'file' => $nonexistent_file ) ) );
351356
$output = ob_get_clean();
352357

353358
// If the file doesn't exist, this should have a message that reflects that.

tests/php/unit/admin/test-class-license.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function test_get_license() {
183183
$this->instance->init();
184184
$valid_license_transient_value = array(
185185
'license' => 'valid',
186-
'expires' => date( 'Y-m-d', time() + DAY_IN_SECONDS )
186+
'expires' => date( 'Y-m-d', time() + DAY_IN_SECONDS ),
187187
);
188188
$invalid_license_transient_value = array(
189189
'license' => 'expired',
@@ -206,10 +206,13 @@ public function test_get_license() {
206206
'expires' => $expiration_date,
207207
);
208208

209-
add_filter( self::HTTP_FILTER_NAME, function( $response ) use ( $expected_license ) {
210-
unset( $response );
211-
return array( 'body' => wp_json_encode( $expected_license ) );
212-
} );
209+
add_filter(
210+
self::HTTP_FILTER_NAME,
211+
function( $response ) use ( $expected_license ) {
212+
unset( $response );
213+
return array( 'body' => wp_json_encode( $expected_license ) );
214+
}
215+
);
213216

214217
delete_transient( self::LICENSE_TRANSIENT_NAME );
215218
$example_valid_license_key = '5134315';
@@ -227,10 +230,12 @@ public function test_get_license() {
227230
public function test_activate_license() {
228231
$this->instance->init();
229232
$license_key = '6234234';
230-
add_filter( self::HTTP_FILTER_NAME, function( $response ) {
231-
unset( $response );
232-
return new WP_Error();
233-
} );
233+
add_filter(
234+
self::HTTP_FILTER_NAME, function( $response ) {
235+
unset( $response );
236+
return new WP_Error();
237+
}
238+
);
234239

235240
// If the POST request returns a wp_error(), this should return false.
236241
$this->assertFalse( $this->instance->activate_license( $license_key ) );
@@ -242,10 +247,13 @@ public function test_activate_license() {
242247
'expires' => date( 'Y-m-d', time() + DAY_IN_SECONDS ),
243248
);
244249

245-
add_filter( self::HTTP_FILTER_NAME, function( $response ) use ( $expected_license ) {
246-
unset( $response );
247-
return array( 'body' => wp_json_encode( $expected_license ) );
248-
} );
250+
add_filter(
251+
self::HTTP_FILTER_NAME,
252+
function( $response ) use ( $expected_license ) {
253+
unset( $response );
254+
return array( 'body' => wp_json_encode( $expected_license ) );
255+
}
256+
);
249257
$this->instance->activate_license( $license_key );
250258

251259
// Having simulated a successful license validation with the filter above, this should activate the license.

tests/php/unit/admin/test-class-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function test_render_page_header() {
209209
* @covers \Block_Lab\Admin\Settings::prepare_notice()
210210
*/
211211
public function test_prepare_notice() {
212-
$notice = 'There was a problem activating your Block Lab license.';
212+
$notice = 'There was a problem activating your Block Lab license.';
213213
$this->instance->prepare_notice( $notice );
214214

215215
$this->assertEquals( array( $notice ), get_option( self::NOTICES_OPTION_NAME ) );

tests/php/unit/blocks/controls/test-class-control-abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function test_render_select() {
163163
$options = array(
164164
'foo' => 'One',
165165
'bar' => 'Two',
166-
'baz' => 'Three'
166+
'baz' => 'Three',
167167
);
168168
ob_start();
169169
$this->instance->render_select( $this->setting, self::NAME, self::ID, $options );

0 commit comments

Comments
 (0)