Skip to content

Commit 6bfd534

Browse files
Merge branch '10.5' into 11.5
2 parents 0acb4cc + c882364 commit 6bfd534

File tree

2 files changed

+66
-55
lines changed

2 files changed

+66
-55
lines changed

src/Framework/TestSuite.php

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -611,70 +611,71 @@ private function invokeMethodsBeforeFirstTest(Event\Emitter $emitter, Event\Test
611611
return true;
612612
}
613613

614-
$methodsCalledBeforeFirstTest = [];
614+
$methods = (new HookMethods)->hookMethods($this->name)['beforeClass']->methodNamesSortedByPriority();
615+
$calledMethods = [];
616+
$emitCalledEvent = true;
617+
$result = true;
615618

616-
$beforeClassMethods = (new HookMethods)->hookMethods($this->name)['beforeClass'];
619+
foreach ($methods as $method) {
620+
if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {
621+
continue;
622+
}
617623

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+
);
623628

624-
$missingRequirements = (new Requirements)->requirementsNotSatisfiedFor($this->name, $beforeClassMethod);
629+
try {
630+
$missingRequirements = (new Requirements)->requirementsNotSatisfiedFor($this->name, $method);
625631

626632
if ($missingRequirements !== []) {
633+
$emitCalledEvent = false;
634+
627635
$this->markTestSuiteSkipped(implode(PHP_EOL, $missingRequirements));
628636
}
629637

630-
$methodCalledBeforeFirstTest = new Event\Code\ClassMethod(
631-
$this->name,
632-
$beforeClassMethod,
633-
);
638+
call_user_func([$this->name, $method]);
639+
} catch (Throwable $t) {
640+
}
634641

642+
if ($emitCalledEvent) {
635643
$emitter->testBeforeFirstTestMethodCalled(
636644
$this->name,
637-
$methodCalledBeforeFirstTest,
645+
$calledMethod,
638646
);
639647

640-
$methodsCalledBeforeFirstTest[] = $methodCalledBeforeFirstTest;
641-
642-
call_user_func([$this->name, $beforeClassMethod]);
648+
$calledMethods[] = $calledMethod;
643649
}
644-
} catch (SkippedTest|SkippedTestSuiteError $e) {
645-
$emitter->testSuiteSkipped(
646-
$testSuiteValueObjectForEvents,
647-
$e->getMessage(),
648-
);
649650

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+
);
653656

654-
$emitter->testBeforeFirstTestMethodErrored(
655-
$this->name,
656-
$methodCalledBeforeFirstTest,
657-
Event\Code\ThrowableBuilder::from($t),
658-
);
657+
return false;
658+
}
659659

660-
if (!empty($methodsCalledBeforeFirstTest)) {
661-
$emitter->testBeforeFirstTestMethodFinished(
660+
if (isset($t)) {
661+
$emitter->testBeforeFirstTestMethodErrored(
662662
$this->name,
663-
...$methodsCalledBeforeFirstTest,
663+
$calledMethod,
664+
Event\Code\ThrowableBuilder::from($t),
664665
);
665-
}
666666

667-
return false;
667+
$result = false;
668+
}
668669
}
669670

670-
if (!empty($methodsCalledBeforeFirstTest)) {
671+
if (!empty($calledMethods)) {
671672
$emitter->testBeforeFirstTestMethodFinished(
672673
$this->name,
673-
...$methodsCalledBeforeFirstTest,
674+
...$calledMethods,
674675
);
675676
}
676677

677-
return true;
678+
return $result;
678679
}
679680

680681
private function invokeMethodsAfterLastTest(Event\Emitter $emitter): void
@@ -683,38 +684,44 @@ private function invokeMethodsAfterLastTest(Event\Emitter $emitter): void
683684
return;
684685
}
685686

686-
$methodsCalledAfterLastTest = [];
687-
688-
$afterClassMethods = (new HookMethods)->hookMethods($this->name)['afterClass'];
687+
$methods = (new HookMethods)->hookMethods($this->name)['afterClass']->methodNamesSortedByPriority();
688+
$calledMethods = [];
689689

690-
foreach ($afterClassMethods->methodNamesSortedByPriority() as $afterClassMethod) {
691-
if ($this->methodDoesNotExistOrIsDeclaredInTestCase($afterClassMethod)) {
690+
foreach ($methods as $method) {
691+
if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {
692692
continue;
693693
}
694694

695+
$calledMethod = new Event\Code\ClassMethod(
696+
$this->name,
697+
$method,
698+
);
699+
695700
try {
696-
call_user_func([$this->name, $afterClassMethod]);
701+
call_user_func([$this->name, $method]);
702+
} catch (Throwable $t) {
703+
}
697704

698-
$methodCalledAfterLastTest = new Event\Code\ClassMethod(
699-
$this->name,
700-
$afterClassMethod,
701-
);
705+
$emitter->testAfterLastTestMethodCalled(
706+
$this->name,
707+
$calledMethod,
708+
);
702709

703-
$emitter->testAfterLastTestMethodCalled(
710+
$calledMethods[] = $calledMethod;
711+
712+
if (isset($t)) {
713+
$emitter->testAfterLastTestMethodErrored(
704714
$this->name,
705-
$methodCalledAfterLastTest,
715+
$calledMethod,
716+
Event\Code\ThrowableBuilder::from($t),
706717
);
707-
708-
$methodsCalledAfterLastTest[] = $methodCalledAfterLastTest;
709-
} catch (Throwable) {
710-
// @todo
711718
}
712719
}
713720

714-
if (!empty($methodsCalledAfterLastTest)) {
721+
if (!empty($calledMethods)) {
715722
$emitter->testAfterLastTestMethodFinished(
716723
$this->name,
717-
...$methodsCalledAfterLastTest,
724+
...$calledMethods,
718725
);
719726
}
720727
}

tests/end-to-end/event/exception-in-teardown-after-class.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Test Preparation Started (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClas
2323
Test Prepared (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
2424
Test Passed (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
2525
Test Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
26+
After Last Test Method Called (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::tearDownAfterClass)
27+
After Last Test Method Errored (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::tearDownAfterClass)
28+
After Last Test Method Finished:
29+
- PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::tearDownAfterClass
2630
Test Suite Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest, 1 test)
2731
Test Runner Execution Finished
2832
Test Runner Finished

0 commit comments

Comments
 (0)