@@ -343,6 +343,74 @@ public function test_execute_input( $input_schema, $execute_callback, $input, $r
343343 $ this ->assertSame ( $ result , $ ability ->execute ( $ input ) );
344344 }
345345
346+ /**
347+ * A static method to be used as a callback in tests.
348+ *
349+ * @param string $input An input string.
350+ * @return int The length of the input string.
351+ */
352+ public static function my_static_execute_callback ( string $ input ): int {
353+ return strlen ( $ input );
354+ }
355+
356+ /**
357+ * A instance method to be used as a callback in tests.
358+ *
359+ * @param string $input An input string.
360+ * @return int The length of the input string.
361+ */
362+ public function my_instance_execute_callback ( string $ input ): int {
363+ return strlen ( $ input );
364+ }
365+
366+ /**
367+ * Data provider for testing different types of execute callbacks.
368+ */
369+ public function data_execute_callback () {
370+ return array (
371+ 'function name string ' => array (
372+ 'strlen ' ,
373+ ),
374+ 'closure ' => array (
375+ static function ( string $ input ): int {
376+ return strlen ( $ input );
377+ },
378+ ),
379+ 'static class method string ' => array (
380+ 'Tests_Abilities_API_WpAbility::my_static_execute_callback ' ,
381+ ),
382+ 'static class method array ' => array (
383+ array ( 'Tests_Abilities_API_WpAbility ' , 'my_static_execute_callback ' ),
384+ ),
385+ 'object method ' => array (
386+ array ( $ this , 'my_instance_execute_callback ' ),
387+ ),
388+ );
389+ }
390+
391+ /**
392+ * Tests the execution of the ability with different types of callbacks.
393+ *
394+ * @dataProvider data_execute_callback
395+ */
396+ public function test_execute_with_different_callbacks ( $ execute_callback ) {
397+ $ args = array_merge (
398+ self ::$ test_ability_properties ,
399+ array (
400+ 'input_schema ' => array (
401+ 'type ' => 'string ' ,
402+ 'description ' => 'Test input string. ' ,
403+ 'required ' => true ,
404+ ),
405+ 'execute_callback ' => $ execute_callback ,
406+ )
407+ );
408+
409+ $ ability = new WP_Ability ( self ::$ test_ability_name , $ args );
410+
411+ $ this ->assertSame ( 6 , $ ability ->execute ( 'hello! ' ) );
412+ }
413+
346414 /**
347415 * Tests the execution of the ability with no input.
348416 */
0 commit comments