Skip to content

Commit f2d0059

Browse files
committed
Tests: Make widget, block and editor data providers static.
Declare 25 data providers in the widget, block registration, editor, connector, and Interactivity API tests as `public static` for compatibility with newer PHPUnit versions. Preserve their datasets and assertions. Make the Interactivity API JSON serialization helper static so providers can call it without a test instance. Developed in: #14651, #14652, #15117, #15135, #15154 Props devmuhib, rejaulalomkhan, shailu25, huzaifaalmesbah, mukesh27. See #66211. git-svn-id: https://develop.svn.wordpress.org/trunk@65006 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 784062b commit f2d0059

11 files changed

Lines changed: 28 additions & 28 deletions

‎tests/phpunit/tests/blocks/register.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ public function test_register_block_style_handle_uses_correct_core_stylesheet( $
754754
}
755755
}
756756

757-
public function data_register_block_style_handle_uses_correct_core_stylesheet() {
757+
public static function data_register_block_style_handle_uses_correct_core_stylesheet() {
758758
return array(
759759
'block with style' => array(
760760
WPINC . '/blocks/archives/block.json',
@@ -1078,7 +1078,7 @@ public function test_block_registers_with_args_override_returns_false_when_name_
10781078
*
10791079
* @return array[]
10801080
*/
1081-
public function data_register_block_registers_with_args_override_returns_false_when_name_is_missing() {
1081+
public static function data_register_block_registers_with_args_override_returns_false_when_name_is_missing() {
10821082
return array(
10831083
'no block.json file and no name argument' => array(
10841084
'file' => '', // No block.json file.
@@ -1350,7 +1350,7 @@ public function test_register_block_type_accepts_editor_script_array( $editor_sc
13501350
*
13511351
* @return array
13521352
*/
1353-
public function data_register_block_type_accepts_editor_script_array() {
1353+
public static function data_register_block_type_accepts_editor_script_array() {
13541354
return array(
13551355
'an empty array' => array(
13561356
'editor_script' => array(),
@@ -1416,7 +1416,7 @@ public function test_register_block_type_throws_doing_it_wrong( $editor_script,
14161416
*
14171417
* @return array
14181418
*/
1419-
public function data_register_block_type_throws_doing_it_wrong() {
1419+
public static function data_register_block_type_throws_doing_it_wrong() {
14201420
return array(
14211421
'a non-string array' => array(
14221422
'editor_script' => array( null, false, true, -1, 0, 1, -1.0, 0.0, 1.0, INF, NAN, new stdClass() ),
@@ -1607,7 +1607,7 @@ public function test_register_block_style_name_contains_spaces( array $block_sty
16071607
*
16081608
* @return array
16091609
*/
1610-
public function data_register_block_style_name_contains_spaces() {
1610+
public static function data_register_block_style_name_contains_spaces() {
16111611
return array(
16121612
'multiple spaces' => array(
16131613
array(

‎tests/phpunit/tests/connectors/wpConnectorRegistry.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function test_register_rejects_empty_application_password_external_names(
202202
*
203203
* @return array<string, array{string}> Test cases.
204204
*/
205-
public function data_application_password_external_name_keys(): array {
205+
public static function data_application_password_external_name_keys(): array {
206206
return array(
207207
'constant name' => array( 'constant_name' ),
208208
'environment variable name' => array( 'env_var_name' ),

‎tests/phpunit/tests/connectors/wpConnectorsMaskApiKey.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function test_mask_api_key( string $input, string $expected ) {
2929
* @type string $expected Expected masked result.
3030
* }
3131
*/
32-
public function data_mask_api_key(): array {
32+
public static function data_mask_api_key(): array {
3333
$bullet = "\u{2022}";
3434

3535
return array(

‎tests/phpunit/tests/connectors/wpConnectorsRestSettingsDispatch.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public function test_settings_endpoint_masks_credentials_for_every_rest_route_sp
299299
*
300300
* @return array<string, array{string}> Test cases.
301301
*/
302-
public function data_settings_route_spellings(): array {
302+
public static function data_settings_route_spellings(): array {
303303
return array(
304304
'lowercase' => array( '/wp/v2/settings' ),
305305
'mixed case' => array( '/wp/v2/Settings' ),
@@ -314,7 +314,7 @@ public function data_settings_route_spellings(): array {
314314
*
315315
* @return array<string, array{string}> Test cases.
316316
*/
317-
public function data_settings_rest_route_query_values(): array {
317+
public static function data_settings_rest_route_query_values(): array {
318318
return array(
319319
'lowercase' => array( '/wp/v2/settings' ),
320320
'mixed case' => array( '/wp/v2/Settings' ),

‎tests/phpunit/tests/editor/classic-to-block-menu-converter.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function test_passing_non_menu_object_to_converter_returns_wp_error( $dat
4040
* @ticket 58557
4141
* @covers WP_Classic_To_Block_Menu_Converter::convert
4242
*/
43-
public function provider_test_passing_non_menu_object_to_converter_returns_wp_error() {
43+
public static function provider_test_passing_non_menu_object_to_converter_returns_wp_error() {
4444
return array(
4545
array( 1 ),
4646
array( -1 ),

‎tests/phpunit/tests/editor/disableBlockEditorForNavigationPostType.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function test_should_return_false_when_wp_navigation( $supports ) {
2323
*
2424
* @return array
2525
*/
26-
public function data_should_return_false_when_wp_navigation() {
26+
public static function data_should_return_false_when_wp_navigation() {
2727
return array(
2828
'support value: true' => array( true ),
2929
'support value: false' => array( false ),
@@ -46,7 +46,7 @@ public function test_should_return_given_value_for_non_wp_navigation_post_types(
4646
*
4747
* @return array
4848
*/
49-
public function data_should_return_given_value_for_non_wp_navigation_post_types() {
49+
public static function data_should_return_given_value_for_non_wp_navigation_post_types() {
5050
return array(
5151
'post' => array(
5252
'post_type' => 'post',

‎tests/phpunit/tests/editor/disableContentEditorForNavigationPostType.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function test_should_not_disable( $post_type ) {
4444
*
4545
* @return array
4646
*/
47-
public function data_should_not_disable() {
47+
public static function data_should_not_disable() {
4848
return array(
4949
'post' => array( 'post' ),
5050
'page' => array( 'page' ),
@@ -81,7 +81,7 @@ public function test_should_not_change_post_type_support( $post_type ) {
8181
*
8282
* @return array
8383
*/
84-
public function data_should_not_change_post_type_support() {
84+
public static function data_should_not_change_post_type_support() {
8585
return array(
8686
'post' => array( 'post' ),
8787
'page' => array( 'page' ),

‎tests/phpunit/tests/editor/enableContentEditorForNavigationPostType.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function test_should_not_enable( $post_type ) {
6565
*
6666
* @return array
6767
*/
68-
public function data_should_not_enable() {
68+
public static function data_should_not_enable() {
6969
return array(
7070
'invalid post type' => array( 'book' ),
7171
'attachments' => array( 'attachments' ),
@@ -98,7 +98,7 @@ public function test_should_not_change_post_type_support( $post_type ) {
9898
*
9999
* @return array
100100
*/
101-
public function data_should_not_change_post_type_support() {
101+
public static function data_should_not_change_post_type_support() {
102102
return array(
103103
'post' => array( 'post' ),
104104
'page' => array( 'page' ),

‎tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public function test_wp_bind_ignores_unique_id_but_processes_valid_binds() {
494494
*
495495
* @return array<non-empty-string, array{ value: float }> Data provider.
496496
*/
497-
public function data_non_finite_values(): array {
497+
public static function data_non_finite_values(): array {
498498
return array(
499499
'INF' => array( 'value' => INF ),
500500
'-INF' => array( 'value' => -INF ),
@@ -539,7 +539,7 @@ public function test_wp_bind_rejects_non_finite_value( $value ) {
539539
*
540540
* @return array<non-empty-string, array{ value: mixed, expected: string }> Data provider.
541541
*/
542-
public function data_json_serializable_values(): array {
542+
public static function data_json_serializable_values(): array {
543543
return array(
544544
'string' => array(
545545
'value' => 'serialized-form',
@@ -558,7 +558,7 @@ public function data_json_serializable_values(): array {
558558
* value bound on the server has to follow it all the way down to match what the client receives.
559559
*/
560560
'nested' => array(
561-
'value' => $this->get_json_serializable( 'serialized-form' ),
561+
'value' => self::get_json_serializable( 'serialized-form' ),
562562
'expected' => 'serialized-form',
563563
),
564564
);
@@ -814,7 +814,7 @@ public function test_wp_bind_number_value_matches_the_client_store() {
814814
* @param mixed $value Value the object serializes to.
815815
* @return JsonSerializable Object serializing to `$value`.
816816
*/
817-
private function get_json_serializable( $value ): JsonSerializable {
817+
private static function get_json_serializable( $value ): JsonSerializable {
818818
return new class( $value ) implements JsonSerializable {
819819
/**
820820
* Value the object serializes to.
@@ -855,7 +855,7 @@ public function jsonSerialize() {
855855
*
856856
* @return array<non-empty-string, array{ value: mixed, tag_name: non-empty-string, attribute: non-empty-string, existing_value: non-empty-string }> Data provider.
857857
*/
858-
public function data_non_scalar_values(): array {
858+
public static function data_non_scalar_values(): array {
859859
$values = array(
860860
'list' => array( 'a', 'b' ),
861861
'associative array' => array( 'a' => 'b' ),
@@ -891,7 +891,7 @@ public function jsonSerialize() {
891891
return array( 'not' => 'the string representation' );
892892
}
893893
},
894-
'object serializing to an array' => $this->get_json_serializable( array( 'a', 'b' ) ),
894+
'object serializing to an array' => self::get_json_serializable( array( 'a', 'b' ) ),
895895
);
896896

897897
$attributes = array(

‎tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public function test_wp_interactivity_data_wp_context_with_different_arrays( $co
414414
*
415415
* @return array
416416
*/
417-
public function data_wp_interactivity_data_wp_context_with_different_arrays() {
417+
public static function data_wp_interactivity_data_wp_context_with_different_arrays() {
418418
return array(
419419
'empty array' => array(
420420
'context' => array(),
@@ -461,7 +461,7 @@ public function test_wp_interactivity_data_wp_context_with_different_arrays_and_
461461
*
462462
* @return array
463463
*/
464-
public function data_wp_interactivity_data_wp_context_with_different_arrays_and_a_namespace() {
464+
public static function data_wp_interactivity_data_wp_context_with_different_arrays_and_a_namespace() {
465465
return array(
466466
'empty array' => array(
467467
'context' => array(),
@@ -513,7 +513,7 @@ public function test_wp_interactivity_data_wp_context_with_json_flags( $context,
513513
*
514514
* @return array
515515
*/
516-
public function data_wp_interactivity_data_wp_context_with_json_flags() {
516+
public static function data_wp_interactivity_data_wp_context_with_json_flags() {
517517
return array(
518518
'value contains <> brackets' => array(
519519
'context' => array( 'tag' => '<foo>' ),

0 commit comments

Comments
 (0)