diff --git a/tests/TestCase.php b/tests/TestCase.php index dac81e1..d9b42d1 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,6 +8,14 @@ abstract class TestCase extends BaseTestCase { use CreatesApplication; + /** Output-buffer depth captured before each test, so tearDown can + * rewind back to it instead of leaving dangling buffers that PHPUnit + * reports as "Test code or tested code did not close its own output + * buffers". The depth leaks when a view throws mid-render — common + * with Blade's compiled files when a feature test exercises an + * error path. */ + private int $preTestObLevel = 0; + /** * Belt-and-braces guard against a repeat of the 2026-10-21 incident, where * a test with the RefreshDatabase trait ran migrate:fresh against the @@ -21,6 +29,20 @@ abstract class TestCase extends BaseTestCase { parent::setUp(); $this->assertSafeTestDatabase(); + $this->preTestObLevel = ob_get_level(); + } + + protected function tearDown(): void + { + // Collapse any output buffers the test (or Blade view it rendered) + // left open. Without this, each view()->render() call that touches + // a Blade partial with its own @once / @push block can leave the + // buffer stack one level deep — PHPUnit reports every one of those + // tests as "risky". + while (ob_get_level() > $this->preTestObLevel) { + ob_end_clean(); + } + parent::tearDown(); } private function assertSafeTestDatabase(): void