Skip to content

Commit

Permalink
Merge branch '10.5' into 11.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 10, 2025
2 parents 0acb4cc + c882364 commit 6bfd534
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 55 deletions.
117 changes: 62 additions & 55 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,70 +611,71 @@ private function invokeMethodsBeforeFirstTest(Event\Emitter $emitter, Event\Test
return true;
}

$methodsCalledBeforeFirstTest = [];
$methods = (new HookMethods)->hookMethods($this->name)['beforeClass']->methodNamesSortedByPriority();
$calledMethods = [];
$emitCalledEvent = true;
$result = true;

$beforeClassMethods = (new HookMethods)->hookMethods($this->name)['beforeClass'];
foreach ($methods as $method) {
if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {
continue;
}

try {
foreach ($beforeClassMethods->methodNamesSortedByPriority() as $beforeClassMethod) {
if ($this->methodDoesNotExistOrIsDeclaredInTestCase($beforeClassMethod)) {
continue;
}
$calledMethod = new Event\Code\ClassMethod(
$this->name,
$method,
);

$missingRequirements = (new Requirements)->requirementsNotSatisfiedFor($this->name, $beforeClassMethod);
try {
$missingRequirements = (new Requirements)->requirementsNotSatisfiedFor($this->name, $method);

if ($missingRequirements !== []) {
$emitCalledEvent = false;

$this->markTestSuiteSkipped(implode(PHP_EOL, $missingRequirements));
}

$methodCalledBeforeFirstTest = new Event\Code\ClassMethod(
$this->name,
$beforeClassMethod,
);
call_user_func([$this->name, $method]);
} catch (Throwable $t) {
}

if ($emitCalledEvent) {
$emitter->testBeforeFirstTestMethodCalled(
$this->name,
$methodCalledBeforeFirstTest,
$calledMethod,
);

$methodsCalledBeforeFirstTest[] = $methodCalledBeforeFirstTest;

call_user_func([$this->name, $beforeClassMethod]);
$calledMethods[] = $calledMethod;
}
} catch (SkippedTest|SkippedTestSuiteError $e) {
$emitter->testSuiteSkipped(
$testSuiteValueObjectForEvents,
$e->getMessage(),
);

return false;
} catch (Throwable $t) {
assert(isset($methodCalledBeforeFirstTest));
if (isset($t) && $t instanceof SkippedTest) {
$emitter->testSuiteSkipped(
$testSuiteValueObjectForEvents,
$t->getMessage(),
);

$emitter->testBeforeFirstTestMethodErrored(
$this->name,
$methodCalledBeforeFirstTest,
Event\Code\ThrowableBuilder::from($t),
);
return false;
}

if (!empty($methodsCalledBeforeFirstTest)) {
$emitter->testBeforeFirstTestMethodFinished(
if (isset($t)) {
$emitter->testBeforeFirstTestMethodErrored(
$this->name,
...$methodsCalledBeforeFirstTest,
$calledMethod,
Event\Code\ThrowableBuilder::from($t),
);
}

return false;
$result = false;
}
}

if (!empty($methodsCalledBeforeFirstTest)) {
if (!empty($calledMethods)) {
$emitter->testBeforeFirstTestMethodFinished(
$this->name,
...$methodsCalledBeforeFirstTest,
...$calledMethods,
);
}

return true;
return $result;
}

private function invokeMethodsAfterLastTest(Event\Emitter $emitter): void
Expand All @@ -683,38 +684,44 @@ private function invokeMethodsAfterLastTest(Event\Emitter $emitter): void
return;
}

$methodsCalledAfterLastTest = [];

$afterClassMethods = (new HookMethods)->hookMethods($this->name)['afterClass'];
$methods = (new HookMethods)->hookMethods($this->name)['afterClass']->methodNamesSortedByPriority();
$calledMethods = [];

foreach ($afterClassMethods->methodNamesSortedByPriority() as $afterClassMethod) {
if ($this->methodDoesNotExistOrIsDeclaredInTestCase($afterClassMethod)) {
foreach ($methods as $method) {
if ($this->methodDoesNotExistOrIsDeclaredInTestCase($method)) {
continue;
}

$calledMethod = new Event\Code\ClassMethod(
$this->name,
$method,
);

try {
call_user_func([$this->name, $afterClassMethod]);
call_user_func([$this->name, $method]);
} catch (Throwable $t) {
}

$methodCalledAfterLastTest = new Event\Code\ClassMethod(
$this->name,
$afterClassMethod,
);
$emitter->testAfterLastTestMethodCalled(
$this->name,
$calledMethod,
);

$emitter->testAfterLastTestMethodCalled(
$calledMethods[] = $calledMethod;

if (isset($t)) {
$emitter->testAfterLastTestMethodErrored(
$this->name,
$methodCalledAfterLastTest,
$calledMethod,
Event\Code\ThrowableBuilder::from($t),
);

$methodsCalledAfterLastTest[] = $methodCalledAfterLastTest;
} catch (Throwable) {
// @todo
}
}

if (!empty($methodsCalledAfterLastTest)) {
if (!empty($calledMethods)) {
$emitter->testAfterLastTestMethodFinished(
$this->name,
...$methodsCalledAfterLastTest,
...$calledMethods,
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/end-to-end/event/exception-in-teardown-after-class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Test Preparation Started (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClas
Test Prepared (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
Test Passed (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
Test Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
After Last Test Method Called (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::tearDownAfterClass)
After Last Test Method Errored (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::tearDownAfterClass)
After Last Test Method Finished:
- PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::tearDownAfterClass
Test Suite Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest, 1 test)
Test Runner Execution Finished
Test Runner Finished
Expand Down

0 comments on commit 6bfd534

Please # to comment.