Skip to content

Commit b415b64

Browse files
committed
Run composer format to fix reported violations
1 parent c111125 commit b415b64

File tree

2 files changed

+66
-60
lines changed

2 files changed

+66
-60
lines changed

tests/phpunit/tests/rest-api/wpRestAbilitiesListController.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ public function test_get_items(): void {
194194
$this->assertIsArray( $data );
195195
$this->assertNotEmpty( $data );
196196

197-
198197
$this->assertCount( 50, $data, 'First page should return exactly 50 items (default per_page)' );
199198

200199
$ability_names = wp_list_pluck( $data, 'name' );
@@ -292,7 +291,7 @@ public function test_pagination_links(): void {
292291

293292
// Test last page (should have 'prev' link but no 'next')
294293
$total_abilities = count( wp_get_abilities() );
295-
$last_page = ceil( $total_abilities / 10 );
294+
$last_page = ceil( $total_abilities / 10 );
296295
$request->set_param( 'page', $last_page );
297296
$response = $this->server->dispatch( $request );
298297

@@ -378,7 +377,7 @@ public function test_context_parameter(): void {
378377
* Test schema retrieval.
379378
*/
380379
public function test_get_schema(): void {
381-
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/abilities' );
380+
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/abilities' );
382381
$response = $this->server->dispatch( $request );
383382
$data = $response->get_data();
384383

@@ -406,17 +405,17 @@ public function test_ability_name_with_valid_special_characters(): void {
406405
wp_register_ability(
407406
'test-hyphen/ability',
408407
array(
409-
'label' => 'Test Hyphen Ability',
410-
'description' => 'Test ability with hyphen',
411-
'execute_callback' => function( $input ) {
408+
'label' => 'Test Hyphen Ability',
409+
'description' => 'Test ability with hyphen',
410+
'execute_callback' => function ( $input ) {
412411
return array( 'success' => true );
413412
},
414413
'permission_callback' => '__return_true',
415414
)
416415
);
417416

418417
// Test valid special characters (hyphen, forward slash)
419-
$request = new WP_REST_Request( 'GET', '/wp/v2/abilities/test-hyphen/ability' );
418+
$request = new WP_REST_Request( 'GET', '/wp/v2/abilities/test-hyphen/ability' );
420419
$response = $this->server->dispatch( $request );
421420
$this->assertEquals( 200, $response->get_status() );
422421
}
@@ -446,7 +445,7 @@ public function invalid_ability_names_provider(): array {
446445
* @param string $name Invalid ability name to test.
447446
*/
448447
public function test_ability_name_with_invalid_special_characters( string $name ): void {
449-
$request = new WP_REST_Request( 'GET', '/wp/v2/abilities/' . $name );
448+
$request = new WP_REST_Request( 'GET', '/wp/v2/abilities/' . $name );
450449
$response = $this->server->dispatch( $request );
451450
// Should return 404 as the regex pattern won't match
452451
$this->assertEquals( 404, $response->get_status() );
@@ -461,7 +460,7 @@ public function test_extremely_long_ability_names(): void {
461460
// Create a very long but valid ability name
462461
$long_name = 'test/' . str_repeat( 'a', 1000 );
463462

464-
$request = new WP_REST_Request( 'GET', '/wp/v2/abilities/' . $long_name );
463+
$request = new WP_REST_Request( 'GET', '/wp/v2/abilities/' . $long_name );
465464
$response = $this->server->dispatch( $request );
466465

467466
// Should return 404 as ability doesn't exist

tests/phpunit/tests/rest-api/wpRestAbilitiesRunController.php

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,18 @@ public function test_invalid_json_in_post_body(): void {
526526
*/
527527
public function test_get_request_with_nested_input_array(): void {
528528
$request = new WP_REST_Request( 'GET', '/wp/v2/abilities/test/query-params/run' );
529-
$request->set_query_params( array(
530-
'input' => array(
531-
'level1' => array(
532-
'level2' => array(
533-
'value' => 'nested',
529+
$request->set_query_params(
530+
array(
531+
'input' => array(
532+
'level1' => array(
533+
'level2' => array(
534+
'value' => 'nested',
535+
),
534536
),
537+
'array' => array( 1, 2, 3 ),
535538
),
536-
'array' => array( 1, 2, 3 ),
537-
),
538-
) );
539+
)
540+
);
539541

540542
$response = $this->server->dispatch( $request );
541543
$this->assertEquals( 200, $response->get_status() );
@@ -550,9 +552,11 @@ public function test_get_request_with_nested_input_array(): void {
550552
*/
551553
public function test_get_request_with_non_array_input(): void {
552554
$request = new WP_REST_Request( 'GET', '/wp/v2/abilities/test/query-params/run' );
553-
$request->set_query_params( array(
554-
'input' => 'not-an-array', // String instead of array
555-
) );
555+
$request->set_query_params(
556+
array(
557+
'input' => 'not-an-array', // String instead of array
558+
)
559+
);
556560

557561
$response = $this->server->dispatch( $request );
558562
// When input is not an array, WordPress returns 400 Bad Request
@@ -565,9 +569,13 @@ public function test_get_request_with_non_array_input(): void {
565569
public function test_post_request_with_non_array_input(): void {
566570
$request = new WP_REST_Request( 'POST', '/wp/v2/abilities/test/calculator/run' );
567571
$request->set_header( 'Content-Type', 'application/json' );
568-
$request->set_body( wp_json_encode( array(
569-
'input' => 'string-value', // String instead of array
570-
) ) );
572+
$request->set_body(
573+
wp_json_encode(
574+
array(
575+
'input' => 'string-value', // String instead of array
576+
)
577+
)
578+
);
571579

572580
$response = $this->server->dispatch( $request );
573581
// When input is not an array, WordPress returns 400 Bad Request
@@ -583,9 +591,9 @@ public function test_output_validation_failure_returns_error(): void {
583591
wp_register_ability(
584592
'test/strict-output',
585593
array(
586-
'label' => 'Strict Output',
587-
'description' => 'Ability with strict output schema',
588-
'output_schema' => array(
594+
'label' => 'Strict Output',
595+
'description' => 'Ability with strict output schema',
596+
'output_schema' => array(
589597
'type' => 'object',
590598
'properties' => array(
591599
'status' => array(
@@ -595,12 +603,12 @@ public function test_output_validation_failure_returns_error(): void {
595603
),
596604
'required' => array( 'status' ),
597605
),
598-
'execute_callback' => function( $input ) {
606+
'execute_callback' => function ( $input ) {
599607
// Return invalid output that doesn't match schema
600608
return array( 'wrong_field' => 'value' );
601609
},
602610
'permission_callback' => '__return_true',
603-
'meta' => array( 'type' => 'tool' ),
611+
'meta' => array( 'type' => 'tool' ),
604612
)
605613
);
606614

@@ -625,9 +633,9 @@ public function test_input_validation_failure_returns_error(): void {
625633
wp_register_ability(
626634
'test/strict-input',
627635
array(
628-
'label' => 'Strict Input',
629-
'description' => 'Ability with strict input schema',
630-
'input_schema' => array(
636+
'label' => 'Strict Input',
637+
'description' => 'Ability with strict input schema',
638+
'input_schema' => array(
631639
'type' => 'object',
632640
'properties' => array(
633641
'required_field' => array(
@@ -636,11 +644,11 @@ public function test_input_validation_failure_returns_error(): void {
636644
),
637645
'required' => array( 'required_field' ),
638646
),
639-
'execute_callback' => function( $input ) {
647+
'execute_callback' => function ( $input ) {
640648
return array( 'status' => 'success' );
641649
},
642650
'permission_callback' => '__return_true',
643-
'meta' => array( 'type' => 'tool' ),
651+
'meta' => array( 'type' => 'tool' ),
644652
)
645653
);
646654

@@ -665,18 +673,18 @@ public function test_ability_without_type_defaults_to_tool(): void {
665673
wp_register_ability(
666674
'test/no-type',
667675
array(
668-
'label' => 'No Type',
669-
'description' => 'Ability without type',
670-
'execute_callback' => function( $input ) {
676+
'label' => 'No Type',
677+
'description' => 'Ability without type',
678+
'execute_callback' => function ( $input ) {
671679
return array( 'executed' => true );
672680
},
673681
'permission_callback' => '__return_true',
674-
'meta' => array(), // No type specified
682+
'meta' => array(), // No type specified
675683
)
676684
);
677685

678686
// Should require POST (default tool behavior)
679-
$get_request = new WP_REST_Request( 'GET', '/wp/v2/abilities/test/no-type/run' );
687+
$get_request = new WP_REST_Request( 'GET', '/wp/v2/abilities/test/no-type/run' );
680688
$get_response = $this->server->dispatch( $get_request );
681689
$this->assertEquals( 405, $get_response->get_status() );
682690

@@ -699,7 +707,7 @@ public function test_permission_check_passes_when_callback_not_set(): void {
699707
array(
700708
'label' => 'No Permission Callback',
701709
'description' => 'Ability without permission callback',
702-
'execute_callback' => function( $input ) {
710+
'execute_callback' => function ( $input ) {
703711
return array( 'executed' => true );
704712
},
705713
'meta' => array( 'type' => 'tool' ),
@@ -730,31 +738,31 @@ public function test_empty_input_handling(): void {
730738
wp_register_ability(
731739
'test/resource-empty',
732740
array(
733-
'label' => 'Resource Empty',
734-
'description' => 'Resource with empty input',
735-
'execute_callback' => function( $input ) {
741+
'label' => 'Resource Empty',
742+
'description' => 'Resource with empty input',
743+
'execute_callback' => function ( $input ) {
736744
return array( 'input_was_empty' => empty( $input ) );
737745
},
738746
'permission_callback' => '__return_true',
739-
'meta' => array( 'type' => 'resource' ),
747+
'meta' => array( 'type' => 'resource' ),
740748
)
741749
);
742750

743751
wp_register_ability(
744752
'test/tool-empty',
745753
array(
746-
'label' => 'Tool Empty',
747-
'description' => 'Tool with empty input',
748-
'execute_callback' => function( $input ) {
754+
'label' => 'Tool Empty',
755+
'description' => 'Tool with empty input',
756+
'execute_callback' => function ( $input ) {
749757
return array( 'input_was_empty' => empty( $input ) );
750758
},
751759
'permission_callback' => '__return_true',
752-
'meta' => array( 'type' => 'tool' ),
760+
'meta' => array( 'type' => 'tool' ),
753761
)
754762
);
755763

756764
// Test GET with no input parameter
757-
$get_request = new WP_REST_Request( 'GET', '/wp/v2/abilities/test/resource-empty/run' );
765+
$get_request = new WP_REST_Request( 'GET', '/wp/v2/abilities/test/resource-empty/run' );
758766
$get_response = $this->server->dispatch( $get_request );
759767
$this->assertEquals( 200, $get_response->get_status() );
760768
$this->assertTrue( $get_response->get_data()['input_was_empty'] );
@@ -813,13 +821,13 @@ public function test_php_type_strings_in_input(): void {
813821
wp_register_ability(
814822
'test/echo',
815823
array(
816-
'label' => 'Echo',
817-
'description' => 'Echoes input',
818-
'execute_callback' => function( $input ) {
824+
'label' => 'Echo',
825+
'description' => 'Echoes input',
826+
'execute_callback' => function ( $input ) {
819827
return array( 'echo' => $input );
820828
},
821829
'permission_callback' => '__return_true',
822-
'meta' => array( 'type' => 'tool' ),
830+
'meta' => array( 'type' => 'tool' ),
823831
)
824832
);
825833

@@ -854,13 +862,13 @@ public function test_mixed_encoding_in_input(): void {
854862
wp_register_ability(
855863
'test/echo-encoding',
856864
array(
857-
'label' => 'Echo Encoding',
858-
'description' => 'Echoes input with encoding',
859-
'execute_callback' => function( $input ) {
865+
'label' => 'Echo Encoding',
866+
'description' => 'Echoes input with encoding',
867+
'execute_callback' => function ( $input ) {
860868
return array( 'echo' => $input );
861869
},
862870
'permission_callback' => '__return_true',
863-
'meta' => array( 'type' => 'tool' ),
871+
'meta' => array( 'type' => 'tool' ),
864872
)
865873
);
866874

@@ -916,15 +924,15 @@ public function test_invalid_http_methods( string $method ): void {
916924
array(
917925
'label' => 'Method Test',
918926
'description' => 'Test ability for HTTP method validation',
919-
'execute_callback' => function() {
927+
'execute_callback' => function () {
920928
return array( 'success' => true );
921929
},
922930
'permission_callback' => '__return_true', // No permission requirements
923931
'meta' => array( 'type' => 'tool' ),
924932
)
925933
);
926934

927-
$request = new WP_REST_Request( $method, '/wp/v2/abilities/test/method-test/run' );
935+
$request = new WP_REST_Request( $method, '/wp/v2/abilities/test/method-test/run' );
928936
$response = $this->server->dispatch( $request );
929937

930938
// Tool abilities should only accept POST, so these should return 405
@@ -937,10 +945,9 @@ public function test_invalid_http_methods( string $method ): void {
937945
* Test OPTIONS method handling.
938946
*/
939947
public function test_options_method_handling(): void {
940-
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/abilities/test/calculator/run' );
948+
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/abilities/test/calculator/run' );
941949
$response = $this->server->dispatch( $request );
942950
// OPTIONS requests return 200 with allowed methods
943951
$this->assertEquals( 200, $response->get_status() );
944952
}
945-
946953
}

0 commit comments

Comments
 (0)