summaryrefslogtreecommitdiff
path: root/ext/standard/tests/filters/filter_errors.inc
blob: 6d1a270c82e0c195d2aa84e9fb6a9b5be1502a1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

function filter_errors_skipif($needle) {
	if (!function_exists('fnmatch')) {
		die('skip fnmatch() not available');
	}
	$filters = stream_get_filters();
	foreach($filters as $filter) {
		if (fnmatch($filter, $needle)) return;
	}
	die("skip $needle not available");
}

function filter_errors_test($filter, $data) {

	echo "test filtering of buffered data\n";

	$stream = fopen('php://memory', 'wb+');

	fwrite($stream, ".\r\n$data");
	fseek($stream, 0, SEEK_SET);
	stream_get_line($stream, 8192, "\r\n");

	$f = stream_filter_append($stream, $filter);

	echo "test filtering of non buffered data\n";

	$stream = fopen('php://memory', 'wb+');

	fwrite($stream, "$data");
	fseek($stream, 0, SEEK_SET);

	stream_filter_append($stream, $filter);
	stream_get_contents($stream);

}