Issues (323)

tests/05LoggerTest.php (1 issue)

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
use PhpXmlRpc\Value;
9
10
class LoggerTest extends PhpXmlRpc_PolyfillTestCase
11
{
12
    protected $debugBuffer = '';
13
    protected $errorBuffer = '';
14
    protected $warningBuffer = '';
15
16
    protected function set_up()
17
    {
18
        $this->debugBuffer = '';
19
        $this->errorBuffer = '';
20
        $this->warningBuffer = '';
21
    }
22
23
    public function testCharsetAltLogger()
24
    {
25
        $ch = Charset::instance();
26
        $l = $ch->getLogger();
27
        Charset::setLogger($this);
28
29
        ob_start();
30
        $ch->encodeEntities('hello world', 'UTF-8', 'NOT-A-CHARSET');
31
        $o = ob_get_clean();
32
        $this->assertEquals('', $o);
33
        $this->assertStringContainsString("via mbstring: failed", $this->errorBuffer);
34
35
        Charset::setLogger($l);
36
    }
37
38
    public function testHttpAltLogger()
39
    {
40
        $h = new Http();
41
        $l = $h->getLogger();
42
        Http::setLogger($this);
43
44
        $s = "HTTP/1.0 200 OK\r\n" .
45
            "Content-Type: unknown\r\n" .
46
            "\r\n" .
47
            "body";
48
        ob_start();
49
        $h->parseResponseHeaders($s, false, 1);
50
        $o = ob_get_clean();
51
        $this->assertEquals('', $o);
52
        $this->assertStringContainsString("HEADER: content-type: unknown", $this->debugBuffer);
53
        Http::setLogger($l);
54
    }
55
56
    public function testXPAltLogger()
57
    {
58
        $xp = new XMLParser();
59
        $l = $xp->getLogger();
60
        XMLParser::setLogger($this);
61
62
        ob_start();
63
        $xp->parse('<?xml version="1.0" ?><methodResponse><params><param><value><boolean>x</boolean></value></param></params></methodResponse>');
64
        $o = ob_get_clean();
65
        $this->assertEquals('', $o);
66
        $this->assertStringContainsString("invalid data received in BOOLEAN value", $this->errorBuffer);
67
68
        XMLParser::setLogger($l);
69
    }
70
71
    public function testDeprecations()
72
    {
73
        $v = new Value(array(), Value::$xmlrpcStruct);
74
        $l = $v->getLogger();
75
        Value::setLogger($this);
76
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_silence_deprecations = false;
77
        $c = $v->structSize();
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Value::structSize() has been deprecated: use count() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

77
        $c = /** @scrutinizer ignore-deprecated */ $v->structSize();

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.

Loading history...
78
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_silence_deprecations = true;
79
        Value::setLogger($l);
80
        $this->assertStringContainsString("Method PhpXmlRpc\Value::structSize is deprecated", $this->warningBuffer);
81
    }
82
83
    // logger API
84
85
    public function debug($message, $context = array())
86
    {
87
        $this->debugBuffer .= $message;
88
    }
89
90
    public function error($message, $context = array())
91
    {
92
        $this->errorBuffer .= $message;
93
    }
94
95
    public function warning($message, $context = array())
96
    {
97
        $this->warningBuffer .= $message;
98
    }
99
}
100