Просмотр исходного кода

Fixes #32 - Zend_Soap_Client has no exceptions flag

Frank Brückner 11 лет назад
Родитель
Сommit
1a065a870c
2 измененных файлов с 75 добавлено и 1 удалено
  1. 39 1
      library/Zend/Soap/Client.php
  2. 36 0
      tests/Zend/Soap/ClientTest.php

+ 39 - 1
library/Zend/Soap/Client.php

@@ -89,6 +89,7 @@ class Zend_Soap_Client
     protected $_features            = null;
     protected $_cache_wsdl          = null;
     protected $_user_agent          = null;
+    protected $_exceptions          = null;
 
     /**
      * WSDL used to access server
@@ -268,6 +269,9 @@ class Zend_Soap_Client
                 case 'user_agent':
                     $this->setUserAgent($value);
                     break;
+                case 'exceptions':
+                    $this->setExceptions($value);
+                    break;
 
                 // Not used now
                 // case 'connection_timeout':
@@ -315,13 +319,14 @@ class Zend_Soap_Client
         $options['cache_wsdl']     = $this->getWsdlCache();
         $options['features']       = $this->getSoapFeatures();
         $options['user_agent']     = $this->getUserAgent();
+        $options['exceptions']     = $this->getExceptions();
 
         foreach ($options as $key => $value) {
             /*
              * ugly hack as I don't know if checking for '=== null'
              * breaks some other option
              */
-            if (in_array($key, array('user_agent', 'cache_wsdl', 'compression'))) {
+            if (in_array($key, array('user_agent', 'cache_wsdl', 'compression', 'exceptions'))) {
                 if ($value === null) {
                     unset($options[$key]);
                 }
@@ -909,6 +914,39 @@ class Zend_Soap_Client
     }
 
     /**
+     * Set the exceptions option
+     *
+     * The exceptions option is a boolean value defining whether soap errors
+     * throw exceptions.
+     *
+     * @see http://php.net/manual/soapclient.soapclient.php#refsect1-soapclient.soapclient-parameters
+     *
+     * @param bool $exceptions
+     * @return $this
+     */
+    public function setExceptions($exceptions)
+    {
+        $this->_exceptions = (bool) $exceptions;
+
+        return $this;
+    }
+
+    /**
+     * Get the exceptions option
+     *
+     * The exceptions option is a boolean value defining whether soap errors
+     * throw exceptions.
+     *
+     * @see http://php.net/manual/soapclient.soapclient.php#refsect1-soapclient.soapclient-parameters
+     *
+     * @return bool|null
+     */
+    public function getExceptions()
+    {
+        return $this->_exceptions;
+    }
+
+    /**
      * Retrieve request XML
      *
      * @return string

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

@@ -260,6 +260,42 @@ class Zend_Soap_ClientTest extends PHPUnit_Framework_TestCase
         $this->assertArrayNotHasKey('compression', $options);
     }
 
+    /**
+     * @group GH-32
+     */
+    public function testGetAndSetExceptionsOption()
+    {
+        $client = new Zend_Soap_Client();
+        $this->assertNull($client->getExceptions());
+        $this->assertEquals(
+            array(
+                'encoding'     => 'UTF-8',
+                'soap_version' => 2,
+            ),
+            $client->getOptions()
+        );
+
+        $client->setExceptions(true);
+        $this->assertTrue($client->getExceptions());
+
+        $client->setExceptions(false);
+        $this->assertFalse($client->getExceptions());
+
+        $client->setOptions(array('exceptions' => true));
+        $this->assertTrue($client->getExceptions());
+
+        $client = new Zend_Soap_Client(null, array('exceptions' => false));
+        $this->assertFalse($client->getExceptions());
+        $this->assertEquals(
+            array(
+                'encoding'     => 'UTF-8',
+                'soap_version' => 2,
+                'exceptions'   => false,
+            ),
+            $client->getOptions()
+        );
+    }
+
     public function testGetFunctions()
     {
         $server = new Zend_Soap_Server(dirname(__FILE__) . '/_files/wsdl_example.wsdl');