@@ -568,18 +568,19 @@ public function test_before_execute_ability_action() {
568568 )
569569 );
570570
571- $ callback = static function ( $ ability_name , $ input ) use ( &$ action_ability_name , &$ action_input ) {
572- $ action_ability_name = $ ability_name ;
573- $ action_input = $ input ;
574- };
575-
576- add_action ( 'wp_before_execute_ability ' , $ callback , 10 , 2 );
571+ add_action (
572+ 'wp_before_execute_ability ' ,
573+ static function ( $ ability_name , $ input ) use ( &$ action_ability_name , &$ action_input ) {
574+ $ action_ability_name = $ ability_name ;
575+ $ action_input = $ input ;
576+ },
577+ 10 ,
578+ 2
579+ );
577580
578581 $ ability = new WP_Ability ( self ::$ test_ability_name , $ args );
579582 $ result = $ ability ->execute ( 5 );
580583
581- remove_action ( 'wp_before_execute_ability ' , $ callback );
582-
583584 $ this ->assertSame ( self ::$ test_ability_name , $ action_ability_name , 'Action should receive correct ability name ' );
584585 $ this ->assertSame ( 5 , $ action_input , 'Action should receive correct input ' );
585586 $ this ->assertSame ( 10 , $ result , 'Ability should execute correctly ' );
@@ -603,18 +604,19 @@ public function test_before_execute_ability_action_no_input() {
603604 )
604605 );
605606
606- $ callback = static function ( $ ability_name , $ input ) use ( &$ action_ability_name , &$ action_input ) {
607- $ action_ability_name = $ ability_name ;
608- $ action_input = $ input ;
609- };
610-
611- add_action ( 'wp_before_execute_ability ' , $ callback , 10 , 2 );
607+ add_action (
608+ 'wp_before_execute_ability ' ,
609+ static function ( $ ability_name , $ input ) use ( &$ action_ability_name , &$ action_input ) {
610+ $ action_ability_name = $ ability_name ;
611+ $ action_input = $ input ;
612+ },
613+ 10 ,
614+ 2
615+ );
612616
613617 $ ability = new WP_Ability ( self ::$ test_ability_name , $ args );
614618 $ result = $ ability ->execute ();
615619
616- remove_action ( 'wp_before_execute_ability ' , $ callback );
617-
618620 $ this ->assertSame ( self ::$ test_ability_name , $ action_ability_name , 'Action should receive correct ability name ' );
619621 $ this ->assertNull ( $ action_input , 'Action should receive null input when no input provided ' );
620622 $ this ->assertSame ( 42 , $ result , 'Ability should execute correctly ' );
@@ -644,19 +646,20 @@ public function test_after_execute_ability_action() {
644646 )
645647 );
646648
647- $ callback = static function ( $ ability_name , $ input , $ result ) use ( &$ action_ability_name , &$ action_input , &$ action_result ) {
648- $ action_ability_name = $ ability_name ;
649- $ action_input = $ input ;
650- $ action_result = $ result ;
651- };
652-
653- add_action ( 'wp_after_execute_ability ' , $ callback , 10 , 3 );
649+ add_action (
650+ 'wp_after_execute_ability ' ,
651+ static function ( $ ability_name , $ input , $ result ) use ( &$ action_ability_name , &$ action_input , &$ action_result ) {
652+ $ action_ability_name = $ ability_name ;
653+ $ action_input = $ input ;
654+ $ action_result = $ result ;
655+ },
656+ 10 ,
657+ 3
658+ );
654659
655660 $ ability = new WP_Ability ( self ::$ test_ability_name , $ args );
656661 $ result = $ ability ->execute ( 7 );
657662
658- remove_action ( 'wp_after_execute_ability ' , $ callback );
659-
660663 $ this ->assertSame ( self ::$ test_ability_name , $ action_ability_name , 'Action should receive correct ability name ' );
661664 $ this ->assertSame ( 7 , $ action_input , 'Action should receive correct input ' );
662665 $ this ->assertSame ( 21 , $ action_result , 'Action should receive correct result ' );
@@ -683,19 +686,20 @@ public function test_after_execute_ability_action_no_input() {
683686 )
684687 );
685688
686- $ callback = static function ( $ ability_name , $ input , $ result ) use ( &$ action_ability_name , &$ action_input , &$ action_result ) {
687- $ action_ability_name = $ ability_name ;
688- $ action_input = $ input ;
689- $ action_result = $ result ;
690- };
691-
692- add_action ( 'wp_after_execute_ability ' , $ callback , 10 , 3 );
689+ add_action (
690+ 'wp_after_execute_ability ' ,
691+ static function ( $ ability_name , $ input , $ result ) use ( &$ action_ability_name , &$ action_input , &$ action_result ) {
692+ $ action_ability_name = $ ability_name ;
693+ $ action_input = $ input ;
694+ $ action_result = $ result ;
695+ },
696+ 10 ,
697+ 3
698+ );
693699
694700 $ ability = new WP_Ability ( self ::$ test_ability_name , $ args );
695701 $ result = $ ability ->execute ();
696702
697- remove_action ( 'wp_after_execute_ability ' , $ callback );
698-
699703 $ this ->assertSame ( self ::$ test_ability_name , $ action_ability_name , 'Action should receive correct ability name ' );
700704 $ this ->assertNull ( $ action_input , 'Action should receive null input when no input provided ' );
701705 $ this ->assertSame ( 'test-result ' , $ action_result , 'Action should receive correct result ' );
@@ -720,23 +724,23 @@ public function test_actions_not_fired_on_permission_failure() {
720724 )
721725 );
722726
723- $ before_callback = static function () use ( &$ before_action_fired ) {
724- $ before_action_fired = true ;
725- };
726-
727- $ after_callback = static function () use ( &$ after_action_fired ) {
728- $ after_action_fired = true ;
729- };
727+ add_action (
728+ 'wp_before_execute_ability ' ,
729+ static function () use ( &$ before_action_fired ) {
730+ $ before_action_fired = true ;
731+ }
732+ );
730733
731- add_action ( 'wp_before_execute_ability ' , $ before_callback );
732- add_action ( 'wp_after_execute_ability ' , $ after_callback );
734+ add_action (
735+ 'wp_after_execute_ability ' ,
736+ static function () use ( &$ after_action_fired ) {
737+ $ after_action_fired = true ;
738+ }
739+ );
733740
734741 $ ability = new WP_Ability ( self ::$ test_ability_name , $ args );
735742 $ result = $ ability ->execute ();
736743
737- remove_action ( 'wp_before_execute_ability ' , $ before_callback );
738- remove_action ( 'wp_after_execute_ability ' , $ after_callback );
739-
740744 $ this ->assertFalse ( $ before_action_fired , 'before_execute_ability action should not be fired on permission failure ' );
741745 $ this ->assertFalse ( $ after_action_fired , 'after_execute_ability action should not be fired on permission failure ' );
742746 $ this ->assertInstanceOf ( WP_Error::class, $ result , 'Should return WP_Error on permission failure ' );
@@ -760,23 +764,23 @@ public function test_after_action_not_fired_on_execution_error() {
760764 )
761765 );
762766
763- $ before_callback = static function () use ( &$ before_action_fired ) {
764- $ before_action_fired = true ;
765- };
766-
767- $ after_callback = static function () use ( &$ after_action_fired ) {
768- $ after_action_fired = true ;
769- };
767+ add_action (
768+ 'wp_before_execute_ability ' ,
769+ static function () use ( &$ before_action_fired ) {
770+ $ before_action_fired = true ;
771+ }
772+ );
770773
771- add_action ( 'wp_before_execute_ability ' , $ before_callback );
772- add_action ( 'wp_after_execute_ability ' , $ after_callback );
774+ add_action (
775+ 'wp_after_execute_ability ' ,
776+ static function () use ( &$ after_action_fired ) {
777+ $ after_action_fired = true ;
778+ }
779+ );
773780
774781 $ ability = new WP_Ability ( self ::$ test_ability_name , $ args );
775782 $ result = $ ability ->execute ();
776783
777- remove_action ( 'wp_before_execute_ability ' , $ before_callback );
778- remove_action ( 'wp_after_execute_ability ' , $ after_callback );
779-
780784 $ this ->assertTrue ( $ before_action_fired , 'before_execute_ability action should be fired even if execution fails ' );
781785 $ this ->assertFalse ( $ after_action_fired , 'after_execute_ability action should not be fired when execution returns WP_Error ' );
782786 $ this ->assertInstanceOf ( WP_Error::class, $ result , 'Should return WP_Error from execution callback ' );
@@ -805,23 +809,23 @@ public function test_after_action_not_fired_on_output_validation_error() {
805809 )
806810 );
807811
808- $ before_callback = static function () use ( &$ before_action_fired ) {
809- $ before_action_fired = true ;
810- };
811-
812- $ after_callback = static function () use ( &$ after_action_fired ) {
813- $ after_action_fired = true ;
814- };
812+ add_action (
813+ 'wp_before_execute_ability ' ,
814+ static function () use ( &$ before_action_fired ) {
815+ $ before_action_fired = true ;
816+ }
817+ );
815818
816- add_action ( 'wp_before_execute_ability ' , $ before_callback );
817- add_action ( 'wp_after_execute_ability ' , $ after_callback );
819+ add_action (
820+ 'wp_after_execute_ability ' ,
821+ static function () use ( &$ after_action_fired ) {
822+ $ after_action_fired = true ;
823+ }
824+ );
818825
819826 $ ability = new WP_Ability ( self ::$ test_ability_name , $ args );
820827 $ result = $ ability ->execute ();
821828
822- remove_action ( 'wp_before_execute_ability ' , $ before_callback );
823- remove_action ( 'wp_after_execute_ability ' , $ after_callback );
824-
825829 $ this ->assertTrue ( $ before_action_fired , 'before_execute_ability action should be fired even if output validation fails ' );
826830 $ this ->assertFalse ( $ after_action_fired , 'after_execute_ability action should not be fired when output validation fails ' );
827831 $ this ->assertInstanceOf ( WP_Error::class, $ result , 'Should return WP_Error for output validation failure ' );
0 commit comments