Ver código fonte

ZF-6955 - Added missing Zend_Soap_Client::setCookie method which proxies to SoapClient

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15994 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 16 anos atrás
pai
commit
d147800131
2 arquivos alterados com 67 adições e 10 exclusões
  1. 38 10
      library/Zend/Soap/Client.php
  2. 29 0
      tests/Zend/Soap/ClientTest.php

+ 38 - 10
library/Zend/Soap/Client.php

@@ -814,6 +814,8 @@ class Zend_Soap_Client
     public function setSoapFeatures($feature)
     {
         $this->_features = $feature;
+
+        $this->_soapClient = null;
         return $this;
     }
 
@@ -1048,14 +1050,12 @@ class Zend_Soap_Client
      */
     public function __call($name, $arguments)
     {
-        if ($this->_soapClient == null) {
-            $this->_initSoapClientObject();
-        }
+        $soapClient = $this->getSoapClient();
 
         $this->_lastMethod = $name;
 
         $soapHeaders = array_merge($this->_permanentSoapInputHeaders, $this->_soapInputHeaders);
-        $result = $this->_soapClient->__soapCall($name,
+        $result = $soapClient->__soapCall($name,
                                                  $this->_preProcessArguments($arguments),
                                                  null, /* Options are already set to the SOAP client object */
                                                  (count($soapHeaders) > 0)? $soapHeaders : null,
@@ -1081,11 +1081,8 @@ class Zend_Soap_Client
             throw new Zend_Soap_Client_Exception('\'getFunctions\' method is available only in WSDL mode.');
         }
 
-        if ($this->_soapClient == null) {
-            $this->_initSoapClientObject();
-        }
-
-        return $this->_soapClient->__getFunctions();
+        $soapClient = $this->getSoapClient();
+        return $soapClient->__getFunctions();
     }
 
 
@@ -1108,10 +1105,41 @@ class Zend_Soap_Client
             throw new Zend_Soap_Client_Exception('\'getTypes\' method is available only in WSDL mode.');
         }
 
+        $soapClient = $this->getSoapClient();
+
+        return $soapClient->__getTypes();
+    }
+
+    /**
+     * @param SoapClient $soapClient
+     * @return Zend_Soap_Client
+     */
+    public function setSoapClient(SoapClient $soapClient)
+    {
+        $this->_soapClient = $soapClient;
+        return $this;
+    }
+
+    /**
+     * @return SoapClient
+     */
+    public function getSoapClient()
+    {
         if ($this->_soapClient == null) {
             $this->_initSoapClientObject();
         }
+        return $this->_soapClient;
+    }
 
-        return $this->_soapClient->__getTypes();
+    /**
+     * @param string $name
+     * @param string $value
+     * @return Zend_Soap_Client
+     */
+    public function setCookie($cookieName, $cookieValue=null)
+    {
+        $soapClient = $this->getSoapClient();
+        $soapClient->__setCookie($cookieName, $cookieValue);
+        return $this;
     }
 }

+ 29 - 0
tests/Zend/Soap/ClientTest.php

@@ -362,6 +362,35 @@ class Zend_Soap_ClientTest extends PHPUnit_Framework_TestCase
 
         $this->assertEquals($client->getLastRequest(), $expectedRequest);
     }
+
+    /**
+     * @group ZF-6955
+     */
+    public function testSetCookieIsDelegatedToSoapClient()
+    {
+        $fixtureCookieKey = "foo";
+        $fixtureCookieValue = "bar";
+
+        $clientMock = $this->getMock('SoapClient', array('__setCookie'), array(null, array('uri' => 'http://www.zend.com', 'location' => 'http://www.zend.com')));
+        $clientMock->expects($this->once())
+                   ->method('__setCookie')
+                   ->with($fixtureCookieKey, $fixtureCookieValue);
+
+        $soap = new Zend_Soap_Client();
+        $soap->setSoapClient($clientMock);
+
+        $soap->setCookie($fixtureCookieKey, $fixtureCookieValue);
+    }
+
+    public function testSetSoapClient()
+    {
+        $clientMock = $this->getMock('SoapClient', array('__setCookie'), array(null, array('uri' => 'http://www.zend.com', 'location' => 'http://www.zend.com')));
+
+        $soap = new Zend_Soap_Client();
+        $soap->setSoapClient($clientMock);
+
+        $this->assertSame($clientMock, $soap->getSoapClient());
+    }
 }