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
|
|
|
|
14
|
|
|
protected function set_up() |
15
|
|
|
{ |
16
|
|
|
$this->debugBuffer = ''; |
17
|
|
|
$this->errorBuffer = ''; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testCharsetAltLogger() |
21
|
|
|
{ |
22
|
|
|
$ch = Charset::instance(); |
23
|
|
|
$l = $ch->getLogger(); |
24
|
|
|
Charset::setLogger($this); |
25
|
|
|
|
26
|
|
|
// silence the mbstring warning |
27
|
|
|
$ch->encodeEntities('hello world', 'UTF-8', 'NOT-A-CHARSET'); |
28
|
|
|
$this->assertStringContainsString("via mbstring: failed", $this->errorBuffer); |
29
|
|
|
|
30
|
|
|
Charset::setLogger($l); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testHttpAltLogger() |
34
|
|
|
{ |
35
|
|
|
$l = Http::getLogger(); |
36
|
|
|
Http::setLogger($this); |
37
|
|
|
|
38
|
|
|
$h = new Http(); |
39
|
|
|
$s = "HTTP/1.0 200 OK\r\n" . |
40
|
|
|
"Content-Type: unknown\r\n" . |
41
|
|
|
"\r\n" . |
42
|
|
|
"body"; |
43
|
|
|
$h->parseResponseHeaders($s, false, 1); |
44
|
|
|
$this->assertStringContainsString("HEADER: content-type: unknown", $this->debugBuffer); |
45
|
|
|
Http::setLogger($l); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testXPAltLogger() |
49
|
|
|
{ |
50
|
|
|
$xp = new XMLParser(); |
51
|
|
|
$l = $xp->getLogger(); |
52
|
|
|
XMLParser::setLogger($this); |
53
|
|
|
|
54
|
|
|
$xp->parse('<?xml version="1.0" ?><methodResponse><params><param><value><boolean> 1 </boolean></value></param></params></methodResponse>'); |
55
|
|
|
$this->assertStringContainsString("invalid data received in BOOLEAN value", $this->errorBuffer); |
56
|
|
|
|
57
|
|
|
XMLParser::setLogger($l); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// logger API |
61
|
|
|
|
62
|
|
|
public function debugMessage($message, $encoding = null) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
$this->debugBuffer .= $message; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function errorLog($message) |
68
|
|
|
{ |
69
|
|
|
$this->errorBuffer .= $message; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/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 beforeOtherDir/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: