Skip to content

Commit d0f88ed

Browse files
committed
Remove cleanup()
Leftover from when watchers were checked after each test.
1 parent d29eefb commit d0f88ed

File tree

2 files changed

+22
-50
lines changed

2 files changed

+22
-50
lines changed

src/AsyncTestCase.php

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ final public function setName(string $name): void
3737
$this->realTestName = $name;
3838
}
3939

40-
/**
41-
* Execute any needed cleanup after the test before loop watchers are checked.
42-
*/
43-
protected function cleanup(): void
44-
{
45-
// Empty method in base class.
46-
}
47-
4840
protected function setUp(): void
4941
{
5042
$this->setUpInvoked = true;
@@ -75,33 +67,29 @@ final protected function runAsyncTest(mixed ...$args): mixed
7567
$start = now();
7668

7769
try {
78-
try {
79-
[, $returnValue] = all([
80-
$this->deferredFuture->getFuture(),
81-
async(function () use ($args): mixed {
82-
try {
83-
$result = ([$this, $this->realTestName])(...$args);
84-
if ($result instanceof Future) {
85-
$result = $result->await();
86-
}
87-
88-
// Force an extra tick of the event loop to ensure any uncaught exceptions are
89-
// forwarded to the event loop handler before the test ends.
90-
$deferred = new DeferredFuture();
91-
EventLoop::defer(static fn () => $deferred->complete());
92-
$deferred->getFuture()->await();
93-
94-
return $result;
95-
} finally {
96-
if (!$this->deferredFuture->isComplete()) {
97-
$this->deferredFuture->complete();
98-
}
70+
[, $returnValue] = all([
71+
$this->deferredFuture->getFuture(),
72+
async(function () use ($args): mixed {
73+
try {
74+
$result = ([$this, $this->realTestName])(...$args);
75+
if ($result instanceof Future) {
76+
$result = $result->await();
9977
}
100-
}),
101-
]);
102-
} finally {
103-
$this->cleanup();
104-
}
78+
79+
// Force an extra tick of the event loop to ensure any uncaught exceptions are
80+
// forwarded to the event loop handler before the test ends.
81+
$deferred = new DeferredFuture();
82+
EventLoop::defer(static fn () => $deferred->complete());
83+
$deferred->getFuture()->await();
84+
85+
return $result;
86+
} finally {
87+
if (!$this->deferredFuture->isComplete()) {
88+
$this->deferredFuture->complete();
89+
}
90+
}
91+
}),
92+
]);
10593
} finally {
10694
if (isset($this->timeoutId)) {
10795
EventLoop::cancel($this->timeoutId);

test/AsyncTestCaseTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515

1616
class AsyncTestCaseTest extends AsyncTestCase
1717
{
18-
public function cleanup(): void
19-
{
20-
parent::cleanup();
21-
22-
if ($this->getName() === 'testCleanupInvoked') {
23-
$exception = new TestException;
24-
$this->expectExceptionObject($exception);
25-
throw $exception;
26-
}
27-
}
28-
2918
public function testThatMethodRunsInEventLoopContext(): Future
3019
{
3120
$returnDeferred = new DeferredFuture; // make sure our test runs to completion
@@ -192,9 +181,4 @@ public function testThrowToEventLoop(): void
192181

193182
(new DeferredFuture)->getFuture()->await();
194183
}
195-
196-
public function testCleanupInvoked(): void
197-
{
198-
// Exception thrown in cleanup() to assert method is invoked.
199-
}
200184
}

0 commit comments

Comments
 (0)