Issues (323)

tests/05LoggerTest.php (6 issues)

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;
0 ignored issues
show
This use statement conflicts with another class in this namespace, XMLParser. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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
The assignment to $c is dead and can be removed.
Loading history...
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())
0 ignored issues
show
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

85
    public function debug($message, /** @scrutinizer ignore-unused */ $context = array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
    {
87
        $this->debugBuffer .= $message;
88
    }
89
90
    public function error($message, $context = array())
0 ignored issues
show
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

90
    public function error($message, /** @scrutinizer ignore-unused */ $context = array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
    {
92
        $this->errorBuffer .= $message;
93
    }
94
95
    public function warning($message, $context = array())
0 ignored issues
show
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

95
    public function warning($message, /** @scrutinizer ignore-unused */ $context = array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        $this->warningBuffer .= $message;
98
    }
99
}
100