Skip to content

Make CITestStreamFilter compatible with php_user_filter #5014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions system/Test/Filters/CITestStreamFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use php_user_filter;

/**
* Class to extract an output snapshot.
* Used to capture output during unit testing, so that it can
* be used in assertions.
*/
Expand All @@ -28,28 +27,24 @@ class CITestStreamFilter extends php_user_filter
public static $buffer = '';

/**
* Output filtering - catch it all.
* This method is called whenever data is read from or written to the
* attached stream (such as with fread() or fwrite()).
*
* @param resource $in
* @param resource $out
* @param int $consumed
* @param bool $closing
*
* @return int
*/
public function filter($in, $out, &$consumed, $closing)
public function filter($in, $out, &$consumed, $closing): int
{
while ($bucket = stream_bucket_make_writeable($in)) {
static::$buffer .= $bucket->data;

$consumed += $bucket->datalen;
}

// @phpstan-ignore-next-line
return PSFS_PASS_ON;
}
}

// @codeCoverageIgnoreStart
stream_filter_register('CITestStreamFilter', 'CodeIgniter\Test\Filters\CITestStreamFilter');
// @codeCoverageIgnoreEnd
stream_filter_register('CITestStreamFilter', CITestStreamFilter::class); // @codeCoverageIgnore