Przeglądaj źródła

ZF-11281
Zend_Rest_Client_Result::getStatus should check to ensure result has at least one status element
Not doing so raises a PHP error


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23884 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan 14 lat temu
rodzic
commit
e38e900c20

+ 2 - 1
library/Zend/Rest/Client/Result.php

@@ -180,7 +180,8 @@ class Zend_Rest_Client_Result implements IteratorAggregate {
     public function getStatus()
     {
         $status = $this->_sxml->xpath('//status/text()');
-
+        if ( !isset($status[0]) ) return false;
+        
         $status = strtolower($status[0]);
 
         if (ctype_alpha($status) && $status == 'success') {

+ 23 - 0
tests/Zend/Rest/ClientTest.php

@@ -297,4 +297,27 @@ class Zend_Rest_ClientTest extends PHPUnit_Framework_TestCase
 
         }
     }
+    
+    /**
+     * @group ZF-11281
+     */
+    public function testCallStatusGetterOnResponseObjectWhenServerResponseHasNoStatusXmlElement()
+    {
+        $expXml   = file_get_contents($this->path . 'returnEmptyStatus.xml');
+        $response = "HTTP/1.0 200 OK\r\n"
+                  . "X-powered-by: PHP/5.2.0\r\n"
+                  . "Content-type: text/xml\r\n"
+                  . "Content-length: " . strlen($expXml) . "\r\n"
+                  . "Server: Apache/1.3.34 (Unix) PHP/5.2.0)\r\n"
+                  . "Date: Tue, 06 Feb 2007 15:01:47 GMT\r\n"
+                  . "Connection: close\r\n"
+                  . "\r\n"
+                  . $expXml;
+        $this->adapter->setResponse($response);
+
+        $response = $this->rest->get('/rest/');
+        $this->assertTrue($response instanceof Zend_Rest_Client_Result);
+        $this->assertFalse($response->getStatus());
+    }
+
 }