File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments