فهرست منبع

Suppress SimpleXmlElement warning (ZF-9039)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21359 44c647ce-9c0f-0410-b52a-842ac1e357ba
lars 16 سال پیش
والد
کامیت
6696076f8c
2فایلهای تغییر یافته به همراه26 افزوده شده و 0 حذف شده
  1. 3 0
      library/Zend/XmlRpc/Response.php
  2. 23 0
      tests/Zend/XmlRpc/ResponseTest.php

+ 3 - 0
library/Zend/XmlRpc/Response.php

@@ -177,8 +177,11 @@ class Zend_XmlRpc_Response
         }
         }
 
 
         try {
         try {
+            $useInternalXmlErrors = libxml_use_internal_errors(true);
             $xml = new SimpleXMLElement($response);
             $xml = new SimpleXMLElement($response);
+            libxml_use_internal_errors($useInternalXmlErrors);
         } catch (Exception $e) {
         } catch (Exception $e) {
+            libxml_use_internal_errors($useInternalXmlErrors);
             // Not valid XML
             // Not valid XML
             $this->_fault = new Zend_XmlRpc_Fault(651);
             $this->_fault = new Zend_XmlRpc_Fault(651);
             $this->_fault->setEncoding($this->getEncoding());
             $this->_fault->setEncoding($this->getEncoding());

+ 23 - 0
tests/Zend/XmlRpc/ResponseTest.php

@@ -44,6 +44,11 @@ class Zend_XmlRpc_ResponseTest extends PHPUnit_Framework_TestCase
     protected $_response;
     protected $_response;
 
 
     /**
     /**
+     * @var bool
+     */
+    protected $_errorOccured = false;
+
+    /**
      * Setup environment
      * Setup environment
      */
      */
     public function setUp()
     public function setUp()
@@ -137,6 +142,19 @@ class Zend_XmlRpc_ResponseTest extends PHPUnit_Framework_TestCase
     }
     }
 
 
     /**
     /**
+     * @group ZF-9039
+     */
+    public function testExceptionIsThrownWhenInvalidXmlIsReturnedByServer()
+    {
+        set_error_handler(array($this, 'handleError'));
+        $invalidResponse = 'foo';
+        $response = new Zend_XmlRpc_Response();
+        $this->assertFalse($this->_errorOccured);
+        $this->assertFalse($response->loadXml($invalidResponse));
+        $this->assertFalse($this->_errorOccured);
+    }
+
+    /**
      * @group ZF-5404
      * @group ZF-5404
      */
      */
     public function testNilResponseFromXmlRpcServer()
     public function testNilResponseFromXmlRpcServer()
@@ -232,4 +250,9 @@ EOD;
         } catch (Exception $e) {
         } catch (Exception $e) {
         }
         }
     }
     }
+
+    public function handleError($error)
+    {
+        $this->_errorOccured = true;
+    }
 }
 }