2018-08-17 21:41:46 +02:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2024-01-02 21:57:26 +01:00
|
|
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
2020-02-09 15:45:36 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-08-17 21:41:46 +02:00
|
|
|
|
|
|
|
namespace Friendica\Test\Util;
|
|
|
|
|
|
|
|
use php_user_filter;
|
|
|
|
|
|
|
|
/**
|
2023-03-22 05:07:55 +01:00
|
|
|
* Output Interceptor for STDOUT to prevent outputting to the console
|
2018-08-17 21:41:46 +02:00
|
|
|
* Instead the $cache variable will get filled with the output
|
|
|
|
*
|
|
|
|
* @package Friendica\Test\Util
|
|
|
|
*/
|
|
|
|
class Intercept extends php_user_filter
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string The cache which holds the current output of STDOUT
|
|
|
|
*/
|
|
|
|
public static $cache = '';
|
|
|
|
|
2020-10-18 20:31:57 +02:00
|
|
|
/** @noinspection PhpMissingParentCallCommonInspection */
|
2023-07-05 22:20:52 +02:00
|
|
|
public function filter($in, $out, &$consumed, $closing): int
|
2018-08-17 21:41:46 +02:00
|
|
|
{
|
|
|
|
while ($bucket = stream_bucket_make_writeable($in)) {
|
|
|
|
self::$cache .= $bucket->data;
|
|
|
|
$consumed += $bucket->datalen;
|
|
|
|
stream_bucket_append($out, $bucket);
|
|
|
|
}
|
|
|
|
return PSFS_FEED_ME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the interceptor and prevents therefore the output to STDOUT
|
|
|
|
*/
|
|
|
|
public static function setUp() {
|
|
|
|
stream_filter_register("intercept", Intercept::class);
|
|
|
|
stream_filter_append(STDOUT, "intercept");
|
|
|
|
stream_filter_append(STDERR, "intercept");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the cache
|
|
|
|
*/
|
|
|
|
public static function reset() {
|
|
|
|
self::$cache = '';
|
|
|
|
}
|
|
|
|
}
|