Skip to content

Commit 3341b14

Browse files
committed
feat: Melhorar controle de buffer de saída nos testes para garantir isolamento e consistência
1 parent 7534d04 commit 3341b14

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/TestCase.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ abstract class TestCase extends BaseTestCase
2323
protected ServerRequestFactory $serverRequestFactory;
2424
protected StreamFactory $streamFactory;
2525
protected UriFactory $uriFactory;
26+
private int $initialBufferLevel;
2627

2728
protected function setUp(): void
2829
{
@@ -91,10 +92,12 @@ private function configureTestOutputControl(): void
9192
define('PHPUNIT_TESTSUITE', true);
9293
}
9394

94-
// Start output buffering to capture any unexpected output
95-
if (ob_get_level() === 0) {
96-
ob_start();
97-
}
95+
// Store the initial buffer level to track how many buffers we add
96+
$this->initialBufferLevel = ob_get_level();
97+
98+
// Always start a new output buffer for test isolation
99+
// This ensures consistent behavior regardless of existing buffers
100+
ob_start();
98101
}
99102

100103
/**
@@ -118,7 +121,8 @@ protected function createTestResponse(): \PivotPHP\Core\Http\Response
118121
*/
119122
private function cleanOutputBuffer(): void
120123
{
121-
while (ob_get_level() > 0) {
124+
// Only clean buffers that we started, maintaining the original buffer level
125+
while (ob_get_level() > $this->initialBufferLevel) {
122126
ob_end_clean();
123127
}
124128
}

0 commit comments

Comments
 (0)