3 namespace Friendica\Test\Util;
8 * Output Interceptor for STDOUT to prevent outputing to the console
9 * Instead the $cache variable will get filled with the output
11 * @package Friendica\Test\Util
13 class Intercept extends php_user_filter
16 * @var string The cache which holds the current output of STDOUT
18 public static $cache = '';
20 public function filter($in, $out, &$consumed, $closing)
22 while ($bucket = stream_bucket_make_writeable($in)) {
23 self::$cache .= $bucket->data;
24 $consumed += $bucket->datalen;
25 stream_bucket_append($out, $bucket);
31 * Registers the interceptor and prevents therefore the output to STDOUT
33 public static function setUp() {
34 stream_filter_register("intercept", Intercept::class);
35 stream_filter_append(STDOUT, "intercept");
36 stream_filter_append(STDERR, "intercept");
42 public static function reset() {