@@ -522,6 +522,116 @@ public function isForTestClass(): bool
522
522
return class_exists ($ this ->name , false ) && is_subclass_of ($ this ->name , TestCase::class);
523
523
}
524
524
525
+ /**
526
+ * @param ReflectionClass<TestCase> $class
527
+ * @param list<non-empty-string> $groups
528
+ *
529
+ * @throws Exception
530
+ */
531
+ protected function addTestMethod (ReflectionClass $ class , ReflectionMethod $ method , array $ groups ): void
532
+ {
533
+ $ className = $ class ->getName ();
534
+ $ methodName = $ method ->getName ();
535
+
536
+ assert (!empty ($ methodName ));
537
+
538
+ try {
539
+ $ test = (new TestBuilder )->build ($ class , $ methodName , $ groups );
540
+ } catch (InvalidDataProviderException $ e ) {
541
+ Event \Facade::emitter ()->testTriggeredPhpunitError (
542
+ new TestMethod (
543
+ $ className ,
544
+ $ methodName ,
545
+ $ class ->getFileName (),
546
+ $ method ->getStartLine (),
547
+ Event \Code \TestDoxBuilder::fromClassNameAndMethodName (
548
+ $ className ,
549
+ $ methodName ,
550
+ ),
551
+ MetadataCollection::fromArray ([]),
552
+ Event \TestData \TestDataCollection::fromArray ([]),
553
+ ),
554
+ sprintf (
555
+ "The data provider specified for %s::%s is invalid \n%s " ,
556
+ $ className ,
557
+ $ methodName ,
558
+ $ this ->throwableToString ($ e ),
559
+ ),
560
+ );
561
+
562
+ return ;
563
+ }
564
+
565
+ if ($ test instanceof TestCase || $ test instanceof DataProviderTestSuite) {
566
+ $ test ->setDependencies (
567
+ Dependencies::dependencies ($ class ->getName (), $ methodName ),
568
+ );
569
+ }
570
+
571
+ $ this ->addTest (
572
+ $ test ,
573
+ array_merge (
574
+ $ groups ,
575
+ (new Groups )->groups ($ class ->getName (), $ methodName ),
576
+ ),
577
+ );
578
+ }
579
+
580
+ private function clearCaches (): void
581
+ {
582
+ $ this ->providedTests = null ;
583
+ $ this ->requiredTests = null ;
584
+ }
585
+
586
+ /**
587
+ * @param list<non-empty-string> $groups
588
+ */
589
+ private function containsOnlyVirtualGroups (array $ groups ): bool
590
+ {
591
+ foreach ($ groups as $ group ) {
592
+ if (!str_starts_with ($ group , '__phpunit_ ' )) {
593
+ return false ;
594
+ }
595
+ }
596
+
597
+ return true ;
598
+ }
599
+
600
+ private function methodDoesNotExistOrIsDeclaredInTestCase (string $ methodName ): bool
601
+ {
602
+ $ reflector = new ReflectionClass ($ this ->name );
603
+
604
+ return !$ reflector ->hasMethod ($ methodName ) ||
605
+ $ reflector ->getMethod ($ methodName )->getDeclaringClass ()->getName () === TestCase::class;
606
+ }
607
+
608
+ /**
609
+ * @throws Exception
610
+ */
611
+ private function throwableToString (Throwable $ t ): string
612
+ {
613
+ $ message = $ t ->getMessage ();
614
+
615
+ if (empty (trim ($ message ))) {
616
+ $ message = '<no message> ' ;
617
+ }
618
+
619
+ if ($ t instanceof InvalidDataProviderException) {
620
+ return sprintf (
621
+ "%s \n%s " ,
622
+ $ message ,
623
+ Filter::stackTraceFromThrowableAsString ($ t ),
624
+ );
625
+ }
626
+
627
+ return sprintf (
628
+ "%s: %s \n%s " ,
629
+ $ t ::class,
630
+ $ message ,
631
+ Filter::stackTraceFromThrowableAsString ($ t ),
632
+ );
633
+ }
634
+
525
635
/**
526
636
* @throws Exception
527
637
* @throws NoPreviousThrowableException
@@ -639,114 +749,4 @@ public function invokeMethodsAfterLastTest(Event\Emitter $emitter): void
639
749
);
640
750
}
641
751
}
642
-
643
- /**
644
- * @param ReflectionClass<TestCase> $class
645
- * @param list<non-empty-string> $groups
646
- *
647
- * @throws Exception
648
- */
649
- protected function addTestMethod (ReflectionClass $ class , ReflectionMethod $ method , array $ groups ): void
650
- {
651
- $ className = $ class ->getName ();
652
- $ methodName = $ method ->getName ();
653
-
654
- assert (!empty ($ methodName ));
655
-
656
- try {
657
- $ test = (new TestBuilder )->build ($ class , $ methodName , $ groups );
658
- } catch (InvalidDataProviderException $ e ) {
659
- Event \Facade::emitter ()->testTriggeredPhpunitError (
660
- new TestMethod (
661
- $ className ,
662
- $ methodName ,
663
- $ class ->getFileName (),
664
- $ method ->getStartLine (),
665
- Event \Code \TestDoxBuilder::fromClassNameAndMethodName (
666
- $ className ,
667
- $ methodName ,
668
- ),
669
- MetadataCollection::fromArray ([]),
670
- Event \TestData \TestDataCollection::fromArray ([]),
671
- ),
672
- sprintf (
673
- "The data provider specified for %s::%s is invalid \n%s " ,
674
- $ className ,
675
- $ methodName ,
676
- $ this ->throwableToString ($ e ),
677
- ),
678
- );
679
-
680
- return ;
681
- }
682
-
683
- if ($ test instanceof TestCase || $ test instanceof DataProviderTestSuite) {
684
- $ test ->setDependencies (
685
- Dependencies::dependencies ($ class ->getName (), $ methodName ),
686
- );
687
- }
688
-
689
- $ this ->addTest (
690
- $ test ,
691
- array_merge (
692
- $ groups ,
693
- (new Groups )->groups ($ class ->getName (), $ methodName ),
694
- ),
695
- );
696
- }
697
-
698
- private function clearCaches (): void
699
- {
700
- $ this ->providedTests = null ;
701
- $ this ->requiredTests = null ;
702
- }
703
-
704
- /**
705
- * @param list<non-empty-string> $groups
706
- */
707
- private function containsOnlyVirtualGroups (array $ groups ): bool
708
- {
709
- foreach ($ groups as $ group ) {
710
- if (!str_starts_with ($ group , '__phpunit_ ' )) {
711
- return false ;
712
- }
713
- }
714
-
715
- return true ;
716
- }
717
-
718
- private function methodDoesNotExistOrIsDeclaredInTestCase (string $ methodName ): bool
719
- {
720
- $ reflector = new ReflectionClass ($ this ->name );
721
-
722
- return !$ reflector ->hasMethod ($ methodName ) ||
723
- $ reflector ->getMethod ($ methodName )->getDeclaringClass ()->getName () === TestCase::class;
724
- }
725
-
726
- /**
727
- * @throws Exception
728
- */
729
- private function throwableToString (Throwable $ t ): string
730
- {
731
- $ message = $ t ->getMessage ();
732
-
733
- if (empty (trim ($ message ))) {
734
- $ message = '<no message> ' ;
735
- }
736
-
737
- if ($ t instanceof InvalidDataProviderException) {
738
- return sprintf (
739
- "%s \n%s " ,
740
- $ message ,
741
- Filter::stackTraceFromThrowableAsString ($ t ),
742
- );
743
- }
744
-
745
- return sprintf (
746
- "%s: %s \n%s " ,
747
- $ t ::class,
748
- $ message ,
749
- Filter::stackTraceFromThrowableAsString ($ t ),
750
- );
751
- }
752
752
}
0 commit comments