LoggerTest::testHttpAltLogger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 16
rs 9.8333
c 0
b 0
f 0
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
Bug introduced by
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
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
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

76
        $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...
Unused Code introduced by
The assignment to $c is dead and can be removed.
Loading history...
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())
0 ignored issues
show
Unused Code introduced by
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

84
    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...
85
    {
86
        $this->debugBuffer .= $message;
87
    }
88
89
    public function error($message, $context = array())
0 ignored issues
show
Unused Code introduced by
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

89
    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...
90
    {
91
        $this->errorBuffer .= $message;
92
    }
93
94
    public function warning($message, $context = array())
0 ignored issues
show
Unused Code introduced by
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

94
    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...
95
    {
96
        $this->warningBuffer .= $message;
97
    }
98
}
99