gggeek /
phpxmlrpc
| 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
|
|||
| 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(); |
||
| 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 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: