Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/soap' of https://github.com/sasezaki/zf2 into ho…
Browse files Browse the repository at this point in the history
…tfix/soap
  • Loading branch information
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 25 deletions.
31 changes: 25 additions & 6 deletions src/AutoDiscover.php
Expand Up @@ -108,21 +108,21 @@ public function __construct($strategy = true, $uri=null, $wsdlClass=null)
/**
* Set the location at which the WSDL file will be availabe.
*
* @throws \Zend\Soap\AutoDiscover\Exception
* @param Uri\Uri|string $uri
* @return \Zend\Soap\AutoDiscover
* @throws \Zend\Soap\Exception\InvalidArgumentException
*/
public function setUri($uri)
{
if(!is_string($uri) && !($uri instanceof Uri\Uri)) {
if (!is_string($uri) && !($uri instanceof Uri\Uri)) {
throw new Exception\InvalidArgumentException(
'No uri given to \Zend\Soap\AutoDiscover::setUri as string or \Zend\Uri\Uri instance.'
);
}
$this->_uri = $uri;

// change uri in WSDL file also if existant
if($this->_wsdl instanceof Wsdl) {
if ($this->_wsdl instanceof Wsdl) {
$this->_wsdl->setUri($uri);
}

Expand Down Expand Up @@ -151,13 +151,13 @@ public function getUri()
/**
* Set the name of the WSDL handling class.
*
* @throws \Zend\Soap\AutoDiscover\Exception
* @param string $wsdlClass
* @return \Zend\Soap\AutoDiscover
* @throws \Zend\Soap\Exception\InvalidArgumentException
*/
public function setWsdlClass($wsdlClass)
{
if(!is_string($wsdlClass) && !is_subclass_of($wsdlClass, 'Zend\Soap\Wsdl')) {
if (!is_string($wsdlClass) && !is_subclass_of($wsdlClass, 'Zend\Soap\Wsdl')) {
throw new Exception\InvalidArgumentException(
'No \Zend\Soap\Wsdl subclass given to Zend\Soap\AutoDiscover::setWsdlClass as string.'
);
Expand Down Expand Up @@ -185,6 +185,7 @@ public function getWsdlClass()
*
* @param array $operationStyle
* @return \Zend\Soap\AutoDiscover
* @throws \Zend\Soap\Exception\InvalidArgumentException
*/
public function setOperationBodyStyle(array $operationStyle=array())
{
Expand Down Expand Up @@ -288,6 +289,7 @@ public function setComplexTypeStrategy($strategy)
* @param string $class Class Name
* @param string $namespace Class Namspace - Not Used
* @param array $argv Arguments to instantiate the class - Not Used
* @return \Zend\Soap\AutoDiscover
*/
public function setClass($class, $namespace = '', $argv = null)
{
Expand All @@ -311,13 +313,16 @@ public function setClass($class, $namespace = '', $argv = null)
$this->_addFunctionToWsdl($method, $wsdl, $port, $binding);
}
$this->_wsdl = $wsdl;

return $this;
}

/**
* Add a Single or Multiple Functions to the WSDL
*
* @param string $function Function Name
* @param string $namespace Function namespace - Not Used
* @return \Zend\Soap\AutoDiscover
*/
public function addFunction($function, $namespace = '')
{
Expand Down Expand Up @@ -353,6 +358,8 @@ public function addFunction($function, $namespace = '')
$this->_addFunctionToWsdl($method, $wsdl, $port, $binding);
}
$this->_wsdl = $wsdl;

return $this;
}

/**
Expand Down Expand Up @@ -460,7 +467,11 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding)
}

// Add the binding operation
$operation = $wsdl->addBindingOperation($binding, $functionName, $this->_operationBodyStyle, $this->_operationBodyStyle);
if($isOneWayMessage == false) {
$operation = $wsdl->addBindingOperation($binding, $functionName, $this->_operationBodyStyle, $this->_operationBodyStyle);
} else {
$operation = $wsdl->addBindingOperation($binding, $functionName, $this->_operationBodyStyle);
}
$wsdl->addSoapOperation($operation, $uri . '#' . $functionName);

// Add the function name to the list
Expand All @@ -472,6 +483,7 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding)
*
* @param string $fault
* @param string|int $code
* @throws \Zend\Soap\Exception\UnexpectedValueException
*/
public function fault($fault = null, $code = null)
{
Expand All @@ -495,6 +507,8 @@ public function handle($request = false)
* Proxy to WSDL dump function
*
* @param string $filename
* @return boolean
* @throws \Zend\Soap\Exception\RuntimeException
*/
public function dump($filename)
{
Expand All @@ -507,6 +521,9 @@ public function dump($filename)

/**
* Proxy to WSDL toXml() function
*
* @return string
* @throws \Zend\Soap\Exception\RuntimeException
*/
public function toXml()
{
Expand All @@ -531,6 +548,7 @@ public function getFunctions()
* Load Functions
*
* @param unknown_type $definition
* @throws \Zend\Soap\Exception\RuntimeException
*/
public function loadFunctions($definition)
{
Expand All @@ -541,6 +559,7 @@ public function loadFunctions($definition)
* Set Persistance
*
* @param int $mode
* @throws \Zend\Soap\Exception\RuntimeException
*/
public function setPersistence($mode)
{
Expand Down
23 changes: 16 additions & 7 deletions src/Client.php
Expand Up @@ -313,7 +313,7 @@ public function getOptions()
* ugly hack as I don't know if checking for '=== null'
* breaks some other option
*/
if ($key == 'user_agent') {
if (in_array($key, array('user_agent', 'cache_wsdl', 'compression'))) {
if ($value === null) {
unset($options[$key]);
}
Expand Down Expand Up @@ -752,13 +752,16 @@ public function getHttpsCertPassphrase()
/**
* Set compression options
*
* @param int $compressionOptions
* @param int|null $compressionOptions
* @return \Zend\Soap\Client\Client
*/
public function setCompressionOptions($compressionOptions)
{
$this->_compression = $compressionOptions;

if ($compressionOptions === null) {
$this->_compression = null;
} else {
$this->_compression = (int)$compressionOptions;
}
$this->_soapClient = null;

return $this;
Expand Down Expand Up @@ -836,17 +839,23 @@ public function getSoapFeatures()
/**
* Set the SOAP WSDL Caching Options
*
* @param string|int|boolean $caching
* @param string|int|boolean|null $caching
* @return \Zend\Soap\Client\Client
*/
public function setWSDLCache($options)
public function setWSDLCache($caching)
{
$this->_cache_wsdl = $options;
if ($caching === null) {
$this->_cache_wsdl = null;
} else {
$this->_cache_wsdl = (int)$caching;
}
return $this;
}

/**
* Get current SOAP WSDL Caching option
*
* @return int
*/
public function getWSDLCache()
{
Expand Down
3 changes: 1 addition & 2 deletions src/Client/Local.php
Expand Up @@ -84,8 +84,7 @@ public function _doRequest(Common $client, $request, $location, $action, $versio
// Perform request as is
ob_start();
$this->_server->handle($request);
$response = ob_get_contents();
ob_end_clean();
$response = ob_get_clean();

return $response;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Server.php
Expand Up @@ -809,7 +809,7 @@ public function handle($request = null)
$soap->fault("Sender", $setRequestException->getMessage());
} else {
try {
$soap->handle($request);
$soap->handle($this->_request);
} catch (\Exception $e) {
$fault = $this->fault($e);
$soap->fault($fault->faultcode, $fault->faultstring);
Expand Down
4 changes: 2 additions & 2 deletions src/Wsdl.php
Expand Up @@ -314,8 +314,8 @@ public function addBindingOperation($binding, $name, $input = false, $output = f
if (isset($fault['name'])) {
$node->setAttribute('name', $fault['name']);
}
$soap_node = $this->_dom->createElement('soap:body');
foreach ($output as $name => $value) {
$soap_node = $this->_dom->createElement('soap:fault');
foreach ($fault as $name => $value) {
$soap_node->setAttribute($name, $value);
}
$node->appendChild($soap_node);
Expand Down
1 change: 0 additions & 1 deletion test/AutoDiscoverTest.php
Expand Up @@ -499,7 +499,6 @@ function testAddFunctionMultiple()
'<operation name="ZendTest.Soap.TestAsset.TestFunc2">'.
'<soap:operation soapAction="' . $scriptUri . '#ZendTest.Soap.TestAsset.TestFunc2"/>'.
'<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
'<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
'</operation>'.
'<operation name="ZendTest.Soap.TestAsset.TestFunc3">'.
'<soap:operation soapAction="' . $scriptUri . '#ZendTest.Soap.TestAsset.TestFunc3"/>'.
Expand Down
43 changes: 43 additions & 0 deletions test/ClientTest.php
Expand Up @@ -204,6 +204,49 @@ public function testUserAgentAllowsEmptyString()
$this->assertArrayNotHasKey('user_agent', $options);
}

/**
* @group ZF-10542
*/
public function testAllowNumericZeroAsValueForCacheWsdlOption()
{
$client = new Client();
$this->assertNull($client->getWsdlCache());
$options = $client->getOptions();
$this->assertArrayNotHasKey('cache_wsdl', $options);

$client->setWsdlCache(WSDL_CACHE_NONE);
$this->assertSame(WSDL_CACHE_NONE, $client->getWsdlCache());
$options = $client->getOptions();
$this->assertSame(WSDL_CACHE_NONE, $options['cache_wsdl']);

$client->setWsdlCache(null);
$this->assertNull($client->getWsdlCache());
$options = $client->getOptions();
$this->assertArrayNotHasKey('cache_wsdl', $options);
}

/**
* @group ZF-10542
*/
public function testAllowNumericZeroAsValueForCompressionOptions()
{
$client = new Client();
$this->assertNull($client->getCompressionOptions());
$options = $client->getOptions();
$this->assertArrayNotHasKey('compression', $options);

$client->setCompressionOptions(SOAP_COMPRESSION_GZIP);
$this->assertSame(SOAP_COMPRESSION_GZIP, $client->getCompressionOptions());
$options = $client->getOptions();
$this->assertSame(SOAP_COMPRESSION_GZIP, $options['compression']);

$client->setCompressionOptions(null);
$this->assertNull($client->getCompressionOptions());
$options = $client->getOptions();
$this->assertArrayNotHasKey('compression', $options);
}


public function testGetFunctions()
{
$server = new Server(__DIR__ . '/TestAsset/wsdl_example.wsdl');
Expand Down
10 changes: 10 additions & 0 deletions test/ServerTest.php
Expand Up @@ -851,4 +851,14 @@ public function testSetAndGetWSDLCache()
$this->assertTrue(isset($options['cache_wsdl']));
$this->assertEquals(100, $options['cache_wsdl']);
}

/**
* @group ZF-11411
*/
public function testHandleUsesProperRequestParameter()
{
$server = new \ZendTest\Soap\TestAsset\MockServer();
$r = $server->handle(new \DOMDocument('1.0', 'UTF-8'));
$this->assertTrue(is_string($server->mockSoapServer->handle[0]));
}
}
18 changes: 18 additions & 0 deletions test/TestAsset/commontypes.php
Expand Up @@ -549,6 +549,24 @@ class TestData2 {
public $property2;
}

class MockSoapServer {
public $handle = null;
public function handle()
{
$this->handle = func_get_args();
}
public function __call($name, $args) {}
}

class MockServer extends \Zend\Soap\Server {
public $mockSoapServer = null;
protected function _getSoap() {
$this->mockSoapServer = new MockSoapServer();
return $this->mockSoapServer;
}
}


/** Server test classes */
class ServerTestClass
{
Expand Down
2 changes: 1 addition & 1 deletion test/Wsdl/ArrayOfTypeComplexStrategyTest.php
Expand Up @@ -127,7 +127,7 @@ public function testArrayOfObjectWithObject()
);

$this->assertContains(
'<xsd:complexType name="ZendTest.Soap.TestAsset.ComplexObjectWithObjectStructure"><xsd:all><xsd:element name="object" type="tns:ZendTest.Soap.TestAsset.ComplexTest"/></xsd:all></xsd:complexType>',
'<xsd:complexType name="ZendTest.Soap.TestAsset.ComplexObjectWithObjectStructure"><xsd:all><xsd:element name="object" type="tns:ZendTest.Soap.TestAsset.ComplexTest" nillable="true"/></xsd:all></xsd:complexType>',
$wsdl,
$wsdl
);
Expand Down
10 changes: 5 additions & 5 deletions test/WsdlTest.php
Expand Up @@ -204,7 +204,7 @@ function testAddBindingOperation()
'operation3',
array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"),
array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"),
array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")
array('name' => 'MyFault','use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")
);

$this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
Expand Down Expand Up @@ -234,8 +234,8 @@ function testAddBindingOperation()
. '<output>'
. '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
. '</output>'
. '<fault>'
. '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
. '<fault name="MyFault">'
. '<soap:fault name="MyFault" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
. '</fault>'
. '</operation>'
. '</binding>'
Expand Down Expand Up @@ -620,8 +620,8 @@ function testAddComplexType()
. '<xsd:schema targetNamespace="http://localhost/MyService.php">'
. '<xsd:complexType name="ZendTest.Soap.TestAsset.WsdlTestClass">'
. '<xsd:all>'
. '<xsd:element name="var1" type="xsd:int"/>'
. '<xsd:element name="var2" type="xsd:string"/>'
. '<xsd:element name="var1" type="xsd:int" nillable="true"/>'
. '<xsd:element name="var2" type="xsd:string" nillable="true"/>'
. '</xsd:all>'
. '</xsd:complexType>'
. '</xsd:schema>'
Expand Down

0 comments on commit 388a6c0

Please sign in to comment.