Skip to content

Commit 7df8633

Browse files
Copilotsamdark
andauthored
Use ReflectionProperty for stack reset in tearDown and add thread-safety note
Agent-Logs-Url: https://github.com/yiisoft/html/sessions/b46b1e7f-121d-4291-8e33-7a1403732003 Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
1 parent 91805de commit 7df8633

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/Tag/Form.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ final class Form extends NormalTag
2222

2323
/**
2424
* @var static[]
25+
*
26+
* @note This static stack is process-scoped. In long-running PHP runtimes
27+
* (e.g. Swoole, RoadRunner) each coroutine or request shares the same
28+
* static property. Ensure {@see begin()} and {@see end()} are always
29+
* paired within the same request/coroutine context.
2530
*/
2631
private static array $stack = [];
2732

tests/Tag/FormTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ final class FormTest extends TestCase
1515
{
1616
protected function tearDown(): void
1717
{
18-
// Drain any Form::begin() calls that were not matched with Form::end()
19-
// to ensure a clean static stack between tests.
20-
try {
21-
while (true) {
22-
Form::end();
23-
}
24-
} catch (\RuntimeException) {
25-
// Stack is now empty.
26-
}
18+
// Reset the static stack to ensure test isolation.
19+
$ref = new \ReflectionProperty(Form::class, 'stack');
20+
$ref->setAccessible(true);
21+
$ref->setValue(null, []);
2722
}
2823

2924
public function testBase(): void

0 commit comments

Comments
 (0)