@@ -611,70 +611,71 @@ private function invokeMethodsBeforeFirstTest(Event\Emitter $emitter, Event\Test
611
611
return true ;
612
612
}
613
613
614
- $ methodsCalledBeforeFirstTest = [];
614
+ $ methods = (new HookMethods )->hookMethods ($ this ->name )['beforeClass ' ]->methodNamesSortedByPriority ();
615
+ $ calledMethods = [];
616
+ $ emitCalledEvent = true ;
617
+ $ result = true ;
615
618
616
- $ beforeClassMethods = (new HookMethods )->hookMethods ($ this ->name )['beforeClass ' ];
619
+ foreach ($ methods as $ method ) {
620
+ if ($ this ->methodDoesNotExistOrIsDeclaredInTestCase ($ method )) {
621
+ continue ;
622
+ }
617
623
618
- try {
619
- foreach ($ beforeClassMethods ->methodNamesSortedByPriority () as $ beforeClassMethod ) {
620
- if ($ this ->methodDoesNotExistOrIsDeclaredInTestCase ($ beforeClassMethod )) {
621
- continue ;
622
- }
624
+ $ calledMethod = new Event \Code \ClassMethod (
625
+ $ this ->name ,
626
+ $ method ,
627
+ );
623
628
624
- $ missingRequirements = (new Requirements )->requirementsNotSatisfiedFor ($ this ->name , $ beforeClassMethod );
629
+ try {
630
+ $ missingRequirements = (new Requirements )->requirementsNotSatisfiedFor ($ this ->name , $ method );
625
631
626
632
if ($ missingRequirements !== []) {
633
+ $ emitCalledEvent = false ;
634
+
627
635
$ this ->markTestSuiteSkipped (implode (PHP_EOL , $ missingRequirements ));
628
636
}
629
637
630
- $ methodCalledBeforeFirstTest = new Event \Code \ClassMethod (
631
- $ this ->name ,
632
- $ beforeClassMethod ,
633
- );
638
+ call_user_func ([$ this ->name , $ method ]);
639
+ } catch (Throwable $ t ) {
640
+ }
634
641
642
+ if ($ emitCalledEvent ) {
635
643
$ emitter ->testBeforeFirstTestMethodCalled (
636
644
$ this ->name ,
637
- $ methodCalledBeforeFirstTest ,
645
+ $ calledMethod ,
638
646
);
639
647
640
- $ methodsCalledBeforeFirstTest [] = $ methodCalledBeforeFirstTest ;
641
-
642
- call_user_func ([$ this ->name , $ beforeClassMethod ]);
648
+ $ calledMethods [] = $ calledMethod ;
643
649
}
644
- } catch (SkippedTest |SkippedTestSuiteError $ e ) {
645
- $ emitter ->testSuiteSkipped (
646
- $ testSuiteValueObjectForEvents ,
647
- $ e ->getMessage (),
648
- );
649
650
650
- return false ;
651
- } catch (Throwable $ t ) {
652
- assert (isset ($ methodCalledBeforeFirstTest ));
651
+ if (isset ($ t ) && $ t instanceof SkippedTest) {
652
+ $ emitter ->testSuiteSkipped (
653
+ $ testSuiteValueObjectForEvents ,
654
+ $ t ->getMessage (),
655
+ );
653
656
654
- $ emitter ->testBeforeFirstTestMethodErrored (
655
- $ this ->name ,
656
- $ methodCalledBeforeFirstTest ,
657
- Event \Code \ThrowableBuilder::from ($ t ),
658
- );
657
+ return false ;
658
+ }
659
659
660
- if (! empty ( $ methodsCalledBeforeFirstTest )) {
661
- $ emitter ->testBeforeFirstTestMethodFinished (
660
+ if (isset ( $ t )) {
661
+ $ emitter ->testBeforeFirstTestMethodErrored (
662
662
$ this ->name ,
663
- ...$ methodsCalledBeforeFirstTest ,
663
+ $ calledMethod ,
664
+ Event \Code \ThrowableBuilder::from ($ t ),
664
665
);
665
- }
666
666
667
- return false ;
667
+ $ result = false ;
668
+ }
668
669
}
669
670
670
- if (!empty ($ methodsCalledBeforeFirstTest )) {
671
+ if (!empty ($ calledMethods )) {
671
672
$ emitter ->testBeforeFirstTestMethodFinished (
672
673
$ this ->name ,
673
- ...$ methodsCalledBeforeFirstTest ,
674
+ ...$ calledMethods ,
674
675
);
675
676
}
676
677
677
- return true ;
678
+ return $ result ;
678
679
}
679
680
680
681
private function invokeMethodsAfterLastTest (Event \Emitter $ emitter ): void
@@ -683,38 +684,44 @@ private function invokeMethodsAfterLastTest(Event\Emitter $emitter): void
683
684
return ;
684
685
}
685
686
686
- $ methodsCalledAfterLastTest = [];
687
-
688
- $ afterClassMethods = (new HookMethods )->hookMethods ($ this ->name )['afterClass ' ];
687
+ $ methods = (new HookMethods )->hookMethods ($ this ->name )['afterClass ' ]->methodNamesSortedByPriority ();
688
+ $ calledMethods = [];
689
689
690
- foreach ($ afterClassMethods -> methodNamesSortedByPriority () as $ afterClassMethod ) {
691
- if ($ this ->methodDoesNotExistOrIsDeclaredInTestCase ($ afterClassMethod )) {
690
+ foreach ($ methods as $ method ) {
691
+ if ($ this ->methodDoesNotExistOrIsDeclaredInTestCase ($ method )) {
692
692
continue ;
693
693
}
694
694
695
+ $ calledMethod = new Event \Code \ClassMethod (
696
+ $ this ->name ,
697
+ $ method ,
698
+ );
699
+
695
700
try {
696
- call_user_func ([$ this ->name , $ afterClassMethod ]);
701
+ call_user_func ([$ this ->name , $ method ]);
702
+ } catch (Throwable $ t ) {
703
+ }
697
704
698
- $ methodCalledAfterLastTest = new Event \ Code \ ClassMethod (
699
- $ this ->name ,
700
- $ afterClassMethod ,
701
- );
705
+ $ emitter -> testAfterLastTestMethodCalled (
706
+ $ this ->name ,
707
+ $ calledMethod ,
708
+ );
702
709
703
- $ emitter ->testAfterLastTestMethodCalled (
710
+ $ calledMethods [] = $ calledMethod ;
711
+
712
+ if (isset ($ t )) {
713
+ $ emitter ->testAfterLastTestMethodErrored (
704
714
$ this ->name ,
705
- $ methodCalledAfterLastTest ,
715
+ $ calledMethod ,
716
+ Event \Code \ThrowableBuilder::from ($ t ),
706
717
);
707
-
708
- $ methodsCalledAfterLastTest [] = $ methodCalledAfterLastTest ;
709
- } catch (Throwable ) {
710
- // @todo
711
718
}
712
719
}
713
720
714
- if (!empty ($ methodsCalledAfterLastTest )) {
721
+ if (!empty ($ calledMethods )) {
715
722
$ emitter ->testAfterLastTestMethodFinished (
716
723
$ this ->name ,
717
- ...$ methodsCalledAfterLastTest ,
724
+ ...$ calledMethods ,
718
725
);
719
726
}
720
727
}
0 commit comments