Skip to content

fix: preserve enclosing stream filter when using MockInputOutput#10307

Merged
paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:mock-io-filter-restore
Jun 12, 2026
Merged

fix: preserve enclosing stream filter when using MockInputOutput#10307
paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:mock-io-filter-restore

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description

When a test uses MockInputOutput while it (or its base) also uses StreamFilterTrait, the mock's internal addStreamFilters() / removeStreamFilters() calls tore down the trait's STDOUT/STDERR filters and left them removed. Any CLI output produced after the MockInputOutput interaction (for example in tearDown()) then bypassed capture and leaked to the console.

MockInputOutput now snapshots the shared CITestStreamFilter state (filter presence and buffer) before attaching its own filters and restores it afterward, so an enclosing StreamFilterTrait keeps capturing once the mock is done. Adds CITestStreamFilter::hasOutputFilter() / hasErrorFilter() accessors and a regression test covering both the fwrite and input paths.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@paulbalandan paulbalandan added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 12, 2026
@paulbalandan paulbalandan merged commit bce872b into codeigniter4:develop Jun 12, 2026
57 checks passed
@paulbalandan paulbalandan deleted the mock-io-filter-restore branch June 12, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants