Skip to content

Commit e0fa2c9

Browse files
committed
Tests: Make Abilities API test data providers static.
Declare five data providers as `public static` for compatibility with newer PHPUnit versions. Use an anonymous object for the instance-method callback dataset so it no longer depends on `$this`, preserving coverage of object-method callables. Developed in: WordPress#13975 Props huzaifaalmesbah. See #66211. git-svn-id: https://develop.svn.wordpress.org/trunk@64088 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 440ce37 commit e0fa2c9

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎tests/phpunit/tests/abilities-api/wpAbility.php‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public function test_meta_public_throws_exception_for_non_boolean() {
386386
*
387387
* @return array<string, array{0: array, 1: callable, 2: mixed, 3: mixed}> Data sets with different configurations.
388388
*/
389-
public function data_execute_input() {
389+
public static function data_execute_input() {
390390
return array(
391391
'null input' => array(
392392
array(
@@ -524,7 +524,7 @@ public function test_execute_input( $input_schema, $execute_callback, $input, $r
524524
*
525525
* @return array<string, array{0: array, 1: mixed, 2: bool}> Data sets.
526526
*/
527-
public function data_validate_input_top_level_required() {
527+
public static function data_validate_input_top_level_required() {
528528
$required_true = array(
529529
'type' => 'string',
530530
'required' => true,
@@ -634,7 +634,7 @@ public function my_instance_execute_callback( string $input ): int {
634634
*
635635
* @return array<string, array{0: callable}> Data sets with different execute callbacks.
636636
*/
637-
public function data_execute_callback() {
637+
public static function data_execute_callback() {
638638
return array(
639639
'function name string' => array(
640640
'strlen',
@@ -651,7 +651,14 @@ static function ( string $input ): int {
651651
array( 'Tests_Abilities_API_WpAbility', 'my_static_execute_callback' ),
652652
),
653653
'object method' => array(
654-
array( $this, 'my_instance_execute_callback' ),
654+
array(
655+
new class() {
656+
public function my_instance_execute_callback( string $input ): int {
657+
return strlen( $input );
658+
}
659+
},
660+
'my_instance_execute_callback',
661+
),
655662
),
656663
);
657664
}

‎tests/phpunit/tests/abilities-api/wpAbilityCategoryRegistry.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public function test_category_with_special_characters(): void {
394394
*
395395
* @return array<int, array<string>> Valid ability category slugs.
396396
*/
397-
public function data_valid_slug_provider(): array {
397+
public static function data_valid_slug_provider(): array {
398398
return array(
399399
array( 'test-simple' ),
400400
array( 'test-multiple-words' ),
@@ -430,7 +430,7 @@ public function test_category_slug_valid_formats( string $slug ): void {
430430
*
431431
* @return array<int, array<string>> Invalid ability category slugs.
432432
*/
433-
public function data_invalid_slug_provider(): array {
433+
public static function data_invalid_slug_provider(): array {
434434
return array(
435435
array( 'Test-Uppercase' ),
436436
array( 'test_underscore' ),

0 commit comments

Comments
 (0)