1 | <?php |
||
2 | |||
3 | include_once __DIR__ . '/PolyfillTestCase.php'; |
||
4 | |||
5 | use PhpXmlRpc\Helper\Charset; |
||
6 | use PhpXmlRpc\Helper\Http; |
||
7 | use PhpXmlRpc\Helper\XMLParser; |
||
8 | |||
9 | class LoggerTest extends PhpXmlRpc_PolyfillTestCase |
||
10 | { |
||
11 | protected $debugBuffer = ''; |
||
12 | protected $errorBuffer = ''; |
||
13 | protected $warningBuffer = ''; |
||
14 | |||
15 | protected function set_up() |
||
16 | { |
||
17 | $this->debugBuffer = ''; |
||
18 | $this->errorBuffer = ''; |
||
19 | $this->warningBuffer = ''; |
||
20 | } |
||
21 | |||
22 | public function testCharsetAltLogger() |
||
23 | { |
||
24 | $ch = Charset::instance(); |
||
25 | $l = $ch->getLogger(); |
||
26 | Charset::setLogger($this); |
||
27 | |||
28 | ob_start(); |
||
29 | $ch->encodeEntities('hello world', 'UTF-8', 'NOT-A-CHARSET'); |
||
30 | $o = ob_get_clean(); |
||
31 | $this->assertEquals('', $o); |
||
32 | $this->assertStringContainsString("via mbstring: failed", $this->errorBuffer); |
||
33 | |||
34 | Charset::setLogger($l); |
||
35 | } |
||
36 | |||
37 | public function testHttpAltLogger() |
||
38 | { |
||
39 | $h = new Http(); |
||
40 | $l = $h->getLogger(); |
||
41 | Http::setLogger($this); |
||
42 | |||
43 | $s = "HTTP/1.0 200 OK\r\n" . |
||
44 | "Content-Type: unknown\r\n" . |
||
45 | "\r\n" . |
||
46 | "body"; |
||
47 | ob_start(); |
||
48 | $h->parseResponseHeaders($s, false, 1); |
||
49 | $o = ob_get_clean(); |
||
50 | $this->assertEquals('', $o); |
||
51 | $this->assertStringContainsString("HEADER: content-type: unknown", $this->debugBuffer); |
||
52 | Http::setLogger($l); |
||
53 | } |
||
54 | |||
55 | public function testXPAltLogger() |
||
56 | { |
||
57 | $xp = new XMLParser(); |
||
58 | $l = $xp->getLogger(); |
||
59 | XMLParser::setLogger($this); |
||
60 | |||
61 | ob_start(); |
||
62 | $xp->parse('<?xml version="1.0" ?><methodResponse><params><param><value><boolean>x</boolean></value></param></params></methodResponse>'); |
||
63 | $o = ob_get_clean(); |
||
64 | $this->assertEquals('', $o); |
||
65 | $this->assertStringContainsString("invalid data received in BOOLEAN value", $this->errorBuffer); |
||
66 | |||
67 | XMLParser::setLogger($l); |
||
68 | } |
||
69 | |||
70 | public function testDeprecations() |
||
71 | { |
||
72 | $v = new \PhpXmlRpc\Value(array(), \PhpXmlRpc\Value::$xmlrpcStruct); |
||
73 | $l = $v->getLogger(); |
||
74 | \PhpXmlRpc\Value::setLogger($this); |
||
75 | \PhpXmlRpc\PhpXmlRpc::$xmlrpc_silence_deprecations = false; |
||
76 | $c = $v->structSize(); |
||
0 ignored issues
–
show
|
|||
77 | \PhpXmlRpc\PhpXmlRpc::$xmlrpc_silence_deprecations = true; |
||
78 | \PhpXmlRpc\Value::setLogger($l); |
||
79 | $this->assertStringContainsString("Method PhpXmlRpc\Value::structSize is deprecated", $this->warningBuffer); |
||
80 | } |
||
81 | |||
82 | // logger API |
||
83 | |||
84 | public function debug($message, $context = array()) |
||
85 | { |
||
86 | $this->debugBuffer .= $message; |
||
87 | } |
||
88 | |||
89 | public function error($message, $context = array()) |
||
90 | { |
||
91 | $this->errorBuffer .= $message; |
||
92 | } |
||
93 | |||
94 | public function warning($message, $context = array()) |
||
95 | { |
||
96 | $this->warningBuffer .= $message; |
||
97 | } |
||
98 | } |
||
99 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.