From 17f4d590abb0227a125b206fa4c1d2bda232641e Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 11 Oct 2012 17:43:13 +0200 Subject: [PATCH 01/22] More DOM --- src/Wsdl.php | 111 ++++++++++++---------- test/TestAsset/validate.wsdl | 2 - test/WsdlTest.php | 176 ++++++++++++++++++++++++----------- 3 files changed, 183 insertions(+), 106 deletions(-) delete mode 100755 test/TestAsset/validate.wsdl diff --git a/src/Wsdl.php b/src/Wsdl.php index 2e8547af..8b0ac7d3 100755 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -76,10 +76,10 @@ class Wsdl const NS_WSDL = 'http://schemas.xmlsoap.org/wsdl/'; - const NS_XMLNS = 'http://www.w3.org/2000/xmlns/'; const NS_SOAP = 'http://schemas.xmlsoap.org/wsdl/soap/'; - const NS_SCHEMA = 'http://www.w3.org/2001/XMLSchema'; - const NS_S_ENC = 'http://schemas.xmlsoap.org/soap/encoding/'; + const NS_S_ENC = 'http://schemas.xmlsoap.org/soap/encoding/'; + const NS_XMLNS = 'http://www.w3.org/2000/xmlns/'; + const NS_SCHEMA = 'http://www.w3.org/2001/XMLSchema'; /** * Constructor * @@ -113,6 +113,7 @@ protected function getDOMDocument($uri, $name) { $dom = new \DOMDocument(); $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; $definitions = $dom->createElementNS(Wsdl::NS_WSDL, 'definitions'); @@ -152,7 +153,7 @@ public function setClassMap($classMap) * Set a new uri for this WSDL * * @param string|Uri $uri - * @return \Zend\Server\Wsdl + * @return \Zend\Soap\Wsdl */ public function setUri($uri) { @@ -196,9 +197,11 @@ public function getComplexTypeStrategy() * * @param string $name Name for the {@link http://www.w3.org/TR/wsdl#_messages message} * @param array $parts An array of {@link http://www.w3.org/TR/wsdl#_message parts} - * The array is constructed like: 'name of part' => 'part xml schema data type' - * or 'name of part' => array('type' => 'part xml schema type') - * or 'name of part' => array('element' => 'part xml element name') + * The array is constructed like: + * 'name of part' => 'part xml schema data type' or + * 'name of part' => array('type' => 'part xml schema type') or + * 'name of part' => array('element' => 'part xml element name') + * * @return object The new message's XML_Tree_Node for use in {@link function addDocumentation} */ public function addMessage($name, $parts) @@ -242,17 +245,18 @@ public function addPortType($name) return $portType; } - /** - * Add an {@link http://www.w3.org/TR/wsdl#_request-response operation} element to a portType element - * - * @param object $portType a portType XML_Tree_Node, from {@link function addPortType} - * @param string $name Operation name - * @param string $input Input Message - * @param string $output Output Message - * @param string $fault Fault Message - * @return object The new operation's XML_Tree_Node for use in {@link function addDocumentation} - */ - public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false) + /** + * Add an {@link http://www.w3.org/TR/wsdl#_request-response operation} element to a portType element + * + * @param object $portType a portType XML_Tree_Node, from {@link function addPortType} + * @param string $name Operation name + * @param bool|string $input Input Message + * @param bool|string $output Output Message + * @param bool|array $faults list of Fault Messages + * + * @return object The new operation's XML_Tree_Node for use in {@link function addDocumentation} + */ + public function addPortOperation($portType, $name, $input = false, $output = false, $faults = false) { $operation = $this->_dom->createElement('operation'); $operation->setAttribute('name', $name); @@ -262,15 +266,19 @@ public function addPortOperation($portType, $name, $input = false, $output = fal $node->setAttribute('message', $input); $operation->appendChild($node); } - if (is_string($output) && (strlen(trim($output)) >= 1)) { + + if (is_string($output) && (strlen(trim($output)) >= 1)) { $node= $this->_dom->createElement('output'); $node->setAttribute('message', $output); $operation->appendChild($node); } - if (is_string($fault) && (strlen(trim($fault)) >= 1)) { - $node = $this->_dom->createElement('fault'); - $node->setAttribute('message', $fault); - $operation->appendChild($node); + + if (is_array($faults) && !empty($faults)) { + foreach ($faults as $fault) { + $node = $this->_dom->createElement('fault'); + $node->setAttribute('message', $fault); + $operation->appendChild($node); + } } $portType->appendChild($operation); @@ -278,13 +286,14 @@ public function addPortOperation($portType, $name, $input = false, $output = fal return $operation; } - /** - * Add a {@link http://www.w3.org/TR/wsdl#_bindings binding} element to WSDL - * - * @param string $name Name of the Binding - * @param string $type name of the portType to bind - * @return object The new binding's XML_Tree_Node for use with {@link function addBindingOperation} and {@link function addDocumentation} - */ + /** + * Add a {@link http://www.w3.org/TR/wsdl#_bindings binding} element to WSDL + * + * @param string $name Name of the Binding + * @param string $portType string $type name of the portType to bind + * + * @return object The new binding's XML_Tree_Node for use with {@link function addBindingOperation} and {@link function addDocumentation} + */ public function addBinding($name, $portType) { $binding = $this->_dom->createElementNS(Wsdl::NS_WSDL, 'binding'); @@ -301,16 +310,18 @@ public function addBinding($name, $portType) return $binding; } - /** - * Add an operation to a binding element - * - * @param object $binding A binding XML_Tree_Node returned by {@link function addBinding} - * @param array $input An array of attributes for the input element, allowed keys are: 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param array $output An array of attributes for the output element, allowed keys are: 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param array $fault An array of attributes for the fault element, allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @return object The new Operation's XML_Tree_Node for use with {@link function addSoapOperation} and {@link function addDocumentation} - */ - public function addBindingOperation($binding, $name, $input = false, $output = false, $fault = false) + /** + * Add an operation to a binding element + * + * @param object $binding A binding XML_Tree_Node returned by {@link function addBinding} + * @param string $name + * @param array|bool $input An array of attributes for the input element, allowed keys are: 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * @param array|bool $output An array of attributes for the output element, allowed keys are: 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * @param array|bool $faults An array of elements, each with attributes for the fault element, allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * + * @return object The new Operation's XML_Tree_Node for use with {@link function addSoapOperation} and {@link function addDocumentation} + */ + public function addBindingOperation($binding, $name, $input = false, $output = false, $faults = false) { $operation = $this->_dom->createElementNS(Wsdl::NS_WSDL, 'operation'); $binding->appendChild($operation); @@ -348,18 +359,18 @@ public function addBindingOperation($binding, $name, $input = false, $output = f } } - if (is_array($fault)) { - $node = $this->_dom->createElementNS(Wsdl::NS_WSDL, 'fault'); - $operation->appendChild($node); + if (is_array($faults)) { + foreach ($faults as $fault) { + $node = $this->_dom->createElementNS(Wsdl::NS_WSDL, 'fault'); + $operation->appendChild($node); - foreach ($fault as $name => $value) { - $attr = $this->_dom->createAttributeNS(Wsdl::NS_WSDL, $name); - $attr->value = $value; + foreach ($fault as $name => $value) { + $attr = $this->_dom->createAttributeNS(Wsdl::NS_WSDL, $name); + $attr->value = $value; - $node->appendChild($attr); - } -// $node->appendChild($soap_node); -// $operation->appendChild($node); + $node->appendChild($attr); + } + } } return $operation; diff --git a/test/TestAsset/validate.wsdl b/test/TestAsset/validate.wsdl deleted file mode 100755 index 06dd899f..00000000 --- a/test/TestAsset/validate.wsdl +++ /dev/null @@ -1,2 +0,0 @@ - -Test Function diff --git a/test/WsdlTest.php b/test/WsdlTest.php index b7ebf7de..c67302d6 100755 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -40,7 +40,7 @@ class WsdlTest extends \PHPUnit_Framework_TestCase { /** - * @var Zend\Soap\Wsdl + * @var \Zend\Soap\Wsdl */ protected $wsdl; @@ -112,7 +112,6 @@ function testConstructor() function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes() { - $newUri = 'http://localhost/MyNewService.php'; $this->wsdl->setUri($newUri); @@ -122,7 +121,6 @@ function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttribute function testSetUriWithZendUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes() { - $newUri = 'http://localhost/MyNewService.php'; $this->wsdl->setUri(new Uri('http://localhost/MyNewService.php')); @@ -143,9 +141,8 @@ function testAddMessage() $this->wsdl->addMessage($messageName, $messageParts); $messageNodes = $this->xpath->query('//wsdl:definitions/message'); - if ($messageNodes->length === 0) { - $this->fail('Missing message node in definitions node.'); - } + $this->assertNotEquals(0, $messageNodes->length, 'Missing message node in definitions node.'); + $this->assertEquals($messageName, $messageNodes->item(0)->getAttribute('name')); foreach ($messageParts as $parameterName => $parameterType) { @@ -160,87 +157,158 @@ function testAddPortType() $this->wsdl->addPortType($portName); $portTypeNodes = $this->xpath->query('//wsdl:definitions/portType'); - - if ($portTypeNodes->length === 0) { - $this->fail('Missing portType node in definitions node.'); - } + $this->assertNotEquals(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); $this->assertTrue($portTypeNodes->item(0)->hasAttribute('name')); $this->assertEquals($portName, $portTypeNodes->item(0)->getAttribute('name')); - } - function testAddPortOperation() - { - $portName = 'myPortType'; - $portType = $this->wsdl->addPortType($portName); + public function testAddPortOperationCheckName() + { + $portName = 'myPortType'; + $portType = $this->wsdl->addPortType($portName); - $this->wsdl->addPortOperation($portType, 'operation1'); - $this->wsdl->addPortOperation($portType, 'operation2', 'tns:operation2Request', 'tns:operation2Response'); - $this->wsdl->addPortOperation($portType, 'operation3', 'tns:operation3Request', 'tns:operation3Response', 'tns:operation3Fault'); + $this->wsdl->addPortOperation($portType, 'operation'); + $portTypeNodes = $this->xpath->query('//wsdl:definitions/portType[@name="'.$portName.'"]'); + $this->assertNotEquals(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); + } - $portTypeNodes = $this->xpath->query('//wsdl:definitions/portType[@name="'.$portName.'"]'); - if ($portTypeNodes->length === 0) { - $this->fail('Missing portType node in definitions node.'); - } + public function testAddPortOperationWithNoRequestAndResponse() + { + $portName = 'myPortType'; + $portType = $this->wsdl->addPortType($portName); + $this->wsdl->addPortOperation($portType, 'operationName'); - $operation1Nodes = $this->xpath->query('operation[@name="operation1"]', $portTypeNodes->item(0)); - $this->assertEquals(1, $operation1Nodes->length); - $this->assertFalse($operation1Nodes->item(0)->hasChildNodes()); + $portTypeNodes = $this->xpath->query('//wsdl:definitions/portType[@name="'.$portName.'"]'); + $operation1Nodes = $this->xpath->query('operation[@name="operationName"]', $portTypeNodes->item(0)); + $this->assertEquals(1, $operation1Nodes->length); + $this->assertFalse($operation1Nodes->item(0)->hasChildNodes()); + } - $operation2Nodes = $this->xpath->query('operation[@name="operation2"]', $portTypeNodes->item(0)); - $this->assertEquals(1, $operation2Nodes->length); + public function testAddPortOperationWithRequest() + { + $portName = 'myPortType'; + $portType = $this->wsdl->addPortType($portName); - $inputNodes = $operation2Nodes->item(0)->getElementsByTagName('input'); - $this->assertEquals(1, $inputNodes->length); - $this->assertEquals('tns:operation2Request', $inputNodes->item(0)->getAttribute('message')); + $this->wsdl->addPortOperation($portType, 'operationName', 'operationRequest'); - $outputNodes = $operation2Nodes->item(0)->getElementsByTagName('output'); - $this->assertEquals(1, $outputNodes->length); - $this->assertEquals('tns:operation2Response', $outputNodes->item(0)->getAttribute('message')); + $portTypeNodes = $this->xpath->query('//wsdl:definitions/portType[@name="'.$portName.'"]'); + $operationNodes = $this->xpath->query('operation[@name="operationName"]', $portTypeNodes->item(0)); + $this->assertEquals(1, $operationNodes->length, 'Missing operation node'); - $operation3Nodes = $this->xpath->query('operation[@name="operation3"]', $portTypeNodes->item(0)); - $this->assertEquals(1, $operation3Nodes->length); + $result = $this->xpath->query('input[@message="operationRequest"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing input operation'); + } - $inputNodes = $operation3Nodes->item(0)->getElementsByTagName('input'); - $this->assertEquals(1, $inputNodes->length); - $this->assertEquals('tns:operation3Request', $inputNodes->item(0)->getAttribute('message')); - $outputNodes = $operation3Nodes->item(0)->getElementsByTagName('output'); - $this->assertEquals(1, $outputNodes->length); - $this->assertEquals('tns:operation3Response', $outputNodes->item(0)->getAttribute('message')); + public function testAddPortOperationWithRequestAndResponse() { + $portName = 'myPortType'; + $portType = $this->wsdl->addPortType($portName); - $faultNodes = $operation3Nodes->item(0)->getElementsByTagName('fault'); - $this->assertEquals(1, $faultNodes->length); - $this->assertEquals('tns:operation3Fault', $faultNodes->item(0)->getAttribute('message')); - } + $this->wsdl->addPortOperation($portType, 'operationName', 'operationRequest', 'operationResponse'); + + $portTypeNodes = $this->xpath->query('//wsdl:definitions/portType[@name="'.$portName.'"]'); + + $operationNodes = $this->xpath->query('operation[@name="operationName"]', $portTypeNodes->item(0)); + $this->assertEquals(1, $operationNodes->length, 'Missing operation node'); + + $result = $this->xpath->query('input[@message="operationRequest"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing input operation'); + + $result = $this->xpath->query('output[@message="operationResponse"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing output operation'); + } + + + public function testAddPortOperationWithRequestAndResponseAndOneFault() { + $portName = 'myPortType'; + $portType = $this->wsdl->addPortType($portName); + + $this->wsdl->addPortOperation($portType, 'operationName', 'operationRequest', 'operationResponse', array('FaultName')); + + $portTypeNodes = $this->xpath->query('//wsdl:definitions/portType[@name="'.$portName.'"]'); + + $operationNodes = $this->xpath->query('operation[@name="operationName"]', $portTypeNodes->item(0)); + $this->assertEquals(1, $operationNodes->length, 'Missing operation node'); + + $result = $this->xpath->query('input[@message="operationRequest"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing input operation'); + + $result = $this->xpath->query('output[@message="operationResponse"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing output operation'); + + $result = $this->xpath->query('fault[@message="FaultName"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing fault: FaultName'); + } + + public function testAddPortOperationWithRequestAndResponseAndMultipleFaults(){ + $portName = 'myPortType'; + $portType = $this->wsdl->addPortType($portName); + + $faultNames = array( + 'FaultName1', + 'FaultName2', + 'FaultName3' + ); + + $this->wsdl->addPortOperation($portType, 'operationName', 'operationRequest', 'operationResponse', $faultNames); + + $portTypeNodes = $this->xpath->query('//wsdl:definitions/portType[@name="'.$portName.'"]'); + + $operationNodes = $this->xpath->query('operation[@name="operationName"]', $portTypeNodes->item(0)); + $this->assertEquals(1, $operationNodes->length, 'Missing operation node'); + + $result = $this->xpath->query('input[@message="operationRequest"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing input operation'); + + $result = $this->xpath->query('output[@message="operationResponse"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing output operation'); + + foreach($faultNames as $faultName) { + $result = $this->xpath->query('fault[@message="'.$faultName.'"]', $operationNodes->item(0)); + $this->assertEquals(1, $result->length, 'Missing fault: '.$faultName); + } + } function testAddBinding() { $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->wsdl->toDomDocument()->formatOutput = true; $bindingNodes = $this->xpath->query('//wsdl:definitions/wsdl:binding'); - if ($bindingNodes->length === 0) { - $this->fail('Missing binding node in definitions node.'.$bindingNodes->length); - } + $this->assertNotEquals(0, $bindingNodes->length, 'Missing binding node in definitions node'); $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'type')); } - function testAddBindingOperation() - { + public function testAddBindingOperationEmptyOperation() + { + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + $this->wsdl->addBindingOperation($binding, 'operation1'); + $bindingNodes = $this->xpath->query('//wsdl:binding'); + $this->assertNotEquals(0, $bindingNodes->length, 'Missing binding node in definitions node.'); + $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); + $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'type')); + } - $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->wsdl->addBindingOperation($binding, 'operation1'); + public function testAddBindingOperationOneWayOperation() + { + + } + + + + + + function testAddBindingOperation() + { $encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"; @@ -255,7 +323,7 @@ function testAddBindingOperation() 'operation3', array('use' => 'encoded', 'encodingStyle' => $encodingStyle), array('use' => 'encoded', 'encodingStyle' => $encodingStyle), - array('use' => 'encoded', 'encodingStyle' => $encodingStyle, 'name' => 'MyFault',) + array('use' => 'encoded', 'encodingStyle' => $encodingStyle, 'name' => array('MyFault')) ); $bindingNodes = $this->xpath->query('//wsdl:binding'); From f92db2d5f0ec9f115c3f87b567be27fec2b49b43 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Fri, 25 Jan 2013 11:51:11 +0100 Subject: [PATCH 02/22] Fixes in wsdl generation and tests. --- src/Wsdl.php | 54 ++--- test/WsdlTest.php | 537 ++++++++++++++++++++++++++++------------------ 2 files changed, 361 insertions(+), 230 deletions(-) mode change 100644 => 100755 src/Wsdl.php mode change 100644 => 100755 test/WsdlTest.php diff --git a/src/Wsdl.php b/src/Wsdl.php old mode 100644 new mode 100755 index 1a570d74..149f8eea --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -85,9 +85,9 @@ public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, a $this->uri = $uri; $this->classMap = $classMap; - $this->_dom = $this->getDOMDocument($uri, $name); + $this->dom = $this->getDOMDocument($uri, $name); - $this->_wsdl = $this->_dom->documentElement; + $this->wsdl = $this->dom->documentElement; $this->setComplexTypeStrategy($strategy ?: new Wsdl\ComplexTypeStrategy\DefaultComplexType); } @@ -102,7 +102,8 @@ public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, a protected function getDOMDocument($uri, $name) { $dom = new \DOMDocument(); - $dom->preserveWhiteSpace = false; + $dom->preserveWhiteSpace = true; + $dom->formatOutput = true; $definitions = $dom->createElementNS(Wsdl::NS_WSDL, 'definitions'); @@ -150,7 +151,6 @@ public function setUri($uri) $uri = $uri->toString(); } $this->uri = $uri; - if($this->dom instanceof \DOMDocument ) { $this->dom->documentElement->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:tns', $uri); @@ -185,22 +185,22 @@ public function getComplexTypeStrategy() /** * Add a {@link http://www.w3.org/TR/wsdl#_messages message} element to the WSDL * - * @param string $name Name for the {@link http://www.w3.org/TR/wsdl#_messages message} + * @param string $messageName Name for the {@link http://www.w3.org/TR/wsdl#_messages message} * @param array $parts An array of {@link http://www.w3.org/TR/wsdl#_message parts} * The array is constructed like: 'name of part' => 'part xml schema data type' * or 'name of part' => array('type' => 'part xml schema type') * or 'name of part' => array('element' => 'part xml element name') * @return object The new message's XML_Tree_Node for use in {@link function addDocumentation} */ - public function addMessage($name, $parts) + public function addMessage($messageName, $parts) { - $message = $this->dom->createElement('message'); + $message = $this->dom->createElementNS(Wsdl::NS_WSDL, 'message'); - $message->setAttribute('name', $name); + $message->setAttribute('name', $messageName); if (count($parts) > 0) { foreach ($parts as $name => $type) { - $part = $this->dom->createElement('part'); + $part = $this->dom->createElementNS(Wsdl::NS_WSDL, 'part'); $part->setAttribute('name', $name); if (is_array($type)) { foreach ($type as $key => $value) { @@ -226,7 +226,7 @@ public function addMessage($name, $parts) */ public function addPortType($name) { - $portType = $this->dom->createElement('portType'); + $portType = $this->dom->createElementNS(Wsdl::NS_WSDL, 'portType'); $portType->setAttribute('name', $name); $this->wsdl->appendChild($portType); @@ -245,21 +245,21 @@ public function addPortType($name) */ public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false) { - $operation = $this->dom->createElement('operation'); + $operation = $this->dom->createElementNS(Wsdl::NS_WSDL, 'operation'); $operation->setAttribute('name', $name); if (is_string($input) && (strlen(trim($input)) >= 1)) { - $node = $this->dom->createElement('input'); + $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'input'); $node->setAttribute('message', $input); $operation->appendChild($node); } if (is_string($output) && (strlen(trim($output)) >= 1)) { - $node= $this->dom->createElement('output'); + $node= $this->dom->createElementNS(Wsdl::NS_WSDL, 'output'); $node->setAttribute('message', $output); $operation->appendChild($node); } if (is_string($fault) && (strlen(trim($fault)) >= 1)) { - $node = $this->dom->createElement('fault'); + $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'fault'); $node->setAttribute('message', $fault); $operation->appendChild($node); } @@ -278,14 +278,14 @@ public function addPortOperation($portType, $name, $input = false, $output = fal */ public function addBinding($name, $portType) { - $binding = $this->_dom->createElementNS(Wsdl::NS_WSDL, 'binding'); - $this->_wsdl->appendChild($binding); + $binding = $this->dom->createElementNS(Wsdl::NS_WSDL, 'binding'); + $this->wsdl->appendChild($binding); - $attr = $this->_dom->createAttributeNS(Wsdl::NS_WSDL, 'name'); + $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, 'name'); $attr->value = $name; $binding->appendChild($attr); - $attr = $this->_dom->createAttributeNS(Wsdl::NS_WSDL, 'type'); + $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, 'type'); $attr->value = $portType; $binding->appendChild($attr); @@ -314,13 +314,13 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'input'); $operation->appendChild($node); - $soap_node = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); - $node->appendChild($soap_node); + $soapNode = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); + $node->appendChild($soapNode); foreach ($input as $name => $value) { $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, $name); $attr->value = $value; - $soap_node->appendChild($attr); + $soapNode->appendChild($attr); } } @@ -329,13 +329,13 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'output'); $operation->appendChild($node); - $soap_node = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); - $node->appendChild($soap_node); + $soapNode = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); + $node->appendChild($soapNode); foreach ($input as $name => $value) { $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, $name); $attr->value = $value; - $soap_node->appendChild($attr); + $soapNode->appendChild($attr); } } @@ -349,7 +349,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $node->appendChild($attr); } -// $node->appendChild($soap_node); +// $node->appendChild($soapNode); // $operation->appendChild($node); } @@ -463,11 +463,13 @@ public function addDocumentation($inputNode, $documentation) * Add WSDL Types element * * @param object $types A DomDocument|DomNode|DomElement|DomDocumentFragment with all the XML Schema types defined in it + * + * @return void */ public function addTypes($types) { if ($types instanceof \DomDocument) { - $dom = $this->dom->importNode($types->documentElement); + $this->dom->importNode($types->documentElement); $this->wsdl->appendChild($types->documentElement); } elseif ($types instanceof \DomNode || $types instanceof \DomElement || $types instanceof \DomDocumentFragment ) { $dom = $this->dom->importNode($types); diff --git a/test/WsdlTest.php b/test/WsdlTest.php old mode 100644 new mode 100755 index f17c8b1a..ffd8ca60 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -23,6 +23,8 @@ use Zend\Soap\Wsdl, Zend\Soap\Wsdl\ComplexTypeStrategy; +use Zend\Uri\Uri; + /** * Test cases for Zend_Soap_Wsdl * @@ -36,6 +38,27 @@ */ class WsdlTest extends \PHPUnit_Framework_TestCase { + + /** + * @var Wsdl + */ + protected $wsdl; + + /** + * @var \DOMDocument + */ + protected $dom; + + /** + * @var \DOMXPath + */ + protected $xpath; + + /** + * @deprecated Move to native DOM + * @param $xmlstring + * @return mixed + */ protected function sanitizeWsdlXmlOutputForOsCompability($xmlstring) { $xmlstring = str_replace(array("\r", "\n"), "", $xmlstring); @@ -50,160 +73,266 @@ public function swallowIncludeNotices($errno, $errstr) } } + + public function setUp() + { + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + + $this->dom = $this->wsdl->toDomDocument(); + $this->xpath = new \DOMXPath($this->dom); + $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); + + $this->xpath->registerNamespace('tns', 'http://localhost/MyService.php'); + $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); + $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); + $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); + $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + + } + function testConstructor() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' ); + $uri = 'http://localhost/MyService.php'; + $name = 'MyService'; + + $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri(null)); + $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); + $this->assertEquals($uri, $this->dom->lookupNamespaceUri('tns')); + $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); + $this->assertEquals(Wsdl::NS_SCHEMA, $this->dom->lookupNamespaceUri('xsd')); + $this->assertEquals(Wsdl::NS_S_ENC, $this->dom->lookupNamespaceUri('soap-enc')); + $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri('wsdl')); + + $this->assertEquals(Wsdl::NS_WSDL, $this->dom->documentElement->namespaceURI); + + $this->assertEquals($name, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'name')); + $this->assertEquals($uri, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'targetNamespace')); + } function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->setUri('http://localhost/MyNewService.php'); + $newUri = 'http://localhost/MyNewService.php'; + $this->wsdl->setUri($newUri); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' ); + $this->assertEquals($newUri, $this->dom->lookupNamespaceUri('tns')); + $this->assertEquals($newUri, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'targetNamespace')); } - function testAddMessage() + function testSetUriWithZendUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $newUri = 'http://localhost/MyNewService.php'; + $this->wsdl->setUri(new Uri('http://localhost/MyNewService.php')); + + $this->assertEquals($newUri, $this->dom->lookupNamespaceUri('tns')); + $this->assertEquals($newUri, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'targetNamespace')); + } + function testAddMessage() + { $messageParts = array(); - $messageParts['parameter1'] = $wsdl->getType('int'); - $messageParts['parameter2'] = $wsdl->getType('string'); - $messageParts['parameter3'] = $wsdl->getType('mixed'); - $wsdl->addMessage('myMessage', $messageParts); + $messageParts['parameter1'] = $this->wsdl->getType('int'); + $messageParts['parameter2'] = $this->wsdl->getType('string'); + $messageParts['parameter3'] = $this->wsdl->getType('mixed'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' ); + $messageName = 'myMessage'; + + $this->wsdl->addMessage($messageName, $messageParts); + + $messageNodes = $this->xpath->query('//wsdl:definitions/wsdl:message'); + + $this->assertGreaterThan(0, $messageNodes->length, 'Missing message node in definitions node.'); + + $this->assertEquals($messageName, $messageNodes->item(0)->getAttribute('name')); + + foreach ($messageParts as $parameterName => $parameterType) { + $part = $this->xpath->query('//wsdl:part[@name="'.$parameterName.'"]', $messageNodes->item(0)); + $this->assertEquals($parameterType, $part->item(0)->getAttribute('type')); + } } function testAddPortType() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $portName = 'myPortType'; + $this->wsdl->addPortType($portName); - $wsdl->addPortType('myPortType'); + $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType'); + print $portTypeNodes->length; + + $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); + + $this->assertTrue($portTypeNodes->item(0)->hasAttribute('name')); + $this->assertEquals($portName, $portTypeNodes->item(0)->getAttribute('name')); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' ); } - function testAddPortOperation() + /** + * @dataProvider dataProviderForAddPortOperation + */ + function testAddPortOperation($operationName, $inputRequest = null, $inputRequest = null, $outputResponse = null, $fail = null) { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $portName = 'myPortType'; + $portType = $this->wsdl->addPortType($portName); + + $this->wsdl->addPortOperation($portType, $operationName, $inputRequest, $outputResponse, $fail); +// $this->wsdl->addPortOperation($portType, 'operation2', 'tns:operation2Request', 'tns:operation2Response'); +// $this->wsdl->addPortOperation($portType, 'operation3', 'tns:operation3Request', 'tns:operation3Response', 'tns:operation3Fault'); + + + $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType[@name="'.$portName.'"]'); + $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); + + + $operation1Nodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $portTypeNodes->item(0)); + $this->assertGreaterThan(0, $operation1Nodes->length); + if (empty($inputRequest)) { + $this->assertFalse($operation1Nodes->item(0)->hasChildNodes()); + } else { + $this->assertTrue($operation1Nodes->item(0)->hasChildNodes()); + + $inputNodes = $operation1Nodes->item(0)->getElementsByTagName('input'); + $this->assertEquals($inputRequest, $inputNodes->item(0)->getAttribute('message')); + } + + +// $inputNodes = $operation2Nodes->item(0)->getElementsByTagName('input'); +// $this->assertEquals(1, $inputNodes->length); +// +// +// $outputNodes = $operation2Nodes->item(0)->getElementsByTagName('output'); +// $this->assertEquals(1, $outputNodes->length); +// $this->assertEquals('tns:operation2Response', $outputNodes->item(0)->getAttribute('message')); +// +// +// $operation3Nodes = $this->xpath->query('wsdl:operation[@name="operation3"]', $portTypeNodes->item(0)); +// $this->assertEquals(1, $operation3Nodes->length); +// +// $inputNodes = $operation3Nodes->item(0)->getElementsByTagName('input'); +// $this->assertEquals(1, $inputNodes->length); +// $this->assertEquals('tns:operation3Request', $inputNodes->item(0)->getAttribute('message')); +// +// $outputNodes = $operation3Nodes->item(0)->getElementsByTagName('output'); +// $this->assertEquals(1, $outputNodes->length); +// $this->assertEquals('tns:operation3Response', $outputNodes->item(0)->getAttribute('message')); +// +// $faultNodes = $operation3Nodes->item(0)->getElementsByTagName('fault'); +// $this->assertEquals(1, $faultNodes->length); +// $this->assertEquals('tns:operation3Fault', $faultNodes->item(0)->getAttribute('message')); + } + + /** + * + */ + function dataProviderForAddPortOperation() + { + + return array( + array('operation1'), + array('operation2', 'tns:operation2Request', 'tns:operation2Response'), + ); - $portType = $wsdl->addPortType('myPortType'); - $wsdl->addPortOperation($portType, 'operation1'); - $wsdl->addPortOperation($portType, 'operation2', 'tns:operation2Request', 'tns:operation2Response'); - $wsdl->addPortOperation($portType, 'operation3', 'tns:operation3Request', 'tns:operation3Response', 'tns:operation3Fault'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' ); } function testAddBinding() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + $this->wsdl->toDomDocument()->formatOutput = true; - $wsdl->addPortType('myPortType'); - $wsdl->addBinding('MyServiceBinding', 'myPortType'); + $bindingNodes = $this->xpath->query('//wsdl:definitions/wsdl:binding'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' ); + if ($bindingNodes->length === 0) { + $this->fail('Missing binding node in definitions node.'.$bindingNodes->length); + } + + $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); + $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'type')); } function testAddBindingOperation() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addPortType('myPortType'); - $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); - $wsdl->addBindingOperation($binding, 'operation1'); - $wsdl->addBindingOperation($binding, + + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + $this->wsdl->addBindingOperation($binding, 'operation1'); + + + $encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"; + $this->wsdl->addBindingOperation($binding, 'operation2', - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") - ); - $wsdl->addBindingOperation($binding, + array('use' => 'encoded', 'encodingStyle' => $encodingStyle), + array('use' => 'encoded', 'encodingStyle' => $encodingStyle) + ); + + + $this->wsdl->addBindingOperation($binding, 'operation3', - 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/") - ); + array('use' => 'encoded', 'encodingStyle' => $encodingStyle), + array('use' => 'encoded', 'encodingStyle' => $encodingStyle), + array('use' => 'encoded', 'encodingStyle' => $encodingStyle, 'name' => 'MyFault',) + ); + + $bindingNodes = $this->xpath->query('//wsdl:binding'); + + if ($bindingNodes->length === 0) { + $this->fail('Missing binding node in definitions node.'.$bindingNodes->length); + } + + $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); + $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'type')); + + + $operation1Nodes = $this->xpath->query('//wsdl:operation[@name="operation1"]', $bindingNodes->item(0)); + $this->assertEquals(1, $operation1Nodes->length); + //@todo namespace ? + $this->assertFalse($operation1Nodes->item(0)->hasChildNodes()); + + $inputBodyNodes = $this->xpath->query('//wsdl:operation[@name="operation2"]/wsdl:input/soap:body', $bindingNodes->item(0)); + if ($inputBodyNodes->length === 0){ + $this->fail('Unable to find body in binding operation node'); + } + $this->assertEquals('encoded', $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'use')); + $this->assertEquals($encodingStyle, $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'encodingStyle')); + + foreach(array('input', 'output') as $direction) { + foreach(array('operation2', 'operation3') as $operation) { + $inputBodyNodes = $this->xpath->query('//wsdl:operation[@name="'.$operation.'"]/wsdl:'.$direction.'/soap:body', $bindingNodes->item(0)); + if ($inputBodyNodes->length === 0){ + $this->fail('Unable to find body in binding '.$operation.' node'); + } + $this->assertEquals('encoded', $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'use')); + $this->assertEquals($encodingStyle, $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'encodingStyle')); + } + } + + $faultNodes = $this->xpath->query('//wsdl:operation[@name="operation3"]/wsdl:fault', $bindingNodes->item(0)); + if ($faultNodes->length === 0){ + $this->fail('Unable to find fault operation node'); + } + $this->assertEquals('encoded', $faultNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'use')); + $this->assertEquals('MyFault', $faultNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); + $this->assertEquals($encodingStyle, $faultNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'encodingStyle')); + + +// $this->wsdl->toDomDocument()->formatOutput = true; +// print ($this->wsdl->toDomDocument()->saveXML());exit; + + +// $inputBodyNodes = $this->xpath->query('//wsdl:operation[@name="operation3"]/wsdl:input/soap:body', $bindingNodes->item(0)); +// if ($inputBodyNodes->length === 0){ +// $this->fail('Unable to find body in binding operation node'); +// } +// $this->assertEquals('encoded', $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'use')); +// $this->assertEquals($encodingStyle, $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'encodingStyle')); + + + - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + ($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()). '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addPortType('myPortType'); - $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); + $this->wsdl->addPortType('myPortType'); + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $wsdl->addSoapBinding($binding); + $this->wsdl->addSoapBinding($binding); - $wsdl->addBindingOperation($binding, 'operation1'); - $wsdl->addBindingOperation($binding, + $this->wsdl->addBindingOperation($binding, 'operation1'); + $this->wsdl->addBindingOperation($binding, 'operation2', array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") ); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addPortType('myPortType'); - $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); + $this->wsdl->addPortType('myPortType'); + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $wsdl->addSoapOperation($binding, 'http://localhost/MyService.php#myOperation'); + $this->wsdl->addSoapOperation($binding, 'http://localhost/MyService.php#myOperation'); - $wsdl->addBindingOperation($binding, 'operation1'); - $wsdl->addBindingOperation($binding, + $this->wsdl->addBindingOperation($binding, 'operation1'); + $this->wsdl->addBindingOperation($binding, 'operation2', array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") ); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addPortType('myPortType'); - $wsdl->addBinding('MyServiceBinding', 'myPortType'); + $this->wsdl->addPortType('myPortType'); + $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', 'http://localhost/MyService.php'); + $this->wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', 'http://localhost/MyService.php'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $portType = $wsdl->addPortType('myPortType'); + $portType = $this->wsdl->addPortType('myPortType'); - $wsdl->addDocumentation($portType, 'This is a description for Port Type node.'); + $this->wsdl->addDocumentation($portType, 'This is a description for Port Type node.'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); $messageParts = array(); - $messageParts['parameter1'] = $wsdl->getType('int'); - $messageParts['parameter2'] = $wsdl->getType('string'); - $messageParts['parameter3'] = $wsdl->getType('mixed'); + $messageParts['parameter1'] = $this->wsdl->getType('int'); + $messageParts['parameter2'] = $this->wsdl->getType('string'); + $messageParts['parameter3'] = $this->wsdl->getType('mixed'); - $message = $wsdl->addMessage('myMessage', $messageParts); - $wsdl->addDocumentation($message, "foo"); + $message = $this->wsdl->addMessage('myMessage', $messageParts); + $this->wsdl->addDocumentation($message, "foo"); $this->assertEquals( '' . @@ -438,15 +567,15 @@ public function testAddDocumentationToSetInsertsBefore() . '' . '' . '', - $this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()) + $this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()) ); } function testToXml() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), '' . 'toDomDocument(); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->dom = $this->wsdl->toDomDocument(); - $this->assertTrue($dom instanceOf \DOMDocument); + $this->assertTrue($this->dom instanceOf \DOMDocument); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->dom->saveXML()), '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); ob_start(); - $wsdl->dump(); + $this->wsdl->dump(); $wsdlDump = ob_get_clean(); $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdlDump), @@ -493,7 +622,7 @@ function testDump() . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" ' . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' ); - $wsdl->dump(__DIR__ . '/TestAsset/dumped.wsdl'); + $this->wsdl->dump(__DIR__ . '/TestAsset/dumped.wsdl'); $dumpedContent = file_get_contents(__DIR__ . '/TestAsset/dumped.wsdl'); $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($dumpedContent), @@ -511,27 +640,27 @@ function testDump() function testGetType() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - - $this->assertEquals('xsd:string', $wsdl->getType('string'), 'xsd:string detection failed.'); - $this->assertEquals('xsd:string', $wsdl->getType('str'), 'xsd:string detection failed.'); - $this->assertEquals('xsd:int', $wsdl->getType('int'), 'xsd:int detection failed.'); - $this->assertEquals('xsd:int', $wsdl->getType('integer'), 'xsd:int detection failed.'); - $this->assertEquals('xsd:float', $wsdl->getType('float'), 'xsd:float detection failed.'); - $this->assertEquals('xsd:double', $wsdl->getType('double'), 'xsd:double detection failed.'); - $this->assertEquals('xsd:boolean', $wsdl->getType('boolean'), 'xsd:boolean detection failed.'); - $this->assertEquals('xsd:boolean', $wsdl->getType('bool'), 'xsd:boolean detection failed.'); - $this->assertEquals('soap-enc:Array', $wsdl->getType('array'), 'soap-enc:Array detection failed.'); - $this->assertEquals('xsd:struct', $wsdl->getType('object'), 'xsd:struct detection failed.'); - $this->assertEquals('xsd:anyType', $wsdl->getType('mixed'), 'xsd:anyType detection failed.'); - $this->assertEquals('', $wsdl->getType('void'), 'void detection failed.'); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + + $this->assertEquals('xsd:string', $this->wsdl->getType('string'), 'xsd:string detection failed.'); + $this->assertEquals('xsd:string', $this->wsdl->getType('str'), 'xsd:string detection failed.'); + $this->assertEquals('xsd:int', $this->wsdl->getType('int'), 'xsd:int detection failed.'); + $this->assertEquals('xsd:int', $this->wsdl->getType('integer'), 'xsd:int detection failed.'); + $this->assertEquals('xsd:float', $this->wsdl->getType('float'), 'xsd:float detection failed.'); + $this->assertEquals('xsd:double', $this->wsdl->getType('double'), 'xsd:double detection failed.'); + $this->assertEquals('xsd:boolean', $this->wsdl->getType('boolean'), 'xsd:boolean detection failed.'); + $this->assertEquals('xsd:boolean', $this->wsdl->getType('bool'), 'xsd:boolean detection failed.'); + $this->assertEquals('soap-enc:Array', $this->wsdl->getType('array'), 'soap-enc:Array detection failed.'); + $this->assertEquals('xsd:struct', $this->wsdl->getType('object'), 'xsd:struct detection failed.'); + $this->assertEquals('xsd:anyType', $this->wsdl->getType('mixed'), 'xsd:anyType detection failed.'); + $this->assertEquals('', $this->wsdl->getType('void'), 'void detection failed.'); } function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals('tns:WsdlTestClass', $wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); + $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); // $wsdl2 = new Wsdl('MyService', 'http://localhost/MyService.php', false); // $this->assertEquals('xsd:anyType', $wsdl2->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); @@ -540,9 +669,9 @@ function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() function testGetComplexTypeBasedOnStrategiesStringNames() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); - $this->assertEquals('tns:WsdlTestClass', $wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); + $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); + $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); $wsdl2 = new Wsdl('MyService', 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); $this->assertEquals('xsd:anyType', $wsdl2->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); @@ -551,10 +680,10 @@ function testGetComplexTypeBasedOnStrategiesStringNames() function testAddingSameComplexTypeMoreThanOnceIsIgnored() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:SomeTypeName'); - $wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:AnotherTypeName'); - $types = $wsdl->getTypes(); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:SomeTypeName'); + $this->wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:AnotherTypeName'); + $types = $this->wsdl->getTypes(); $this->assertEquals(1, count($types)); $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:SomeTypeName'), $types); @@ -562,25 +691,25 @@ function testAddingSameComplexTypeMoreThanOnceIsIgnored() function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:WsdlTestClass'), - $wsdl->getTypes()); + $this->wsdl->getTypes()); - $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:WsdlTestClass'), - $wsdl->getTypes()); + $this->wsdl->getTypes()); } function testAddComplexType() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), '' . 'assertEquals("xsd:string", $wsdl->getType("StrIng")); - $this->assertEquals("xsd:string", $wsdl->getType("sTr")); - $this->assertEquals("xsd:int", $wsdl->getType("iNt")); - $this->assertEquals("xsd:int", $wsdl->getType("INTEGER")); - $this->assertEquals("xsd:float", $wsdl->getType("FLOAT")); - $this->assertEquals("xsd:double", $wsdl->getType("douBLE")); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + + $this->assertEquals("xsd:string", $this->wsdl->getType("StrIng")); + $this->assertEquals("xsd:string", $this->wsdl->getType("sTr")); + $this->assertEquals("xsd:int", $this->wsdl->getType("iNt")); + $this->assertEquals("xsd:int", $this->wsdl->getType("INTEGER")); + $this->assertEquals("xsd:float", $this->wsdl->getType("FLOAT")); + $this->assertEquals("xsd:double", $this->wsdl->getType("douBLE")); } /** @@ -622,8 +751,8 @@ function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() */ public function testWsdlGetTypeWillAllowLongType() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals("xsd:long", $wsdl->getType("long")); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->assertEquals("xsd:long", $this->wsdl->getType("long")); } /** @@ -631,14 +760,14 @@ public function testWsdlGetTypeWillAllowLongType() */ public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceBySequenceStrategy() { - $wsdl = new Wsdl("MyService", "http://localhost/MyService.php"); - $wsdl->setComplexTypeStrategy(new ComplexTypeStrategy\ArrayOfTypeSequence()); + $this->wsdl = new Wsdl("MyService", "http://localhost/MyService.php"); + $this->wsdl->setComplexTypeStrategy(new ComplexTypeStrategy\ArrayOfTypeSequence()); - $wsdl->addComplexType("string[]"); - $wsdl->addComplexType("int[]"); - $wsdl->addComplexType("string[]"); + $this->wsdl->addComplexType("string[]"); + $this->wsdl->addComplexType("int[]"); + $this->wsdl->addComplexType("string[]"); - $xml = $wsdl->toXml(); + $xml = $this->wsdl->toXml(); $this->assertEquals(1, substr_count($xml, "ArrayOfString"), "ArrayOfString should appear only once."); $this->assertEquals(1, substr_count($xml, "ArrayOfInt"), "ArrayOfInt should appear only once."); } @@ -651,8 +780,8 @@ public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceByS */ public function testHtmlAmpersandInUrlInConstructorIsEncodedCorrectly() { - $wsdl = new Wsdl("MyService", self::URI_WITH_EXPANDED_AMP); - $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML()); + $this->wsdl = new Wsdl("MyService", self::URI_WITH_EXPANDED_AMP); + $this->assertContains(self::URI_WITH_EXPANDED_AMP, $this->wsdl->toXML()); } /** @@ -660,8 +789,8 @@ public function testHtmlAmpersandInUrlInConstructorIsEncodedCorrectly() */ public function testHtmlAmpersandInUrlInSetUriIsEncodedCorrectly() { - $wsdl = new Wsdl("MyService", "http://example.com"); - $wsdl->setUri(self::URI_WITH_EXPANDED_AMP); - $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML()); + $this->wsdl = new Wsdl("MyService", "http://example.com"); + $this->wsdl->setUri(self::URI_WITH_EXPANDED_AMP); + $this->assertContains(self::URI_WITH_EXPANDED_AMP, $this->wsdl->toXML()); } } From 5c1309d9fc607c7772018f349bca2a01aa61be3d Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Tue, 29 Jan 2013 10:22:52 +0100 Subject: [PATCH 03/22] More code changes --- src/Wsdl.php | 8 +- test/WsdlTest.php | 255 ++++++++++++++++++++++------------------------ 2 files changed, 124 insertions(+), 139 deletions(-) diff --git a/src/Wsdl.php b/src/Wsdl.php index 149f8eea..6736a2a8 100755 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -310,7 +310,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $attr->value = $name; $operation->appendChild($attr); - if (is_array($input)) { + if (is_array($input) AND !empty($input)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'input'); $operation->appendChild($node); @@ -325,21 +325,21 @@ public function addBindingOperation($binding, $name, $input = false, $output = f } - if (is_array($output)) { + if (is_array($output) AND !empty($output)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'output'); $operation->appendChild($node); $soapNode = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); $node->appendChild($soapNode); - foreach ($input as $name => $value) { + foreach ($output as $name => $value) { $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, $name); $attr->value = $value; $soapNode->appendChild($attr); } } - if (is_array($fault)) { + if (is_array($fault) AND !empty($fault)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'fault'); $operation->appendChild($node); diff --git a/test/WsdlTest.php b/test/WsdlTest.php index ffd8ca60..3704302f 100755 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -129,13 +129,18 @@ function testSetUriWithZendUriChangesDomDocumentWsdlStructureTnsAndTargetNamespa $this->assertEquals($newUri, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'targetNamespace')); } - function testAddMessage() + /** + * + * @dataProvider dataProviderForAddMessage + * + * @param array $parameters + */ + function testAddMessage($parameters) { - $messageParts = array(); - - $messageParts['parameter1'] = $this->wsdl->getType('int'); - $messageParts['parameter2'] = $this->wsdl->getType('string'); - $messageParts['parameter3'] = $this->wsdl->getType('mixed'); + $messageParts = array(); + foreach($parameters as $i => $parameter) { + $messageParts['parameter'.$i] = $this->wsdl->getType($parameter); + } $messageName = 'myMessage'; @@ -153,6 +158,19 @@ function testAddMessage() } } + /** + * + */ + public function dataProviderForAddMessage(){ + return array( + array(array('int', 'int', 'int')), + array(array('string', 'string', 'string', 'string')), + array(array('mixed')), + array(array('int', 'int', 'string', 'string')), + array(array('int', 'string', 'int', 'string')), + ); + } + function testAddPortType() { $portName = 'myPortType'; @@ -177,49 +195,35 @@ function testAddPortOperation($operationName, $inputRequest = null, $inputReques $portType = $this->wsdl->addPortType($portName); $this->wsdl->addPortOperation($portType, $operationName, $inputRequest, $outputResponse, $fail); -// $this->wsdl->addPortOperation($portType, 'operation2', 'tns:operation2Request', 'tns:operation2Response'); -// $this->wsdl->addPortOperation($portType, 'operation3', 'tns:operation3Request', 'tns:operation3Response', 'tns:operation3Fault'); - $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType[@name="'.$portName.'"]'); $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); - $operation1Nodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $portTypeNodes->item(0)); - $this->assertGreaterThan(0, $operation1Nodes->length); - if (empty($inputRequest)) { - $this->assertFalse($operation1Nodes->item(0)->hasChildNodes()); + $operationNodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $portTypeNodes->item(0)); + $this->assertGreaterThan(0, $operationNodes->length); + + if (empty($inputRequest) AND empty($outputResponse) AND empty($fail)) { + $this->assertFalse($operationNodes->item(0)->hasChildNodes()); } else { - $this->assertTrue($operation1Nodes->item(0)->hasChildNodes()); + $this->assertTrue($operationNodes->item(0)->hasChildNodes()); + } - $inputNodes = $operation1Nodes->item(0)->getElementsByTagName('input'); + if (!empty($inputRequest)) { + $inputNodes = $operationNodes->item(0)->getElementsByTagName('input'); $this->assertEquals($inputRequest, $inputNodes->item(0)->getAttribute('message')); } + if (!empty($outputResponse)) { + $outputNodes = $operationNodes->item(0)->getElementsByTagName('output'); + $this->assertEquals($outputResponse, $outputNodes->item(0)->getAttribute('message')); + } -// $inputNodes = $operation2Nodes->item(0)->getElementsByTagName('input'); -// $this->assertEquals(1, $inputNodes->length); -// -// -// $outputNodes = $operation2Nodes->item(0)->getElementsByTagName('output'); -// $this->assertEquals(1, $outputNodes->length); -// $this->assertEquals('tns:operation2Response', $outputNodes->item(0)->getAttribute('message')); -// -// -// $operation3Nodes = $this->xpath->query('wsdl:operation[@name="operation3"]', $portTypeNodes->item(0)); -// $this->assertEquals(1, $operation3Nodes->length); -// -// $inputNodes = $operation3Nodes->item(0)->getElementsByTagName('input'); -// $this->assertEquals(1, $inputNodes->length); -// $this->assertEquals('tns:operation3Request', $inputNodes->item(0)->getAttribute('message')); -// -// $outputNodes = $operation3Nodes->item(0)->getElementsByTagName('output'); -// $this->assertEquals(1, $outputNodes->length); -// $this->assertEquals('tns:operation3Response', $outputNodes->item(0)->getAttribute('message')); -// -// $faultNodes = $operation3Nodes->item(0)->getElementsByTagName('fault'); -// $this->assertEquals(1, $faultNodes->length); -// $this->assertEquals('tns:operation3Fault', $faultNodes->item(0)->getAttribute('message')); + //@todo fault array + if (!empty($fail)) { + $faultNodes = $operationNodes->item(0)->getElementsByTagName('fault'); + $this->assertEquals($fail, $faultNodes->item(0)->getAttribute('message')); + } } /** @@ -227,14 +231,15 @@ function testAddPortOperation($operationName, $inputRequest = null, $inputReques */ function dataProviderForAddPortOperation() { - return array( - array('operation1'), - array('operation2', 'tns:operation2Request', 'tns:operation2Response'), - ); - - - + array('operation'), + array('operation', 'tns:operationRequest', 'tns:operationResponse'), + array('operation', 'tns:operationRequest', 'tns:operationResponse', 'tns:operationFault'), + array('operation', 'tns:operationRequest', null, 'tns:operationFault'), + array('operation', null, null, 'tns:operationFault'), + array('operation', null, 'tns:operationResponse', 'tns:operationFault'), + array('operation', null, 'tns:operationResponse'), + ); } function testAddBinding() @@ -252,120 +257,100 @@ function testAddBinding() $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'type')); } - function testAddBindingOperation() + /** + * @dataProvider dataProviderForAddBindingOperation + * + * @param $operationName + * @param null $input + * @param null $inputEncoding + * @param null $output + * @param null $outputEncoding + * @param null $fault + * @param null $faultEncoding + * @param null $faultName + */ + function testAddBindingOperation($operationName, + $input = null, $inputEncoding = null, + $output = null, $outputEncoding = null, + $fault = null, $faultEncoding = null, $faultName = null) { - - - $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->wsdl->addBindingOperation($binding, 'operation1'); + $inputArray = array(); + if (!empty($input) AND !empty($inputEncoding)) { + $inputArray = array('use' => $input, 'encodingStyle' => $inputEncoding); + } - $encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"; - $this->wsdl->addBindingOperation($binding, - 'operation2', - array('use' => 'encoded', 'encodingStyle' => $encodingStyle), - array('use' => 'encoded', 'encodingStyle' => $encodingStyle) - ); + $outputArray = array(); + if (!empty($output) AND !empty($outputEncoding)) { + $outputArray = array('use' => $output, 'encodingStyle' => $outputEncoding); + } + $faultArray = array(); + if (!empty($fault) AND !empty($faultEncoding) AND !empty($faultName)) { + $faultArray = array('use' => $fault, 'encodingStyle' => $faultEncoding, 'name'=>$faultName); + } - $this->wsdl->addBindingOperation($binding, - 'operation3', - array('use' => 'encoded', 'encodingStyle' => $encodingStyle), - array('use' => 'encoded', 'encodingStyle' => $encodingStyle), - array('use' => 'encoded', 'encodingStyle' => $encodingStyle, 'name' => 'MyFault',) - ); + $this->wsdl->addBindingOperation($binding, + $operationName, + $inputArray, + $outputArray, + $faultArray + ); $bindingNodes = $this->xpath->query('//wsdl:binding'); - if ($bindingNodes->length === 0) { - $this->fail('Missing binding node in definitions node.'.$bindingNodes->length); - } + $this->assertGreaterThan(0, $bindingNodes->length, 'Missing binding node in definition.'); $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'type')); + $operationNodes = $this->xpath->query('//wsdl:operation[@name="'.$operationName.'"]', $bindingNodes->item(0)); + $this->assertEquals(1, $operationNodes->length, 'Missing operation node in definition.'); - $operation1Nodes = $this->xpath->query('//wsdl:operation[@name="operation1"]', $bindingNodes->item(0)); - $this->assertEquals(1, $operation1Nodes->length); - //@todo namespace ? - $this->assertFalse($operation1Nodes->item(0)->hasChildNodes()); + if (empty($inputArray) AND empty($outputArray) AND empty($faultArray)) { + $this->assertFalse($operationNodes->item(0)->hasChildNodes()); + } - $inputBodyNodes = $this->xpath->query('//wsdl:operation[@name="operation2"]/wsdl:input/soap:body', $bindingNodes->item(0)); - if ($inputBodyNodes->length === 0){ - $this->fail('Unable to find body in binding operation node'); - } - $this->assertEquals('encoded', $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'use')); - $this->assertEquals($encodingStyle, $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'encodingStyle')); - - foreach(array('input', 'output') as $direction) { - foreach(array('operation2', 'operation3') as $operation) { - $inputBodyNodes = $this->xpath->query('//wsdl:operation[@name="'.$operation.'"]/wsdl:'.$direction.'/soap:body', $bindingNodes->item(0)); - if ($inputBodyNodes->length === 0){ - $this->fail('Unable to find body in binding '.$operation.' node'); - } - $this->assertEquals('encoded', $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'use')); - $this->assertEquals($encodingStyle, $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'encodingStyle')); - } - } + foreach (array( + '//wsdl:input/soap:body' => $inputArray, + '//wsdl:output/soap:body' => $outputArray, + '//wsdl:fault' => $faultArray + ) as $query => $ar) { - $faultNodes = $this->xpath->query('//wsdl:operation[@name="operation3"]/wsdl:fault', $bindingNodes->item(0)); - if ($faultNodes->length === 0){ - $this->fail('Unable to find fault operation node'); - } - $this->assertEquals('encoded', $faultNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'use')); - $this->assertEquals('MyFault', $faultNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); - $this->assertEquals($encodingStyle, $faultNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'encodingStyle')); + if (!empty($ar)) { + $nodes = $this->xpath->query($query); + $this->assertGreaterThan(0, $nodes->length, 'Missing operation body.'); -// $this->wsdl->toDomDocument()->formatOutput = true; -// print ($this->wsdl->toDomDocument()->saveXML());exit; + foreach ($ar as $key => $val) { + $this->assertEquals($ar[$key], $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, $key), + 'Bad attribute in operation definition: '.$key); + } + } + } + print_r($this->wsdl->toXML()); -// $inputBodyNodes = $this->xpath->query('//wsdl:operation[@name="operation3"]/wsdl:input/soap:body', $bindingNodes->item(0)); -// if ($inputBodyNodes->length === 0){ -// $this->fail('Unable to find body in binding operation node'); -// } -// $this->assertEquals('encoded', $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'use')); -// $this->assertEquals($encodingStyle, $inputBodyNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'encodingStyle')); + } + /** + * + */ + public function dataProviderForAddBindingOperation() { + $enc = 'http://schemas.xmlsoap.org/soap/encoding/'; + return array( + array('operation'), + array('operation', 'encoded', $enc, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), + array('operation', null, null, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), + array('operation', null, null, 'encoded', $enc, 'encoded'), + array('operation', 'encoded', $enc), + array('operation', null, null, null, null, 'encoded', $enc, 'myFaultName'), + ); + } - ($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()). - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' ); - } function testAddSoapBinding() { From 1da0383ebf3d4de8f397aa011abedd5e2b4386a8 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Sun, 24 Feb 2013 10:03:01 +0100 Subject: [PATCH 04/22] Old files removed --- test/AutoDiscover/OnlineTest.php | 71 ++ test/AutoDiscoverTest.php | 743 +++++++++++++++ test/ClientTest.php | 523 +++++++++++ test/Server/DocumentLiteralWrapperTest.php | 45 + test/Server/_files/calculator.wsdl | 52 + test/ServerTest.php | 889 ++++++++++++++++++ test/TestAsset/MyCalculatorService.php | 29 + test/TestAsset/WsdlTestClass.php | 27 + test/TestAsset/cert_file | 0 test/TestAsset/commontypes.php | 636 +++++++++++++ test/TestAsset/fulltests/server1.php | 81 ++ test/TestAsset/fulltests/server2.php | 58 ++ test/TestAsset/validate.wsdl | 2 - test/TestAsset/wsdl_documentation.wsdl | 106 +++ test/TestAsset/wsdl_example.wsdl | 2 + test/Wsdl/ArrayOfTypeComplexStrategyTest.php | 201 ++++ test/Wsdl/ArrayOfTypeSequenceStrategyTest.php | 149 +++ test/Wsdl/CompositeStrategyTest.php | 129 +++ test/Wsdl/DefaultComplexTypeTest.php | 75 ++ test/WsdlTest.php | 656 ++++++------- test/_files/cert_file | 0 test/_files/commontypes.php | 435 +++++++++ test/_files/fulltests/server1.php | 83 ++ test/_files/fulltests/server2.php | 60 ++ test/_files/wsdl_documentation.wsdl | 106 +++ test/_files/wsdl_example.wsdl | 2 + test/schemas/wsdl.xsd | 334 +++++++ 27 files changed, 5101 insertions(+), 393 deletions(-) create mode 100644 test/AutoDiscover/OnlineTest.php create mode 100644 test/AutoDiscoverTest.php create mode 100644 test/ClientTest.php create mode 100644 test/Server/DocumentLiteralWrapperTest.php create mode 100644 test/Server/_files/calculator.wsdl create mode 100644 test/ServerTest.php create mode 100644 test/TestAsset/MyCalculatorService.php create mode 100644 test/TestAsset/WsdlTestClass.php create mode 100644 test/TestAsset/cert_file create mode 100644 test/TestAsset/commontypes.php create mode 100644 test/TestAsset/fulltests/server1.php create mode 100644 test/TestAsset/fulltests/server2.php delete mode 100755 test/TestAsset/validate.wsdl create mode 100644 test/TestAsset/wsdl_documentation.wsdl create mode 100644 test/TestAsset/wsdl_example.wsdl create mode 100644 test/Wsdl/ArrayOfTypeComplexStrategyTest.php create mode 100644 test/Wsdl/ArrayOfTypeSequenceStrategyTest.php create mode 100644 test/Wsdl/CompositeStrategyTest.php create mode 100644 test/Wsdl/DefaultComplexTypeTest.php mode change 100755 => 100644 test/WsdlTest.php create mode 100644 test/_files/cert_file create mode 100644 test/_files/commontypes.php create mode 100644 test/_files/fulltests/server1.php create mode 100644 test/_files/fulltests/server2.php create mode 100644 test/_files/wsdl_documentation.wsdl create mode 100644 test/_files/wsdl_example.wsdl create mode 100644 test/schemas/wsdl.xsd diff --git a/test/AutoDiscover/OnlineTest.php b/test/AutoDiscover/OnlineTest.php new file mode 100644 index 00000000..b77d55c6 --- /dev/null +++ b/test/AutoDiscover/OnlineTest.php @@ -0,0 +1,71 @@ +markTestSkipped('The constant TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI has to be defined to allow the Online test to work.'); + } + $this->baseuri = TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI; + } + + public function testNestedObjectArrayResponse() + { + $wsdl = $this->baseuri."/server1.php?wsdl"; + + $b = new \ZendTest_Soap_TestAsset_ComplexTypeB(); + $b->bar = "test"; + $b->foo = "test"; + + $client = new Client($wsdl); + $ret = $client->request($b); + + $this->assertTrue( is_array($ret) ); + $this->assertEquals(1, count($ret) ); + $this->assertTrue( is_array($ret[0]->baz) ); + $this->assertEquals(3, count($ret[0]->baz) ); + + $baz = $ret[0]->baz; + $this->assertEquals("bar", $baz[0]->bar); + $this->assertEquals("bar", $baz[0]->foo); + $this->assertEquals("foo", $baz[1]->bar); + $this->assertEquals("foo", $baz[1]->foo); + $this->assertEquals("test", $baz[2]->bar); + $this->assertEquals("test", $baz[2]->foo); + } + + public function testObjectResponse() + { + $wsdl = $this->baseuri."/server2.php?wsdl"; + + $client = new Client($wsdl); + $ret = $client->request("test", "test"); + + $this->assertTrue( ($ret instanceof \stdClass) ); + $this->assertEquals("test", $ret->foo); + $this->assertEquals("test", $ret->bar); + } +} diff --git a/test/AutoDiscoverTest.php b/test/AutoDiscoverTest.php new file mode 100644 index 00000000..098511c9 --- /dev/null +++ b/test/AutoDiscoverTest.php @@ -0,0 +1,743 @@ +setUri('http://localhost/my_script.php'); + $server->setServiceName('TestService'); + return $server; + } + + protected function sanitizeWsdlXmlOutputForOsCompability($xmlstring) + { + $xmlstring = str_replace(array("\r", "\n"), "", $xmlstring); + $xmlstring = preg_replace('/(>[\s]{1,}<)/', '', $xmlstring); + return $xmlstring; + } + + /** + * Assertion to validate DOMDocument is a valid WSDL file. + * + * @param \DOMDocument $dom + */ + protected function assertValidWSDL(\DOMDocument $dom) + { + // this code is necessary to support some libxml stupidities. + $file = __DIR__.'/TestAsset/validate.wsdl'; + if (file_exists($file)) { + unlink($file); + } + + $dom->save($file); + $dom = new \DOMDocument(); + $dom->load($file); + + $this->assertTrue($dom->schemaValidate(__DIR__ .'/schemas/wsdl.xsd'), "WSDL Did not validate"); + unlink($file); + } + + public function testSetClass() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->setClass('\ZendTest\Soap\TestAsset\Test'); + $dom = $server->generate()->toDomDocument(); + + $wsdl = '' + . '' + . '' + . '' + . '' + . '' + . '' + . 'Test Function 1' + . '' + . '' + . '' + . '' + . 'Test Function 2' + . '' + . '' + . '' + . '' + . 'Test Function 3' + . '' + . '' + . '' + . 'Test Function 4' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . ''; + + $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); + $this->assertValidWSDL($dom); + } + + public function testSetClassWithDifferentStyles() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com')); + $server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com')); + $server->setClass('\ZendTest\Soap\TestAsset\Test'); + $dom = $server->generate()->toDomDocument(); + + $wsdl = '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . 'Test Function 1' + . '' + . '' + . '' + . '' + . 'Test Function 2' + . '' + . '' + . '' + . '' + . 'Test Function 3' + . '' + . '' + . '' + . 'Test Function 4' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . ''; + + $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); + $this->assertValidWSDL($dom); + } + + /** + * @group ZF-5072 + */ + public function testSetClassWithResponseReturnPartCompabilityMode() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->setClass('\ZendTest\Soap\TestAsset\Test'); + $dom = $server->generate()->toDomDocument(); + + $dom->save(__DIR__.'/TestAsset/setclass.wsdl'); + $this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); + $this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); + $this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); + $this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); + + unlink(__DIR__.'/TestAsset/setclass.wsdl'); + } + + public function testAddFunctionSimple() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + $dom = $server->generate()->toDomDocument(); + + $name = "TestService"; + + $wsdl = ''. + ''. + ''. + ''. + 'Test Function'. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''; + $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated"); + $this->assertValidWSDL($dom); + } + + public function testAddFunctionSimpleWithDifferentStyle() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com')); + $server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com')); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + $dom = $server->generate()->toDomDocument(); + + $name = "TestService"; + $wsdl = ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + 'Test Function'. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''; + $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated"); + $this->assertValidWSDL($dom); + } + + /** + * @group ZF-5072 + */ + public function testAddFunctionSimpleInReturnNameCompabilityMode() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + $dom = $server->generate()->toDomDocument(); + + $name = "TestService"; + + $wsdl = $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()); + $this->assertContains('', $wsdl); + $this->assertNotContains('assertValidWSDL($dom); + } + + public function testAddFunctionMultiple() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc2'); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc3'); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc4'); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc5'); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc6'); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc7'); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc9'); + + $dom = $server->generate()->toDomDocument(); + + $name = "TestService"; + + $wsdl = ''. + ''. + ''. + ''. + 'Test Function'. + 'Test Function 2'. + 'Return false'. + 'Return true'. + 'Return integer'. + 'Return string'. + 'Return array'. + 'Multiple Args'. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''; + $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Generated WSDL did not match expected XML"); + $this->assertValidWSDL($dom); + } + + /** + * @group ZF-4117 + */ + public function testChangeWsdlUriInConstructor() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = new AutoDiscover(null, "http://example.com/service.php"); + $server->setServiceName("TestService"); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + $wsdlOutput = $server->toXml(); + + $this->assertNotContains($scriptUri, $wsdlOutput); + $this->assertContains("http://example.com/service.php", $wsdlOutput); + } + + /** + * @group ZF-4117 + */ + public function testChangeWsdlUriViaSetUri() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->setUri("http://example.com/service.php"); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + $wsdlOutput = $server->toXml(); + + $this->assertNotContains($scriptUri, $wsdlOutput); + $this->assertContains("http://example.com/service.php", $wsdlOutput); + } + + public function testSetNonStringNonZendUriUriThrowsException() + { + $server = $this->createAutodiscoverService(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'No uri given to'); + $server->setUri(array("bogus")); + } + + /** + * @group ZF-4117 + */ + public function testChangingWsdlUriAfterGenerationIsPossible() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->setUri("http://example.com/service.php"); + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + $wsdlOutput = $server->toXml(); + + $this->assertNotContains($scriptUri, $wsdlOutput); + $this->assertContains("http://example.com/service.php", $wsdlOutput); + + $server->setUri("http://example2.com/service2.php"); + + $wsdlOutput = $server->toXml(); + + $this->assertNotContains($scriptUri, $wsdlOutput); + $this->assertNotContains("http://example.com/service.php", $wsdlOutput); + $this->assertContains("http://example2.com/service2.php", $wsdlOutput); + } + + /** + * @group ZF-4688 + * @group ZF-4125 + * + */ + public function testUsingClassWithMultipleMethodPrototypesProducesValidWsdl() + { + $scriptUri = 'http://localhost/my_script.php'; + + $server = $this->createAutodiscoverService(); + $server->setClass('\ZendTest\Soap\TestAsset\TestFixingMultiplePrototypes'); + + $wsdlOutput = $server->toXml(); + + $this->assertEquals(1, substr_count($wsdlOutput, '')); + $this->assertEquals(1, substr_count($wsdlOutput, '')); + } + + /** + * @group ZF-4937 + */ + public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce() + { + $server = $this->createAutodiscoverService(); + $server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + $server->setClass('\ZendTest\Soap\TestAsset\AutoDiscoverTestClass2'); + + $wsdlOutput = $server->toXml(); + + $this->assertEquals(1, + substr_count($wsdlOutput, 'wsdl:arrayType="tns:AutoDiscoverTestClass1[]"'), + 'wsdl:arrayType definition of TestClass1 has to occour once.' + ); + $this->assertEquals(1, + substr_count($wsdlOutput, ''), + '\ZendTest\Soap\TestAsset\AutoDiscoverTestClass1 has to be defined once.' + ); + $this->assertEquals(1, + substr_count($wsdlOutput, ''), + '\ZendTest\Soap\TestAsset\AutoDiscoverTestClass1 should be defined once.' + ); + $this->assertTrue( + substr_count($wsdlOutput, '') >= 1, + '\ZendTest\Soap\TestAsset\AutoDiscoverTestClass1 appears once or more than once in the message parts section.' + ); + } + + /** + * @group ZF-5604 + */ + public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayComplex() + { + $autodiscover = $this->createAutodiscoverService(); + $autodiscover->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + $autodiscover->setClass('\ZendTest\Soap\TestAsset\MyService'); + $wsdl = $autodiscover->toXml(); + + $this->assertEquals(1, substr_count($wsdl, '')); + + $this->assertEquals(0, substr_count($wsdl, 'tns:My_Response[]')); + } + + /** + * @group ZF-5430 + */ + public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArraySequence() + { + $autodiscover = $this->createAutodiscoverService(); + $autodiscover->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); + $autodiscover->setClass('\ZendTest\Soap\TestAsset\MyServiceSequence'); + $wsdl = $autodiscover->toXml(); + + $this->assertEquals(1, substr_count($wsdl, '')); + $this->assertEquals(1, substr_count($wsdl, '')); + $this->assertEquals(1, substr_count($wsdl, '')); + + $this->assertEquals(0, substr_count($wsdl, 'tns:string[]')); + } + + /** + * @group ZF-5736 + */ + public function testAmpersandInUrlIsCorrectlyEncoded() + { + $autodiscover = new AutoDiscover(); + $autodiscover->setUri("http://example.com/?a=b&b=c"); + + $autodiscover->setClass('\ZendTest\Soap\TestAsset\Test'); + $wsdl = $autodiscover->toXml(); + + $this->assertContains("http://example.com/?a=b&b=c", $wsdl); + } + + /** + * @group ZF-6689 + */ + public function testNoReturnIsOneWayCallInSetClass() + { + $autodiscover = $this->createAutodiscoverService(); + $autodiscover->setClass('\ZendTest\Soap\TestAsset\NoReturnType'); + $wsdl = $autodiscover->toXml(); + + $this->assertContains( + '@param string $message', + $wsdl + ); + } + + /** + * @group ZF-6689 + */ + public function testNoReturnIsOneWayCallInAddFunction() + { + $autodiscover = $this->createAutodiscoverService(); + $autodiscover->setServiceName('TestService'); + $autodiscover->addFunction('\ZendTest\Soap\TestAsset\OneWay'); + $wsdl = $autodiscover->toXml(); + + $this->assertContains( + '@param string $message', + $wsdl + ); + } + + /** + * @group ZF-8948 + * @group ZF-5766 + */ + public function testRecursiveWsdlDependencies() + { + $autodiscover = $this->createAutodiscoverService(); + $autodiscover->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); + $autodiscover->setClass('\ZendTest\Soap\TestAsset\Recursion'); + $wsdl = $autodiscover->toXml(); + + // + // + // + // + // + + + $path = '//wsdl:types/xsd:schema/xsd:complexType[@name="Recursion"]/xsd:all/xsd:element[@name="recursion" and @type="tns:Recursion"]'; + $this->assertWsdlPathExists($wsdl, $path); + } + + public function assertWsdlPathExists($xml, $path) + { + $doc = new \DOMDocument('UTF-8'); + $doc->loadXML($xml); + + $xpath = new \DOMXPath($doc); + $xpath->registerNamespace('wsdl', 'http://schemas.xmlsoap.org/wsdl/'); + + $nodes = $xpath->query($path); + + $this->assertTrue($nodes->length >= 1, "Could not assert that XML Document contains a node that matches the XPath Expression: " . $path); + } +} diff --git a/test/ClientTest.php b/test/ClientTest.php new file mode 100644 index 00000000..2c3a7222 --- /dev/null +++ b/test/ClientTest.php @@ -0,0 +1,523 @@ +markTestSkipped('SOAP Extension is not loaded'); + } + } + + public function testSetOptions() + { + /************************************************************* + * ------ Test WSDL mode options ----------------------------- + *************************************************************/ + $client = new Client(); + + $this->assertTrue($client->getOptions() == array('encoding' => 'UTF-8', 'soap_version' => SOAP_1_2)); + + $ctx = stream_context_create(); + + $nonWSDLOptions = array('soap_version' => SOAP_1_1, + 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',), + 'encoding' => 'ISO-8859-1', + 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'location' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'use' => SOAP_ENCODED, + 'style' => SOAP_RPC, + + 'login' => 'http_login', + 'password' => 'http_password', + + 'proxy_host' => 'proxy.somehost.com', + 'proxy_port' => 8080, + 'proxy_login' => 'proxy_login', + 'proxy_password' => 'proxy_password', + + 'local_cert' => __DIR__.'/TestAsset/cert_file', + 'passphrase' => 'some pass phrase', + + 'stream_context' => $ctx, + 'cache_wsdl' => 8, + 'features' => 4, + + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5); + + $client->setOptions($nonWSDLOptions); + $this->assertTrue($client->getOptions() == $nonWSDLOptions); + + /************************************************************* + * ------ Test non-WSDL mode options ----------------------------- + *************************************************************/ + $client1 = new Client(); + + $this->assertTrue($client1->getOptions() == array('encoding' => 'UTF-8', 'soap_version' => SOAP_1_2)); + + $wsdlOptions = array('soap_version' => SOAP_1_1, + 'wsdl' => __DIR__.'/TestAsset/wsdl_example.wsdl', + 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',), + 'encoding' => 'ISO-8859-1', + + 'login' => 'http_login', + 'password' => 'http_password', + + 'proxy_host' => 'proxy.somehost.com', + 'proxy_port' => 8080, + 'proxy_login' => 'proxy_login', + 'proxy_password' => 'proxy_password', + + 'local_cert' => __DIR__.'/TestAsset/cert_file', + 'passphrase' => 'some pass phrase', + + 'stream_context' => $ctx, + + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5); + + $client1->setOptions($wsdlOptions); + $this->assertTrue($client1->getOptions() == $wsdlOptions); + } + + public function testGetOptions() + { + $client = new Client(); + + $this->assertTrue($client->getOptions() == array('encoding' => 'UTF-8', 'soap_version' => SOAP_1_2)); + + $options = array('soap_version' => SOAP_1_1, + 'wsdl' => __DIR__.'/TestAsset/wsdl_example.wsdl', + + 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',), + 'encoding' => 'ISO-8859-1', + 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'location' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'use' => SOAP_ENCODED, + 'style' => SOAP_RPC, + + 'login' => 'http_login', + 'password' => 'http_password', + + 'proxy_host' => 'proxy.somehost.com', + 'proxy_port' => 8080, + 'proxy_login' => 'proxy_login', + 'proxy_password' => 'proxy_password', + + 'local_cert' => __DIR__.'/TestAsset/cert_file', + 'passphrase' => 'some pass phrase', + + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5); + + $client->setOptions($options); + $this->assertTrue($client->getOptions() == $options); + } + + /** + * @group ZF-8053 + */ + public function testGetAndSetUserAgentOption() + { + $client = new Client(); + $this->assertNull($client->getUserAgent()); + + $client->setUserAgent('agent1'); + $this->assertEquals('agent1', $client->getUserAgent()); + + $client->setOptions(array( + 'user_agent' => 'agent2' + )); + $this->assertEquals('agent2', $client->getUserAgent()); + + $client->setOptions(array( + 'useragent' => 'agent3' + )); + $this->assertEquals('agent3', $client->getUserAgent()); + + $client->setOptions(array( + 'userAgent' => 'agent4' + )); + $this->assertEquals('agent4', $client->getUserAgent()); + + $options = $client->getOptions(); + $this->assertEquals('agent4', $options['user_agent']); + } + + /** + * @group ZF-6954 + */ + public function testUserAgentAllowsEmptyString() + { + $client = new Client(); + $this->assertNull($client->getUserAgent()); + $options = $client->getOptions(); + $this->assertArrayNotHasKey('user_agent', $options); + + $client->setUserAgent(''); + $this->assertEquals('', $client->getUserAgent()); + $options = $client->getOptions(); + $this->assertEquals('', $options['user_agent']); + + $client->setUserAgent(null); + $this->assertNull($client->getUserAgent()); + $options = $client->getOptions(); + $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'); + $server->setClass('\ZendTest\Soap\TestAsset\TestClass'); + + $client = new Client\Local($server, __DIR__ . '/TestAsset/wsdl_example.wsdl'); + + $this->assertTrue($client->getFunctions() == array('string testFunc()', + 'string testFunc2(string $who)', + 'string testFunc3(string $who, int $when)', + 'string testFunc4()')); + } + + /** + * @todo Implement testGetTypes(). + */ + public function testGetTypes() + { + // Remove the following line when you implement this test. + $this->markTestIncomplete( + "This test has not been implemented yet." + ); + } + + public function testGetLastRequest() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run testGetLastRequest() when headers have already been sent; enable output buffering to run this test'); + + return; + } + + $server = new Server(__DIR__ . '/TestAsset/wsdl_example.wsdl'); + $server->setClass('\ZendTest\Soap\TestAsset\TestClass'); + + $client = new Client\Local($server, __DIR__ . '/TestAsset/wsdl_example.wsdl'); + + // Perform request + $client->testFunc2('World'); + + $expectedRequest = '' . "\n" + . '' + . '' + . '' + . 'World' + . '' + . '' + . '' . "\n"; + + $this->assertEquals($client->getLastRequest(), $expectedRequest); + } + + public function testGetLastResponse() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run testGetLastResponse() when headers have already been sent; enable output buffering to run this test'); + + return; + } + + $server = new Server(__DIR__ . '/TestAsset/wsdl_example.wsdl'); + $server->setClass('\ZendTest\Soap\TestAsset\TestClass'); + + $client = new Client\Local($server, __DIR__ . '/TestAsset/wsdl_example.wsdl'); + + // Perform request + $client->testFunc2('World'); + + $expectedResponse = '' . "\n" + . '' + . '' + . '' + . 'testFunc2Return' + . 'Hello World!' + . '' + . '' + . '' . "\n"; + + $this->assertEquals($client->getLastResponse(), $expectedResponse); + } + + public function testCallInvoke() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run testCallInvoke() when headers have already been sent; enable output buffering to run this test'); + + return; + } + + $server = new Server(__DIR__ . '/TestAsset/wsdl_example.wsdl'); + $server->setClass('\ZendTest\Soap\TestAsset\TestClass'); + + $client = new Client\Local($server, __DIR__ . '/TestAsset/wsdl_example.wsdl'); + + $this->assertEquals($client->testFunc2('World'), 'Hello World!'); + } + + public function testCallDirect() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run testCallInvoke() when headers have already been sent; enable output buffering to run this test'); + + return; + } + + $server = new Server(__DIR__ . '/TestAsset/wsdl_example.wsdl'); + $server->setClass('\ZendTest\Soap\TestAsset\TestClass'); + + $client = new Client\Local($server, __DIR__ . '/TestAsset/wsdl_example.wsdl'); + + $this->assertEquals($client->call('testFunc2', array('World')), 'Hello World!'); + } + + public function testCallDirectWithArgString() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run testCallInvoke() when headers have already been sent; enable output buffering to run this test'); + + return; + } + + $server = new Server(__DIR__ . '/TestAsset/wsdl_example.wsdl'); + $server->setClass('\ZendTest\Soap\TestAsset\TestClass'); + + $client = new Client\Local($server, __DIR__ . '/TestAsset/wsdl_example.wsdl'); + + $this->assertEquals($client->call('testFunc2', 'World'), 'Hello World!'); + } + + public function testSetOptionsWithZendConfig() + { + $ctx = stream_context_create(); + + $nonWSDLOptions = array('soap_version' => SOAP_1_1, + 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',), + 'encoding' => 'ISO-8859-1', + 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'location' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'use' => SOAP_ENCODED, + 'style' => SOAP_RPC, + + 'login' => 'http_login', + 'password' => 'http_password', + + 'proxy_host' => 'proxy.somehost.com', + 'proxy_port' => 8080, + 'proxy_login' => 'proxy_login', + 'proxy_password' => 'proxy_password', + + 'local_cert' => __DIR__.'/TestAsset/cert_file', + 'passphrase' => 'some pass phrase', + + 'stream_context' => $ctx, + + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5 + ); + + $config = new \Zend\Config\Config($nonWSDLOptions); + + $client = new Client(null, $config); + + $this->assertEquals($nonWSDLOptions, $client->getOptions()); + } + + public function testSetInputHeaders() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run testSetInputHeaders() when headers have already been sent; enable output buffering to run this test'); + + return; + } + + $server = new Server(__DIR__ . '/TestAsset/wsdl_example.wsdl'); + $server->setClass('\ZendTest\Soap\TestAsset\TestClass'); + + $client = new Client\Local($server, __DIR__ . '/TestAsset/wsdl_example.wsdl'); + + // Add request header + $client->addSoapInputHeader(new \SoapHeader('http://www.example.com/namespace', 'MyHeader1', 'SOAP header content 1')); + // Add permanent request header + $client->addSoapInputHeader(new \SoapHeader('http://www.example.com/namespace', 'MyHeader2', 'SOAP header content 2'), true); + + // Perform request + $client->testFunc2('World'); + + $expectedRequest = '' . "\n" + . '' + . '' + . 'SOAP header content 2' + . 'SOAP header content 1' + . '' + . '' + . '' + . 'World' + . '' + . '' + . '' . "\n"; + + $this->assertEquals($client->getLastRequest(), $expectedRequest); + + // Add request header + $client->addSoapInputHeader(new \SoapHeader('http://www.example.com/namespace', 'MyHeader3', 'SOAP header content 3')); + + // Perform request + $client->testFunc2('World'); + + $expectedRequest = '' . "\n" + . '' + . '' + . 'SOAP header content 2' + . 'SOAP header content 3' + . '' + . '' + . '' + . 'World' + . '' + . '' + . '' . "\n"; + + $this->assertEquals($client->getLastRequest(), $expectedRequest); + + $client->resetSoapInputHeaders(); + + // Add request header + $client->addSoapInputHeader(new \SoapHeader('http://www.example.com/namespace', 'MyHeader4', 'SOAP header content 4')); + + // Perform request + $client->testFunc2('World'); + + $expectedRequest = '' . "\n" + . '' + . '' + . 'SOAP header content 4' + . '' + . '' + . '' + . 'World' + . '' + . '' + . '' . "\n"; + + $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 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 Client(); + $soap->setSoapClient($clientMock); + + $this->assertSame($clientMock, $soap->getSoapClient()); + } +} diff --git a/test/Server/DocumentLiteralWrapperTest.php b/test/Server/DocumentLiteralWrapperTest.php new file mode 100644 index 00000000..a19c801c --- /dev/null +++ b/test/Server/DocumentLiteralWrapperTest.php @@ -0,0 +1,45 @@ +setObject(new DocumentLiteralWrapper(new MyCalculatorService)); + + // The local client needs an abstraction for this pattern as well. + // This is just a test so we use the messy way. + $client = new SoapClient($server, __DIR__ . self::WSDL); + $ret = $client->add(array('x' => 10, 'y' => 20)); + + $this->assertInstanceOf('stdClass', $ret); + $this->assertEquals(30, $ret->addResult); + } +} diff --git a/test/Server/_files/calculator.wsdl b/test/Server/_files/calculator.wsdl new file mode 100644 index 00000000..4d170db4 --- /dev/null +++ b/test/Server/_files/calculator.wsdl @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + @param int $x + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/ServerTest.php b/test/ServerTest.php new file mode 100644 index 00000000..8183b4ae --- /dev/null +++ b/test/ServerTest.php @@ -0,0 +1,889 @@ +markTestSkipped('SOAP Extension is not loaded'); + } + } + + public function testSetOptions() + { + $server = new Server(); + + $this->assertTrue($server->getOptions() == array('soap_version' => SOAP_1_2)); + + $options = array('soap_version' => SOAP_1_1, + 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',), + 'encoding' => 'ISO-8859-1', + 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php' + ); + $server->setOptions($options); + + $this->assertTrue($server->getOptions() == $options); + } + + public function testSetOptionsViaSecondConstructorArgument() + { + $options = array( + 'soap_version' => SOAP_1_1, + 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'classmap' => array( + 'TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2', + ), + 'encoding' => 'ISO-8859-1', + 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + ); + $server = new Server(null, $options); + + $this->assertTrue($server->getOptions() == $options); + } + + /** + * @group ZF-9816 + */ + public function testSetOptionsWithFeaturesOption() + { + $server = new Server(null, array( + 'features' => SOAP_SINGLE_ELEMENT_ARRAYS + )); + + $this->assertEquals( + SOAP_SINGLE_ELEMENT_ARRAYS, + $server->getSoapFeatures() + ); + } + + public function testSetWsdlViaOptionsArrayIsPossible() + { + $server = new Server(); + $server->setOptions(array('wsdl' => 'http://www.example.com/test.wsdl')); + + $this->assertEquals('http://www.example.com/test.wsdl', $server->getWSDL()); + } + + public function testGetOptions() + { + $server = new Server(); + + $this->assertTrue($server->getOptions() == array('soap_version' => SOAP_1_2)); + + $options = array('soap_version' => SOAP_1_1, + 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php' + ); + $server->setOptions($options); + + $this->assertTrue($server->getOptions() == $options); + } + + public function testEncoding() + { + $server = new Server(); + + $this->assertNull($server->getEncoding()); + $server->setEncoding('ISO-8859-1'); + $this->assertEquals('ISO-8859-1', $server->getEncoding()); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid encoding specified'); + $server->setEncoding(array('UTF-8')); + } + + public function testSoapVersion() + { + $server = new Server(); + + $this->assertEquals(SOAP_1_2, $server->getSoapVersion()); + $server->setSoapVersion(SOAP_1_1); + $this->assertEquals(SOAP_1_1, $server->getSoapVersion()); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid soap version specified'); + $server->setSoapVersion('bogus'); + } + + public function testValidateUrn() + { + $server = new Server(); + $this->assertTrue($server->validateUrn('http://framework.zend.com/')); + $this->assertTrue($server->validateUrn('urn:soapHandler/GetOpt')); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid URN'); + $server->validateUrn('bogosity'); + } + + public function testSetActor() + { + $server = new Server(); + + $this->assertNull($server->getActor()); + $server->setActor('http://framework.zend.com/'); + $this->assertEquals('http://framework.zend.com/', $server->getActor()); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid URN'); + $server->setActor('bogus'); + } + + public function testGetActor() + { + $server = new Server(); + + $this->assertNull($server->getActor()); + $server->setActor('http://framework.zend.com/'); + $this->assertEquals('http://framework.zend.com/', $server->getActor()); + } + + public function testSetUri() + { + $server = new Server(); + + $this->assertNull($server->getUri()); + $server->setUri('http://framework.zend.com/'); + $this->assertEquals('http://framework.zend.com/', $server->getUri()); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid URN'); + $server->setUri('bogus'); + } + + public function testGetUri() + { + $server = new Server(); + + $this->assertNull($server->getUri()); + $server->setUri('http://framework.zend.com/'); + $this->assertEquals('http://framework.zend.com/', $server->getUri()); + } + + public function testSetClassmap() + { + $server = new Server(); + + $classmap = array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2'); + + $this->assertNull($server->getClassmap()); + $server->setClassmap($classmap); + $this->assertTrue($classmap == $server->getClassmap()); + } + + public function testSetClassmapThrowsExceptionOnBogusStringParameter() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Classmap must be an array'); + $server->setClassmap('bogus'); + } + + public function testSetClassmapThrowsExceptionOnBogusArrayParameter() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid class in class map'); + $server->setClassmap(array('soapTypeName', 'bogusClassName')); + } + + public function testGetClassmap() + { + $server = new Server(); + + $classmap = array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2'); + + $this->assertNull($server->getClassmap()); + $server->setClassmap($classmap); + $this->assertTrue($classmap == $server->getClassmap()); + } + + public function testSetWsdl() + { + $server = new Server(); + + $this->assertNull($server->getWSDL()); + $server->setWSDL(__DIR__.'/_files/wsdl_example.wsdl'); + $this->assertEquals(__DIR__.'/_files/wsdl_example.wsdl', $server->getWSDL()); + + //$this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'foo'); + $server->setWSDL(__DIR__.'/_files/bogus.wsdl'); + } + + public function testGetWsdl() + { + $server = new Server(); + + $this->assertNull($server->getWSDL()); + $server->setWSDL(__DIR__.'/_files/wsdl_example.wsdl'); + $this->assertEquals(__DIR__.'/_files/wsdl_example.wsdl', $server->getWSDL()); + } + + public function testAddFunction() + { + $server = new Server(); + + // Correct function should pass + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + // Array of correct functions should pass + $functions = array('\ZendTest\Soap\TestAsset\TestFunc2', + '\ZendTest\Soap\TestAsset\TestFunc3', + '\ZendTest\Soap\TestAsset\TestFunc4'); + $server->addFunction($functions); + + $this->assertEquals( + array_merge(array('\ZendTest\Soap\TestAsset\TestFunc'), $functions), + $server->getFunctions() + ); + } + + public function testAddBogusFunctionAsInteger() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid function specified'); + $server->addFunction(126); + } + + public function testAddBogusFunctionsAsString() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid function specified'); + $server->addFunction('bogus_function'); + } + + public function testAddBogusFunctionsAsArray() + { + $server = new Server(); + + $functions = array('\ZendTest\Soap\TestAsset\TestFunc5', + 'bogus_function', + '\ZendTest\Soap\TestAsset\TestFunc6'); + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'One or more invalid functions specified in array'); + $server->addFunction($functions); + } + + public function testAddAllFunctionsSoapConstant() + { + $server = new Server(); + + // SOAP_FUNCTIONS_ALL as a value should pass + $server->addFunction(SOAP_FUNCTIONS_ALL); + $server->addFunction('substr'); + $this->assertEquals(array(SOAP_FUNCTIONS_ALL), $server->getFunctions()); + } + + public function testSetClass() + { + $server = new Server(); + + // Correct class name should pass + $r = $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + $this->assertSame($server, $r); + } + + /** + * @group PR-706 + */ + public function testSetClassWithObject() + { + $server = new Server(); + + // Correct class name should pass + $object = new \ZendTest\Soap\TestAsset\ServerTestClass(); + $r = $server->setClass($object); + $this->assertSame($server, $r); + } + + public function testSetClassTwiceThrowsException() + { + $server = new Server(); + $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + + $this->setExpectedException( + 'Zend\Soap\Exception\InvalidArgumentException', + 'A class has already been registered with this soap server instance' + ); + $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + } + + public function testSetClassWithArguments() + { + $server = new Server(); + + // Correct class name should pass + $r = $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass', null, 1, 2, 3, 4); + $this->assertSame($server, $r); + } + + public function testSetBogusClassWithIntegerName() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid class argument (integer)'); + $server->setClass(465); + } + + public function testSetBogusClassWithUnknownClassName() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Class "Zend_Soap_Server_Test_BogusClass" does not exist'); + $server->setClass('Zend_Soap_Server_Test_BogusClass'); + } + + /** + * @group ZF-4366 + */ + public function testSetObject() + { + $server = new Server(); + + // Correct class name should pass + $r = $server->setObject(new TestAsset\ServerTestClass()); + $this->assertSame($server, $r); + } + + /** + * @group ZF-4366 + */ + public function testSetObjectThrowsExceptionWithBadInput1() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid object argument (integer)'); + $server->setObject(465); + } + + /** + * @group ZF-4366 + */ + public function testSetObjectThrowsExceptionWithBadInput2() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid object argument (integer)'); + $int = 1; + $server->setObject($int); + } + + /** + * @group ZF-4366 + */ + public function testSetObjectThrowsExceptionWithBadInput3() + { + $server = new Server(); + + //$this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'foo'); + $server->setObject(new TestAsset\ServerTestClass()); + } + + public function testGetFunctions() + { + $server = new Server(); + + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + $functions = array('\ZendTest\Soap\TestAsset\TestFunc2', + '\ZendTest\Soap\TestAsset\TestFunc3', + '\ZendTest\Soap\TestAsset\TestFunc4'); + $server->addFunction($functions); + + $functions = array('\ZendTest\Soap\TestAsset\TestFunc3', + '\ZendTest\Soap\TestAsset\TestFunc5', + '\ZendTest\Soap\TestAsset\TestFunc6'); + $server->addFunction($functions); + + $allAddedFunctions = array( + '\ZendTest\Soap\TestAsset\TestFunc', + '\ZendTest\Soap\TestAsset\TestFunc2', + '\ZendTest\Soap\TestAsset\TestFunc3', + '\ZendTest\Soap\TestAsset\TestFunc4', + '\ZendTest\Soap\TestAsset\TestFunc5', + '\ZendTest\Soap\TestAsset\TestFunc6' + ); + $this->assertTrue($server->getFunctions() == $allAddedFunctions); + } + + public function testGetFunctionsWithClassAttached() + { + $server = new Server(); + $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + + $this->assertEquals( + array('testFunc1', 'testFunc2', 'testFunc3', 'testFunc4', 'testFunc5'), + $server->getFunctions() + ); + } + + public function testGetFunctionsWithObjectAttached() + { + $server = new Server(); + $server->setObject(new TestAsset\ServerTestClass()); + + $this->assertEquals( + array('testFunc1', 'testFunc2', 'testFunc3', 'testFunc4', 'testFunc5'), + $server->getFunctions() + ); + } + + public function testSetPersistence() + { + $server = new Server(); + + $this->assertNull($server->getPersistence()); + $server->setPersistence(SOAP_PERSISTENCE_SESSION); + $this->assertEquals(SOAP_PERSISTENCE_SESSION, $server->getPersistence()); + + $server->setPersistence(SOAP_PERSISTENCE_REQUEST); + $this->assertEquals(SOAP_PERSISTENCE_REQUEST, $server->getPersistence()); + } + + public function testSetUnknownPersistenceStateThrowsException() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid persistence mode specified'); + $server->setPersistence('bogus'); + } + + public function testGetPersistence() + { + $server = new Server(); + + $this->assertNull($server->getPersistence()); + $server->setPersistence(SOAP_PERSISTENCE_SESSION); + $this->assertEquals(SOAP_PERSISTENCE_SESSION, $server->getPersistence()); + } + + public function testGetLastRequest() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run testGetLastRequest() when headers have already been sent; enable output buffering to run this test'); + return; + } + + $server = new Server(); + $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com')); + $server->setReturnResponse(true); + + $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + + $request = + '' . "\n" + . '' + . '' + . '' + . 'World' + . '' + . '' + . '' . "\n"; + + $response = $server->handle($request); + + $this->assertEquals($request, $server->getLastRequest()); + } + + public function testSetReturnResponse() + { + $server = new Server(); + + $this->assertFalse($server->getReturnResponse()); + + $server->setReturnResponse(true); + $this->assertTrue($server->getReturnResponse()); + + $server->setReturnResponse(false); + $this->assertFalse($server->getReturnResponse()); + } + + public function testGetReturnResponse() + { + $server = new Server(); + + $this->assertFalse($server->getReturnResponse()); + + $server->setReturnResponse(true); + $this->assertTrue($server->getReturnResponse()); + } + + public function testGetLastResponse() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run testGetLastResponse() when headers have already been sent; enable output buffering to run this test'); + return; + } + + $server = new Server(); + $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com')); + $server->setReturnResponse(true); + + $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + + $request = + '' . "\n" + . '' + . '' + . '' + . 'World' + . '' + . '' + . '' . "\n"; + + $expectedResponse = + '' . "\n" + . '' + . '' + . '' + . 'Hello World!' + . '' + . '' + . '' . "\n"; + + $server->handle($request); + + $this->assertEquals($expectedResponse, $server->getResponse()); + } + + public function testHandle() + { + if (!extension_loaded('soap')) { + $this->markTestSkipped('Soap extension not loaded'); + } + + if (headers_sent()) { + $this->markTestSkipped('Cannot run testHandle() when headers have already been sent; enable output buffering to run this test'); + return; + } + + $server = new Server(); + $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com')); + + $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + + $localClient = new TestAsset\TestLocalSoapClient($server, + null, + array('location'=>'test://', + 'uri'=>'http://framework.zend.com')); + + // Local SOAP client call automatically invokes handle method of the provided SOAP server + $this->assertEquals('Hello World!', $localClient->testFunc2('World')); + + + $request = + '' . "\n" + . '' + . '' + . '' + . 'World' + . '' + . '' + . '' . "\n"; + + $expectedResponse = + '' . "\n" + . '' + . '' + . '' + . 'Hello World!' + . '' + . '' + . '' . "\n"; + + $server1 = new Server(); + $server1->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com')); + + $server1->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + $server1->setReturnResponse(true); + + $this->assertEquals($expectedResponse, $server1->handle($request)); + } + + /** + * @todo Implement testRegisterFaultException(). + */ + public function testRegisterFaultException() + { + $server = new Server(); + + $server->registerFaultException("Zend_Soap_Server_Exception"); + $server->registerFaultException(array("OutOfBoundsException", "BogusException")); + + $this->assertEquals(array( + 'Zend_Soap_Server_Exception', + 'OutOfBoundsException', + 'BogusException', + ), $server->getFaultExceptions()); + } + + /** + * @todo Implement testDeregisterFaultException(). + */ + public function testDeregisterFaultException() + { + $server = new Server(); + + $server->registerFaultException(array("OutOfBoundsException", "BogusException")); + $ret = $server->deregisterFaultException("BogusException"); + $this->assertTrue($ret); + + $this->assertEquals(array( + 'OutOfBoundsException', + ), $server->getFaultExceptions()); + + $ret = $server->deregisterFaultException("NonRegisteredException"); + $this->assertFalse($ret); + } + + /** + * @todo Implement testGetFaultExceptions(). + */ + public function testGetFaultExceptions() + { + $server = new Server(); + + $this->assertEquals(array(), $server->getFaultExceptions()); + $server->registerFaultException("Exception"); + $this->assertEquals(array("Exception"), $server->getFaultExceptions()); + } + + public function testFaultWithTextMessage() + { + $server = new Server(); + $fault = $server->fault("Faultmessage!"); + + $this->assertTrue($fault instanceof \SOAPFault); + $this->assertContains("Faultmessage!", $fault->getMessage()); + } + + public function testFaultWithUnregisteredException() + { + $server = new Server(); + $fault = $server->fault(new \Exception("MyException")); + + $this->assertTrue($fault instanceof \SOAPFault); + $this->assertContains("Unknown error", $fault->getMessage()); + $this->assertNotContains("MyException", $fault->getMessage()); + } + + public function testFaultWithRegisteredException() + { + $server = new Server(); + $server->registerFaultException("Exception"); + $fault = $server->fault(new \Exception("MyException")); + + $this->assertTrue($fault instanceof \SOAPFault); + $this->assertNotContains("Unknown error", $fault->getMessage()); + $this->assertContains("MyException", $fault->getMessage()); + } + + public function testFautlWithBogusInput() + { + $server = new Server(); + $fault = $server->fault(array("Here", "There", "Bogus")); + + $this->assertContains("Unknown error", $fault->getMessage()); + } + + /** + * @group ZF-3958 + */ + public function testFaultWithIntegerFailureCodeDoesNotBreakClassSoapFault() + { + $server = new Server(); + $fault = $server->fault("Faultmessage!", 5000); + + $this->assertTrue($fault instanceof \SOAPFault); + } + + /** + * @todo Implement testHandlePhpErrors(). + */ + public function testHandlePhpErrors() + { + $server = new Server(); + + // Remove the following line when you implement this test. + $this->markTestIncomplete( + "This test has not been implemented yet." + ); + } + + public function testLoadFunctionsIsNotImplemented() + { + $server = new Server(); + + $this->setExpectedException('Zend\Soap\Exception\RuntimeException', 'Unimplemented method'); + $server->loadFunctions("bogus"); + } + + public function testErrorHandlingOfSoapServerChangesToThrowingSoapFaultWhenInHandleMode() + { + if (headers_sent()) { + $this->markTestSkipped('Cannot run ' . __METHOD__ . '() when headers have already been sent; enable output buffering to run this test'); + return; + } + + $server = new Server(); + $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com')); + $server->setReturnResponse(true); + + // Requesting Method with enforced parameter without it. + $request = + '' . "\n" + . '' + . '' + . '' + . '' + . '' . "\n"; + + $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + $response = $server->handle($request); + + $this->assertContains( + 'ReceiverTest Message', + $response + ); + } + + /** + * @group ZF-5597 + */ + public function testServerAcceptsZendConfigObject() + { + $options = array('soap_version' => SOAP_1_1, + 'actor' => 'http://framework.zend.com/Zend_Soap_ServerTest.php', + 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', + 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',), + 'encoding' => 'ISO-8859-1', + 'uri' => 'http://framework.zend.com/Zend_Soap_ServerTest.php' + ); + $config = new \Zend\Config\Config($options); + + $server = new Server(); + $server->setOptions($config); + $this->assertEquals($options, $server->getOptions()); + } + + /** + * @group ZF-5300 + */ + public function testSetAndGetFeatures() + { + $server = new Server(); + $this->assertNull($server->getSoapFeatures()); + $server->setSoapFeatures(100); + $this->assertEquals(100, $server->getSoapFeatures()); + $options = $server->getOptions(); + $this->assertTrue(isset($options['features'])); + $this->assertEquals(100, $options['features']); + } + + /** + * @group ZF-5300 + */ + public function testSetAndGetWSDLCache() + { + $server = new Server(); + $this->assertNull($server->getWSDLCache()); + $server->setWSDLCache(100); + $this->assertEquals(100, $server->getWSDLCache()); + $options = $server->getOptions(); + $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])); + } + + /** + * @runInSeparateProcess + */ + public function testShouldThrowExceptionIfHandledRequestContainsDoctype() + { + $server = new Server(); + $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com')); + $server->setReturnResponse(true); + + $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); + + $request = + '' . "\n" . '' . "\n" + . '' + . '' + . '' + . 'World' + . '' + . '' + . '' . "\n"; + $response = $server->handle($request); + $this->assertContains('Invalid XML', $response->getMessage()); + } + +} diff --git a/test/TestAsset/MyCalculatorService.php b/test/TestAsset/MyCalculatorService.php new file mode 100644 index 00000000..04be6a59 --- /dev/null +++ b/test/TestAsset/MyCalculatorService.php @@ -0,0 +1,29 @@ + 'bar', 'baz' => true, 1 => false, 'bat' => 123); +} + +/** + * Return Object + * + * @return stdClass + */ +function TestFunc8() +{ + $return = (object) array('foo' => 'bar', 'baz' => true, 'bat' => 123, 'qux' => false); + return $return; +} + +/** + * Multiple Args + * + * @param string $foo + * @param string $bar + * @return string + */ +function TestFunc9($foo, $bar) +{ + return "$foo $bar"; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class TestFixingMultiplePrototypes +{ + /** + * Test function + * + * @param integer $a + * @param integer $b + * @param integer $d + * @return integer + */ + public function testFunc($a=100, $b=200, $d=300) + { + + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Test +{ + /** + * Test Function 1 + * + * @return string + */ + public function testFunc1() + { + return "Hello World"; + } + + /** + * Test Function 2 + * + * @param string $who Some Arg + * @return string + */ + public function testFunc2($who) + { + return "Hello $who!"; + } + + /** + * Test Function 3 + * + * @param string $who Some Arg + * @param int $when Some + * @return string + */ + public function testFunc3($who, $when) + { + return "Hello $who, How are you $when"; + } + + /** + * Test Function 4 + * + * @return string + */ + public static function testFunc4() + { + return "I'm Static!"; + } +} + +class AutoDiscoverTestClass1 +{ + /** + * @var integer $var + */ + public $var = 1; + + /** + * @var string $param + */ + public $param = "hello"; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class AutoDiscoverTestClass2 +{ + /** + * + * @param \ZendTest\Soap\TestAsset\AutoDiscoverTestClass1 $test + * @return bool + */ + public function add(AutoDiscoverTestClass1 $test) + { + return true; + } + + /** + * @return \ZendTest\Soap\TestAsset\AutoDiscoverTestClass1[] + */ + public function fetchAll() + { + return array( + new AutoDiscoverTestClass1(), + new AutoDiscoverTestClass1(), + ); + } + + /** + * @param \ZendTest\Soap\TestAsset\AutoDiscoverTestClass1[] + */ + public function addMultiple($test) + { + + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class ComplexTypeB +{ + /** + * @var string + */ + public $bar; + /** + * @var string + */ + public $foo; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class ComplexTypeA +{ + /** + * @var \ZendTest\Soap\TestAsset\ComplexTypeB[] + */ + public $baz = array(); +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class ComplexTest +{ + /** + * @var int + */ + public $var = 5; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class ComplexObjectStructure +{ + /** + * @var bool + */ + public $boolean = true; + + /** + * @var string + */ + public $string = "Hello World"; + + /** + * @var int + */ + public $int = 10; + + /** + * @var array + */ + public $array = array(1, 2, 3); +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class ComplexObjectWithObjectStructure +{ + /** + * @var \ZendTest\Soap\TestAsset\ComplexTest + */ + public $object; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class MyService +{ + /** + * @param string $foo + * @return \ZendTest\Soap\TestAsset\MyResponse[] + */ + public function foo($foo) + { + } + /** + * @param string $bar + * @return \ZendTest\Soap\TestAsset\MyResponse[] + */ + public function bar($bar) + { + } + + /** + * @param string $baz + * @return \ZendTest\Soap\TestAsset\MyResponse[] + */ + public function baz($baz) + { + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class MyServiceSequence +{ + /** + * @param string $foo + * @return string[] + */ + public function foo($foo) + { + } + /** + * @param string $bar + * @return string[] + */ + public function bar($bar) + { + } + + /** + * @param string $baz + * @return string[] + */ + public function baz($baz) + { + } + + /** + * @param string $baz + * @return string[][][] + */ + public function bazNested($baz) + { + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class MyResponse +{ + /** + * @var string + */ + public $p1; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Recursion +{ + /** + * @var \ZendTest\Soap\TestAsset\Recursion + */ + public $recursion; + + /** + * @return \ZendTest\Soap\TestAsset\Recursion + */ + public function create() {} +} + +/** + * @param string $message + */ +function OneWay($message) +{ + +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class NoReturnType +{ + /** + * + * @param string $message + */ + public function pushOneWay($message) + { + + } +} + +/* Client test classes */ +/** Test Class */ +class TestClass +{ + /** + * Test Function 1 + * + * @return string + */ + public function testFunc1() + { + return "Hello World"; + } + + /** + * Test Function 2 + * + * @param string $who Some Arg + * @return string + */ + public function testFunc2($who) + { + return "Hello $who!"; + } + + /** + * Test Function 3 + * + * @param string $who Some Arg + * @param int $when Some + * @return string + */ + public function testFunc3($who, $when) + { + return "Hello $who, How are you $when"; + } + + /** + * Test Function 4 + * + * @return string + */ + public static function testFunc4() + { + return "I'm Static!"; + } +} + +/** Test class 2 */ +class TestData1 +{ + /** + * Property1 + * + * @var string + */ + public $property1; + + /** + * Property2 + * + * @var float + */ + public $property2; +} + +/** Test class 2 */ +class TestData2 +{ + /** + * Property1 + * + * @var integer + */ + public $property1; + + /** + * Property1 + * + * @var float + */ + 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 +{ + /** + * Test Function 1 + * + * @return string + */ + public function testFunc1() + { + return "Hello World"; + } + + /** + * Test Function 2 + * + * @param string $who Some Arg + * @return string + */ + public function testFunc2($who) + { + return "Hello $who!"; + } + + /** + * Test Function 3 + * + * @param string $who Some Arg + * @param int $when Some + * @return string + */ + public function testFunc3($who, $when) + { + return "Hello $who, How are you $when"; + } + + /** + * Test Function 4 + * + * @return string + */ + public static function testFunc4() + { + return "I'm Static!"; + } + + /** + * Test Function 5 raises a user error + * + * @return void + */ + public function testFunc5() + { + trigger_error("Test Message", E_USER_ERROR); + } +} + +if (extension_loaded('soap')) { + +/** Local SOAP client */ +class TestLocalSoapClient extends \SoapClient +{ + /** + * Server object + * + * @var Zend_Soap_Server + */ + public $server; + + /** + * Local client constructor + * + * @param Zend_Soap_Server $server + * @param string $wsdl + * @param array $options + */ + public function __construct(\Zend\Soap\Server $server, $wsdl, $options) + { + $this->server = $server; + parent::__construct($wsdl, $options); + } + + public function __doRequest($request, $location, $action, $version, $one_way = 0) + { + ob_start(); + $this->server->handle($request); + $response = ob_get_clean(); + + return $response; + } +} + +} diff --git a/test/TestAsset/fulltests/server1.php b/test/TestAsset/fulltests/server1.php new file mode 100644 index 00000000..5fb76e40 --- /dev/null +++ b/test/TestAsset/fulltests/server1.php @@ -0,0 +1,81 @@ +bar = "bar"; + $b1->foo = "bar"; + $a->baz[] = $b1; + + $b2 = new ComplexTypeB(); + $b2->bar = "foo"; + $b2->foo = "foo"; + $a->baz[] = $b2; + + $a->baz[] = $request; + + return array($a); + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class ComplexTypeB +{ + /** + * @var string + */ + public $bar; + /** + * @var string + */ + public $foo; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class ComplexTypeA +{ + /** + * @var \ZendTest\Soap\TestAsset\fulltests\ComplexTypeB[] + */ + public $baz = array(); +} + +if (isset($_GET['wsdl'])) { + $server = new \Zend\Soap\AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex()); +} else { + $uri = "http://".$_SERVER['HTTP_HOST']."/".$_SERVER['PHP_SELF']."?wsdl"; + $server = new \Zend\Soap\Server($uri); +} +$server->setClass('\ZendTest\Soap\TestAsset\fulltests\Server1'); +$server->handle(); diff --git a/test/TestAsset/fulltests/server2.php b/test/TestAsset/fulltests/server2.php new file mode 100644 index 00000000..57a0b2d1 --- /dev/null +++ b/test/TestAsset/fulltests/server2.php @@ -0,0 +1,58 @@ +bar = $bar; + $b->foo = $foo; + return $b; + } +} + +if (isset($_GET['wsdl'])) { + $server = new \Zend\Soap\AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex()); +} else { + $uri = "http://".$_SERVER['HTTP_HOST']."/".$_SERVER['PHP_SELF']."?wsdl"; + $server = new \Zend\Soap\Server($uri); +} +$server->setClass('ZendTest\Soap\TestAsset\fulltests\Server2'); +$server->handle(); diff --git a/test/TestAsset/validate.wsdl b/test/TestAsset/validate.wsdl deleted file mode 100755 index 06dd899f..00000000 --- a/test/TestAsset/validate.wsdl +++ /dev/null @@ -1,2 +0,0 @@ - -Test Function diff --git a/test/TestAsset/wsdl_documentation.wsdl b/test/TestAsset/wsdl_documentation.wsdl new file mode 100644 index 00000000..18870d84 --- /dev/null +++ b/test/TestAsset/wsdl_documentation.wsdl @@ -0,0 +1,106 @@ + + + Definitions + + + Ports + + + + + + + + + + + + + + + + + + + + Bindings + + + + + + + + + Operation1 + + + + + + + + + Operation2 + + + + + + + + + Operation3 + + + + + + + + + Operation4 + + + + + + + + + + + Services + + + + + + + + Message + + + + Message + + + + Message + + + + Message + + + + + Message + + + + + Message + + + \ No newline at end of file diff --git a/test/TestAsset/wsdl_example.wsdl b/test/TestAsset/wsdl_example.wsdl new file mode 100644 index 00000000..129f28de --- /dev/null +++ b/test/TestAsset/wsdl_example.wsdl @@ -0,0 +1,2 @@ + + diff --git a/test/Wsdl/ArrayOfTypeComplexStrategyTest.php b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php new file mode 100644 index 00000000..72405fb1 --- /dev/null +++ b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php @@ -0,0 +1,201 @@ +strategy = new ArrayOfTypeComplex(); + $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php', $this->strategy); + } + + public function testNestingObjectsDeepMakesNoSenseThrowingException() + { + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than one level'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTest[][]'); + } + + public function testAddComplexTypeOfNonExistingClassThrowsException() + { + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Cannot add a complex type \ZendTest\Soap\TestAsset\UnknownClass that is not an object or where class'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\UnknownClass[]'); + } + + /** + * @group ZF-5046 + */ + public function testArrayOfSimpleObject() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTest[]'); + $this->assertEquals("tns:ArrayOfComplexTest", $return); + + $wsdl = $this->wsdl->toXML(); + + $this->assertContains( + '', + $wsdl, + $wsdl + ); + + $this->assertContains( + '', + $wsdl + ); + } + + public function testThatOverridingStrategyIsReset() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTest[]'); + $this->assertEquals("tns:ArrayOfComplexTest", $return); + // $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplexStrategy); + + $wsdl = $this->wsdl->toXML(); + } + + /** + * @group ZF-5046 + */ + public function testArrayOfComplexObjects() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectStructure[]'); + $this->assertEquals("tns:ArrayOfComplexObjectStructure", $return); + + $wsdl = $this->wsdl->toXML(); + + $this->assertContains( + '', + $wsdl, + $wsdl + ); + + $this->assertContains( + '', + $wsdl + ); + } + + public function testArrayOfObjectWithObject() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); + $this->assertEquals("tns:ArrayOfComplexObjectWithObjectStructure", $return); + + $wsdl = $this->wsdl->toXML(); + + $this->assertContains( + '', + $wsdl + ); + + $this->assertContains( + '', + $wsdl, + $wsdl + ); + + $this->assertContains( + '', + $wsdl + ); + } + + /** + * @group ZF-4937 + */ + public function testAddingTypesMultipleTimesIsSavedOnlyOnce() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); + + $wsdl = $this->wsdl->toXML(); + + $this->assertEquals(1, + substr_count($wsdl, 'wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"') + ); + $this->assertEquals(1, + substr_count($wsdl, '') + ); + $this->assertEquals(1, + substr_count($wsdl, '') + ); + } + + /** + * @group ZF-4937 + */ + public function testAddingSingularThenArrayTypeIsRecognizedCorretly() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure'); + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); + + $wsdl = $this->wsdl->toXML(); + + $this->assertEquals(1, + substr_count($wsdl, 'wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"') + ); + $this->assertEquals(1, + substr_count($wsdl, '') + ); + $this->assertEquals(1, + substr_count($wsdl, '') + ); + } + + /** + * @group ZF-5149 + */ + public function testArrayOfComplexNestedObjectsIsCoveredByStrategy() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTypeA'); + $wsdl = $this->wsdl->toXml(); + $this->assertTrue(is_string($wsdl)); // no exception was thrown + } + + /** + * @group ZF-5149 + */ + public function testArrayOfComplexNestedObjectsIsCoveredByStrategyAndAddsAllTypesRecursivly() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTypeA'); + $wsdl = $this->wsdl->toXml(); + + $this->assertEquals(1, + substr_count($wsdl, ''), + 'No definition of complex type A found.' + ); + $this->assertEquals(1, + substr_count($wsdl, ''), + 'No definition of complex type B array found.' + ); + $this->assertEquals(1, + substr_count($wsdl, 'wsdl:arrayType="tns:ComplexTypeB[]"'), + 'No usage of Complex Type B array found.' + ); + } +} diff --git a/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php new file mode 100644 index 00000000..69898f91 --- /dev/null +++ b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php @@ -0,0 +1,149 @@ +strategy = new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence(); + $this->wsdl = new \Zend\Soap\Wsdl('MyService', 'http://localhost/MyService.php', $this->strategy); + } + + public function testFunctionReturningSimpleArrayOfInts() + { + $this->wsdl->addComplexType('int[]'); + + $this->assertContains( + ''. + ''. + '', + $this->wsdl->toXML() + ); + } + + public function testFunctionReturningSimpleArrayOfString() + { + $this->wsdl->addComplexType('string[]'); + + $this->assertContains( + ''. + ''. + '', + $this->wsdl->toXML() + ); + } + + public function testFunctionReturningNestedArrayOfString() + { + $return = $this->wsdl->addComplexType('string[][]'); + $this->assertEquals('tns:ArrayOfArrayOfString', $return); + + $wsdl = $this->wsdl->toXML(); + + // Check for ArrayOfArrayOfString + $this->assertContains( + '', + $wsdl + ); + // Check for ArrayOfString + $this->assertContains( + '', + $wsdl + ); + } + + public function testFunctionReturningMultipleNestedArrayOfType() + { + $return = $this->wsdl->addComplexType('string[][][]'); + $this->assertEquals('tns:ArrayOfArrayOfArrayOfString', $return); + + $wsdl = $this->wsdl->toXML(); + + // Check for ArrayOfArrayOfArrayOfString + $this->assertContains( + '', + $wsdl + ); + // Check for ArrayOfArrayOfString + $this->assertContains( + '', + $wsdl + ); + // Check for ArrayOfString + $this->assertContains( + '', + $wsdl + ); + } + + + public function testAddComplexTypeObject() + { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\Wsdl\SequenceTest'); + + $this->assertEquals('tns:SequenceTest', $return); + + $wsdl = $this->wsdl->toXML(); + + $this->assertContains( + '', + $wsdl + ); + } + + public function testAddComplexTypeArrayOfObject() + { + + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTypeA[]'); + + $this->assertEquals('tns:ArrayOfComplexTypeA', $return); + + $wsdl = $this->wsdl->toXML(); + + $this->assertContains( + '', + $wsdl, + $wsdl + ); + + $this->assertContains( + '', + $wsdl + ); + } + + public function testAddComplexTypeOfNonExistingClassThrowsException() + { + $this->setExpectedException('\Zend\Soap\Exception\InvalidArgumentException', 'Cannot add a complex type'); + $this->wsdl->addComplexType('ZendTest\Soap\Wsdl\UnknownClass[]'); + } +} + +class SequenceTest +{ + /** + * @var int + */ + public $var = 5; +} diff --git a/test/Wsdl/CompositeStrategyTest.php b/test/Wsdl/CompositeStrategyTest.php new file mode 100644 index 00000000..090adf03 --- /dev/null +++ b/test/Wsdl/CompositeStrategyTest.php @@ -0,0 +1,129 @@ +connectTypeToStrategy('Book', new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + + $bookStrategy = $strategy->getStrategyOfType('Book'); + $cookieStrategy = $strategy->getStrategyOfType('Cookie'); + + $this->assertTrue( $bookStrategy instanceof ArrayOfTypeComplex ); + $this->assertTrue( $cookieStrategy instanceof ArrayOfTypeSequence ); + } + + public function testConstructorTypeMapSyntax() + { + $typeMap = array('Book' => '\Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex'); + + $strategy = new ComplexTypeStrategy\Composite($typeMap, new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); + + $bookStrategy = $strategy->getStrategyOfType('Book'); + $cookieStrategy = $strategy->getStrategyOfType('Cookie'); + + $this->assertTrue( $bookStrategy instanceof ArrayOfTypeComplex ); + $this->assertTrue( $cookieStrategy instanceof ArrayOfTypeSequence ); + } + + public function testCompositeThrowsExceptionOnInvalidType() + { + $strategy = new ComplexTypeStrategy\Composite(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid type given to Composite Type Map'); + $strategy->connectTypeToStrategy(array(), 'strategy'); + } + + public function testCompositeThrowsExceptionOnInvalidStrategy() + { + $strategy = new ComplexTypeStrategy\Composite(array(), 'invalid'); + $strategy->connectTypeToStrategy('Book', 'strategy'); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Strategy for Complex Type \'Book\' is not a valid strategy'); + $book = $strategy->getStrategyOfType('Book'); + } + + public function testCompositeThrowsExceptionOnInvalidStrategyPart2() + { + $strategy = new ComplexTypeStrategy\Composite(array(), 'invalid'); + $strategy->connectTypeToStrategy('Book', 'strategy'); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Default Strategy for Complex Types is not a valid strategy object'); + $book = $strategy->getStrategyOfType('Anything'); + } + + + + public function testCompositeDelegatesAddingComplexTypesToSubStrategies() + { + $strategy = new ComplexTypeStrategy\Composite(array(), new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); + $strategy->connectTypeToStrategy('\ZendTest\Soap\Wsdl\Book', new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + $strategy->connectTypeToStrategy('\ZendTest\Soap\Wsdl\Cookie', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); + + $wsdl = new Wsdl('SomeService', 'http://example.com'); + $strategy->setContext($wsdl); + + $this->assertEquals('tns:Book', $strategy->addComplexType('\ZendTest\Soap\Wsdl\Book')); + $this->assertEquals('tns:Cookie', $strategy->addComplexType('\ZendTest\Soap\Wsdl\Cookie')); + $this->assertEquals('xsd:anyType', $strategy->addComplexType('\ZendTest\Soap\Wsdl\Anything')); + } + + public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrowsException() + { + $strategy = new ComplexTypeStrategy\Composite(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Cannot add complex type \'Test\''); + $strategy->addComplexType('Test'); + } +} + +class Book +{ + /** + * @var int + */ + public $somevar; +} +class Cookie +{ + /** + * @var int + */ + public $othervar; +} +class Anything +{ +} diff --git a/test/Wsdl/DefaultComplexTypeTest.php b/test/Wsdl/DefaultComplexTypeTest.php new file mode 100644 index 00000000..39479d76 --- /dev/null +++ b/test/Wsdl/DefaultComplexTypeTest.php @@ -0,0 +1,75 @@ +strategy = new DefaultComplexType(); + $this->wsdl = new Wsdl("TestService", "http://framework.zend.com/soap/unittests"); + $this->wsdl->setComplexTypeStrategy($this->strategy); + $this->strategy->setContext($this->wsdl); + } + + /** + * @group ZF-5944 + */ + public function testOnlyPublicPropertiesAreDiscoveredByStrategy() + { + $this->strategy->addComplexType('\ZendTest\Soap\Wsdl\PublicPrivateProtected'); + + $xml = $this->wsdl->toXML(); + $this->assertNotContains( PublicPrivateProtected::PROTECTED_VAR_NAME, $xml); + $this->assertNotContains( PublicPrivateProtected::PRIVATE_VAR_NAME, $xml); + } +} + +class PublicPrivateProtected +{ + const PROTECTED_VAR_NAME = 'bar'; + const PRIVATE_VAR_NAME = 'baz'; + + /** + * @var string + */ + public $foo; + + /** + * @var string + */ + protected $bar; + + /** + * @var string + */ + private $baz; +} diff --git a/test/WsdlTest.php b/test/WsdlTest.php old mode 100755 new mode 100644 index 3704302f..213749f3 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -1,29 +1,17 @@ wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - - $this->dom = $this->wsdl->toDomDocument(); - $this->xpath = new \DOMXPath($this->dom); - $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); - - $this->xpath->registerNamespace('tns', 'http://localhost/MyService.php'); - $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); - $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); - $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); - $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + '' . + '' ); } - function testConstructor() - { - - $uri = 'http://localhost/MyService.php'; - $name = 'MyService'; - - $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri(null)); - $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); - $this->assertEquals($uri, $this->dom->lookupNamespaceUri('tns')); - $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); - $this->assertEquals(Wsdl::NS_SCHEMA, $this->dom->lookupNamespaceUri('xsd')); - $this->assertEquals(Wsdl::NS_S_ENC, $this->dom->lookupNamespaceUri('soap-enc')); - $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri('wsdl')); - - $this->assertEquals(Wsdl::NS_WSDL, $this->dom->documentElement->namespaceURI); - - $this->assertEquals($name, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'name')); - $this->assertEquals($uri, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'targetNamespace')); - - } - - function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes() - { - $newUri = 'http://localhost/MyNewService.php'; - $this->wsdl->setUri($newUri); - - $this->assertEquals($newUri, $this->dom->lookupNamespaceUri('tns')); - $this->assertEquals($newUri, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'targetNamespace')); - } - - function testSetUriWithZendUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes() + public function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes() { - $newUri = 'http://localhost/MyNewService.php'; - $this->wsdl->setUri(new Uri('http://localhost/MyNewService.php')); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl->setUri('http://localhost/MyNewService.php'); - $this->assertEquals($newUri, $this->dom->lookupNamespaceUri('tns')); - $this->assertEquals($newUri, $this->dom->documentElement->getAttributeNS(Wsdl::NS_WSDL, 'targetNamespace')); + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + '' . + '' ); } - /** - * - * @dataProvider dataProviderForAddMessage - * - * @param array $parameters - */ - function testAddMessage($parameters) + public function testAddMessage() { - $messageParts = array(); - foreach($parameters as $i => $parameter) { - $messageParts['parameter'.$i] = $this->wsdl->getType($parameter); - } - - $messageName = 'myMessage'; - - $this->wsdl->addMessage($messageName, $messageParts); - - $messageNodes = $this->xpath->query('//wsdl:definitions/wsdl:message'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertGreaterThan(0, $messageNodes->length, 'Missing message node in definitions node.'); + $messageParts = array(); + $messageParts['parameter1'] = $wsdl->getType('int'); + $messageParts['parameter2'] = $wsdl->getType('string'); + $messageParts['parameter3'] = $wsdl->getType('mixed'); - $this->assertEquals($messageName, $messageNodes->item(0)->getAttribute('name')); + $wsdl->addMessage('myMessage', $messageParts); - foreach ($messageParts as $parameterName => $parameterType) { - $part = $this->xpath->query('//wsdl:part[@name="'.$parameterName.'"]', $messageNodes->item(0)); - $this->assertEquals($parameterType, $part->item(0)->getAttribute('type')); - } + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + '' . + '' + . '' + . '' + . '' + . '' + . '' + . '' ); } - /** - * - */ - public function dataProviderForAddMessage(){ - return array( - array(array('int', 'int', 'int')), - array(array('string', 'string', 'string', 'string')), - array(array('mixed')), - array(array('int', 'int', 'string', 'string')), - array(array('int', 'string', 'int', 'string')), - ); - } - - function testAddPortType() + public function testAddPortType() { - $portName = 'myPortType'; - $this->wsdl->addPortType($portName); - - $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType'); - print $portTypeNodes->length; - - $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertTrue($portTypeNodes->item(0)->hasAttribute('name')); - $this->assertEquals($portName, $portTypeNodes->item(0)->getAttribute('name')); + $wsdl->addPortType('myPortType'); + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + '' . + '' + . '' + . '' ); } - /** - * @dataProvider dataProviderForAddPortOperation - */ - function testAddPortOperation($operationName, $inputRequest = null, $inputRequest = null, $outputResponse = null, $fail = null) + public function testAddPortOperation() { - $portName = 'myPortType'; - $portType = $this->wsdl->addPortType($portName); - - $this->wsdl->addPortOperation($portType, $operationName, $inputRequest, $outputResponse, $fail); - - $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType[@name="'.$portName.'"]'); - $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $portType = $wsdl->addPortType('myPortType'); - $operationNodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $portTypeNodes->item(0)); - $this->assertGreaterThan(0, $operationNodes->length); + $wsdl->addPortOperation($portType, 'operation1'); + $wsdl->addPortOperation($portType, 'operation2', 'tns:operation2Request', 'tns:operation2Response'); + $wsdl->addPortOperation($portType, 'operation3', 'tns:operation3Request', 'tns:operation3Response', 'tns:operation3Fault'); - if (empty($inputRequest) AND empty($outputResponse) AND empty($fail)) { - $this->assertFalse($operationNodes->item(0)->hasChildNodes()); - } else { - $this->assertTrue($operationNodes->item(0)->hasChildNodes()); - } - - if (!empty($inputRequest)) { - $inputNodes = $operationNodes->item(0)->getElementsByTagName('input'); - $this->assertEquals($inputRequest, $inputNodes->item(0)->getAttribute('message')); - } - - if (!empty($outputResponse)) { - $outputNodes = $operationNodes->item(0)->getElementsByTagName('output'); - $this->assertEquals($outputResponse, $outputNodes->item(0)->getAttribute('message')); - } - - //@todo fault array - if (!empty($fail)) { - $faultNodes = $operationNodes->item(0)->getElementsByTagName('fault'); - $this->assertEquals($fail, $faultNodes->item(0)->getAttribute('message')); - } - } - - /** - * - */ - function dataProviderForAddPortOperation() - { - return array( - array('operation'), - array('operation', 'tns:operationRequest', 'tns:operationResponse'), - array('operation', 'tns:operationRequest', 'tns:operationResponse', 'tns:operationFault'), - array('operation', 'tns:operationRequest', null, 'tns:operationFault'), - array('operation', null, null, 'tns:operationFault'), - array('operation', null, 'tns:operationResponse', 'tns:operationFault'), - array('operation', null, 'tns:operationResponse'), - ); + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + '' . + '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' ); } - function testAddBinding() + public function testAddBinding() { - $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->wsdl->toDomDocument()->formatOutput = true; + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $bindingNodes = $this->xpath->query('//wsdl:definitions/wsdl:binding'); - - if ($bindingNodes->length === 0) { - $this->fail('Missing binding node in definitions node.'.$bindingNodes->length); - } + $wsdl->addPortType('myPortType'); + $wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); - $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'type')); + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + '' . + '' + . '' + . '' + . '' ); } - /** - * @dataProvider dataProviderForAddBindingOperation - * - * @param $operationName - * @param null $input - * @param null $inputEncoding - * @param null $output - * @param null $outputEncoding - * @param null $fault - * @param null $faultEncoding - * @param null $faultName - */ - function testAddBindingOperation($operationName, - $input = null, $inputEncoding = null, - $output = null, $outputEncoding = null, - $fault = null, $faultEncoding = null, $faultName = null) + public function testAddBindingOperation() { - $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - - $inputArray = array(); - if (!empty($input) AND !empty($inputEncoding)) { - $inputArray = array('use' => $input, 'encodingStyle' => $inputEncoding); - } - - $outputArray = array(); - if (!empty($output) AND !empty($outputEncoding)) { - $outputArray = array('use' => $output, 'encodingStyle' => $outputEncoding); - } - - $faultArray = array(); - if (!empty($fault) AND !empty($faultEncoding) AND !empty($faultName)) { - $faultArray = array('use' => $fault, 'encodingStyle' => $faultEncoding, 'name'=>$faultName); - } - - $this->wsdl->addBindingOperation($binding, - $operationName, - $inputArray, - $outputArray, - $faultArray - ); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $bindingNodes = $this->xpath->query('//wsdl:binding'); - - $this->assertGreaterThan(0, $bindingNodes->length, 'Missing binding node in definition.'); - - $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'name')); - $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'type')); - - $operationNodes = $this->xpath->query('//wsdl:operation[@name="'.$operationName.'"]', $bindingNodes->item(0)); - $this->assertEquals(1, $operationNodes->length, 'Missing operation node in definition.'); - - if (empty($inputArray) AND empty($outputArray) AND empty($faultArray)) { - $this->assertFalse($operationNodes->item(0)->hasChildNodes()); - } - - foreach (array( - '//wsdl:input/soap:body' => $inputArray, - '//wsdl:output/soap:body' => $outputArray, - '//wsdl:fault' => $faultArray - ) as $query => $ar) { - - if (!empty($ar)) { - $nodes = $this->xpath->query($query); - - $this->assertGreaterThan(0, $nodes->length, 'Missing operation body.'); - - foreach ($ar as $key => $val) { - $this->assertEquals($ar[$key], $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, $key), - 'Bad attribute in operation definition: '.$key); - } - } - } + $wsdl->addPortType('myPortType'); + $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); - print_r($this->wsdl->toXML()); + $wsdl->addBindingOperation($binding, 'operation1'); + $wsdl->addBindingOperation($binding, + 'operation2', + array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), + array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") + ); + $wsdl->addBindingOperation($binding, + 'operation3', + 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()), + '' . + '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' ); } - /** - * - */ - public function dataProviderForAddBindingOperation() { - - $enc = 'http://schemas.xmlsoap.org/soap/encoding/'; - - return array( - array('operation'), - array('operation', 'encoded', $enc, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), - array('operation', null, null, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), - array('operation', null, null, 'encoded', $enc, 'encoded'), - array('operation', 'encoded', $enc), - array('operation', null, null, null, null, 'encoded', $enc, 'myFaultName'), - ); - } - - - function testAddSoapBinding() + public function testAddSoapBinding() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->wsdl->addPortType('myPortType'); - $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + $wsdl->addPortType('myPortType'); + $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->wsdl->addSoapBinding($binding); + $wsdl->addSoapBinding($binding); - $this->wsdl->addBindingOperation($binding, 'operation1'); - $this->wsdl->addBindingOperation($binding, + $wsdl->addBindingOperation($binding, 'operation1'); + $wsdl->addBindingOperation($binding, 'operation2', array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") ); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->wsdl->addPortType('myPortType'); - $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + $wsdl->addPortType('myPortType'); + $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->wsdl->addSoapOperation($binding, 'http://localhost/MyService.php#myOperation'); + $wsdl->addSoapOperation($binding, 'http://localhost/MyService.php#myOperation'); - $this->wsdl->addBindingOperation($binding, 'operation1'); - $this->wsdl->addBindingOperation($binding, + $wsdl->addBindingOperation($binding, 'operation1'); + $wsdl->addBindingOperation($binding, 'operation2', array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") ); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), '' . '' ); } - function testAddService() + public function testAddService() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->wsdl->addPortType('myPortType'); - $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + $wsdl->addPortType('myPortType'); + $wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', 'http://localhost/MyService.php'); + $wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', 'http://localhost/MyService.php'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), '' . '' ); } - function testAddDocumentation() + public function testAddDocumentation() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $portType = $this->wsdl->addPortType('myPortType'); + $portType = $wsdl->addPortType('myPortType'); - $this->wsdl->addDocumentation($portType, 'This is a description for Port Type node.'); + $wsdl->addDocumentation($portType, 'This is a description for Port Type node.'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); $messageParts = array(); - $messageParts['parameter1'] = $this->wsdl->getType('int'); - $messageParts['parameter2'] = $this->wsdl->getType('string'); - $messageParts['parameter3'] = $this->wsdl->getType('mixed'); + $messageParts['parameter1'] = $wsdl->getType('int'); + $messageParts['parameter2'] = $wsdl->getType('string'); + $messageParts['parameter3'] = $wsdl->getType('mixed'); - $message = $this->wsdl->addMessage('myMessage', $messageParts); - $this->wsdl->addDocumentation($message, "foo"); + $message = $wsdl->addMessage('myMessage', $messageParts); + $wsdl->addDocumentation($message, "foo"); $this->assertEquals( '' . @@ -552,15 +426,15 @@ public function testAddDocumentationToSetInsertsBefore() . '' . '' . '', - $this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()) + $this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()) ); } - function testToXml() + public function testToXml() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), '' . '' ); } - function testToDomDocument() + public function testToDomDocument() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->dom = $this->wsdl->toDomDocument(); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $dom = $wsdl->toDomDocument(); - $this->assertTrue($this->dom instanceOf \DOMDocument); + $this->assertTrue($dom instanceOf \DOMDocument); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->dom->saveXML()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), '' . '' ); } - function testDump() + public function testDump() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); ob_start(); - $this->wsdl->dump(); + $wsdl->dump(); $wsdlDump = ob_get_clean(); $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdlDump), @@ -607,7 +481,7 @@ function testDump() . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" ' . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' ); - $this->wsdl->dump(__DIR__ . '/TestAsset/dumped.wsdl'); + $wsdl->dump(__DIR__ . '/TestAsset/dumped.wsdl'); $dumpedContent = file_get_contents(__DIR__ . '/TestAsset/dumped.wsdl'); $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($dumpedContent), @@ -623,78 +497,78 @@ function testDump() unlink(__DIR__ . '/TestAsset/dumped.wsdl'); } - function testGetType() + public function testGetType() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - - $this->assertEquals('xsd:string', $this->wsdl->getType('string'), 'xsd:string detection failed.'); - $this->assertEquals('xsd:string', $this->wsdl->getType('str'), 'xsd:string detection failed.'); - $this->assertEquals('xsd:int', $this->wsdl->getType('int'), 'xsd:int detection failed.'); - $this->assertEquals('xsd:int', $this->wsdl->getType('integer'), 'xsd:int detection failed.'); - $this->assertEquals('xsd:float', $this->wsdl->getType('float'), 'xsd:float detection failed.'); - $this->assertEquals('xsd:double', $this->wsdl->getType('double'), 'xsd:double detection failed.'); - $this->assertEquals('xsd:boolean', $this->wsdl->getType('boolean'), 'xsd:boolean detection failed.'); - $this->assertEquals('xsd:boolean', $this->wsdl->getType('bool'), 'xsd:boolean detection failed.'); - $this->assertEquals('soap-enc:Array', $this->wsdl->getType('array'), 'soap-enc:Array detection failed.'); - $this->assertEquals('xsd:struct', $this->wsdl->getType('object'), 'xsd:struct detection failed.'); - $this->assertEquals('xsd:anyType', $this->wsdl->getType('mixed'), 'xsd:anyType detection failed.'); - $this->assertEquals('', $this->wsdl->getType('void'), 'void detection failed.'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + + $this->assertEquals('xsd:string', $wsdl->getType('string'), 'xsd:string detection failed.'); + $this->assertEquals('xsd:string', $wsdl->getType('str'), 'xsd:string detection failed.'); + $this->assertEquals('xsd:int', $wsdl->getType('int'), 'xsd:int detection failed.'); + $this->assertEquals('xsd:int', $wsdl->getType('integer'), 'xsd:int detection failed.'); + $this->assertEquals('xsd:float', $wsdl->getType('float'), 'xsd:float detection failed.'); + $this->assertEquals('xsd:double', $wsdl->getType('double'), 'xsd:double detection failed.'); + $this->assertEquals('xsd:boolean', $wsdl->getType('boolean'), 'xsd:boolean detection failed.'); + $this->assertEquals('xsd:boolean', $wsdl->getType('bool'), 'xsd:boolean detection failed.'); + $this->assertEquals('soap-enc:Array', $wsdl->getType('array'), 'soap-enc:Array detection failed.'); + $this->assertEquals('xsd:struct', $wsdl->getType('object'), 'xsd:struct detection failed.'); + $this->assertEquals('xsd:anyType', $wsdl->getType('mixed'), 'xsd:anyType detection failed.'); + $this->assertEquals('', $wsdl->getType('void'), 'void detection failed.'); } - function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() + public function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->assertEquals('tns:WsdlTestClass', $wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); + $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); // $wsdl2 = new Wsdl('MyService', 'http://localhost/MyService.php', false); // $this->assertEquals('xsd:anyType', $wsdl2->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); // $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof ComplexTypeStrategy\AnyType); } - function testGetComplexTypeBasedOnStrategiesStringNames() + public function testGetComplexTypeBasedOnStrategiesStringNames() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); - $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); + $this->assertEquals('tns:WsdlTestClass', $wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); + $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); $wsdl2 = new Wsdl('MyService', 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); $this->assertEquals('xsd:anyType', $wsdl2->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof ComplexTypeStrategy\AnyType); } - function testAddingSameComplexTypeMoreThanOnceIsIgnored() + public function testAddingSameComplexTypeMoreThanOnceIsIgnored() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:SomeTypeName'); - $this->wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:AnotherTypeName'); - $types = $this->wsdl->getTypes(); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:SomeTypeName'); + $wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:AnotherTypeName'); + $types = $wsdl->getTypes(); $this->assertEquals(1, count($types)); $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:SomeTypeName'), $types); } - function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition() + public function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:WsdlTestClass'), - $this->wsdl->getTypes()); + $wsdl->getTypes()); - $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:WsdlTestClass'), - $this->wsdl->getTypes()); + $wsdl->getTypes()); } - function testAddComplexType() + public function testAddComplexType() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), + $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), '' . 'wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - - $this->assertEquals("xsd:string", $this->wsdl->getType("StrIng")); - $this->assertEquals("xsd:string", $this->wsdl->getType("sTr")); - $this->assertEquals("xsd:int", $this->wsdl->getType("iNt")); - $this->assertEquals("xsd:int", $this->wsdl->getType("INTEGER")); - $this->assertEquals("xsd:float", $this->wsdl->getType("FLOAT")); - $this->assertEquals("xsd:double", $this->wsdl->getType("douBLE")); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + + $this->assertEquals("xsd:string", $wsdl->getType("StrIng")); + $this->assertEquals("xsd:string", $wsdl->getType("sTr")); + $this->assertEquals("xsd:int", $wsdl->getType("iNt")); + $this->assertEquals("xsd:int", $wsdl->getType("INTEGER")); + $this->assertEquals("xsd:float", $wsdl->getType("FLOAT")); + $this->assertEquals("xsd:double", $wsdl->getType("douBLE")); } /** @@ -736,8 +610,8 @@ function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() */ public function testWsdlGetTypeWillAllowLongType() { - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals("xsd:long", $this->wsdl->getType("long")); + $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->assertEquals("xsd:long", $wsdl->getType("long")); } /** @@ -745,14 +619,14 @@ public function testWsdlGetTypeWillAllowLongType() */ public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceBySequenceStrategy() { - $this->wsdl = new Wsdl("MyService", "http://localhost/MyService.php"); - $this->wsdl->setComplexTypeStrategy(new ComplexTypeStrategy\ArrayOfTypeSequence()); + $wsdl = new Wsdl("MyService", "http://localhost/MyService.php"); + $wsdl->setComplexTypeStrategy(new ComplexTypeStrategy\ArrayOfTypeSequence()); - $this->wsdl->addComplexType("string[]"); - $this->wsdl->addComplexType("int[]"); - $this->wsdl->addComplexType("string[]"); + $wsdl->addComplexType("string[]"); + $wsdl->addComplexType("int[]"); + $wsdl->addComplexType("string[]"); - $xml = $this->wsdl->toXml(); + $xml = $wsdl->toXml(); $this->assertEquals(1, substr_count($xml, "ArrayOfString"), "ArrayOfString should appear only once."); $this->assertEquals(1, substr_count($xml, "ArrayOfInt"), "ArrayOfInt should appear only once."); } @@ -765,8 +639,8 @@ public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceByS */ public function testHtmlAmpersandInUrlInConstructorIsEncodedCorrectly() { - $this->wsdl = new Wsdl("MyService", self::URI_WITH_EXPANDED_AMP); - $this->assertContains(self::URI_WITH_EXPANDED_AMP, $this->wsdl->toXML()); + $wsdl = new Wsdl("MyService", self::URI_WITH_EXPANDED_AMP); + $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML()); } /** @@ -774,8 +648,8 @@ public function testHtmlAmpersandInUrlInConstructorIsEncodedCorrectly() */ public function testHtmlAmpersandInUrlInSetUriIsEncodedCorrectly() { - $this->wsdl = new Wsdl("MyService", "http://example.com"); - $this->wsdl->setUri(self::URI_WITH_EXPANDED_AMP); - $this->assertContains(self::URI_WITH_EXPANDED_AMP, $this->wsdl->toXML()); + $wsdl = new Wsdl("MyService", "http://example.com"); + $wsdl->setUri(self::URI_WITH_EXPANDED_AMP); + $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML()); } } diff --git a/test/_files/cert_file b/test/_files/cert_file new file mode 100644 index 00000000..e69de29b diff --git a/test/_files/commontypes.php b/test/_files/commontypes.php new file mode 100644 index 00000000..946fc7d4 --- /dev/null +++ b/test/_files/commontypes.php @@ -0,0 +1,435 @@ + 'bar', 'baz' => true, 1 => false, 'bat' => 123); +} + +/** + * Return Object + * + * @return stdClass + */ +function Zend_Soap_AutoDiscover_TestFunc8() +{ + $return = (object) array('foo' => 'bar', 'baz' => true, 'bat' => 123, 'qux' => false); + return $return; +} + +/** + * Multiple Args + * + * @param string $foo + * @param string $bar + * @return string + */ +function Zend_Soap_AutoDiscover_TestFunc9($foo, $bar) +{ + return "$foo $bar"; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_AutoDiscover_TestFixingMultiplePrototypes +{ + /** + * Test function + * + * @param integer $a + * @param integer $b + * @param integer $d + * @return integer + */ + public function testFunc($a=100, $b=200, $d=300) + { + + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_AutoDiscover_Test +{ + /** + * Test Function 1 + * + * @return string + */ + public function testFunc1() + { + return "Hello World"; + } + + /** + * Test Function 2 + * + * @param string $who Some Arg + * @return string + */ + public function testFunc2($who) + { + return "Hello $who!"; + } + + /** + * Test Function 3 + * + * @param string $who Some Arg + * @param int $when Some + * @return string + */ + public function testFunc3($who, $when) + { + return "Hello $who, How are you $when"; + } + + /** + * Test Function 4 + * + * @return string + */ + public static function testFunc4() + { + return "I'm Static!"; + } +} + +class Zend_Soap_AutoDiscoverTestClass1 +{ + /** + * @var integer $var + */ + public $var = 1; + + /** + * @var string $param + */ + public $param = "hello"; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_AutoDiscoverTestClass2 +{ + /** + * + * @param Zend_Soap_AutoDiscoverTestClass1 $test + * @return bool + */ + public function add(Zend_Soap_AutoDiscoverTestClass1 $test) + { + return true; + } + + /** + * @return Zend_Soap_AutoDiscoverTestClass1[] + */ + public function fetchAll() + { + return array( + new Zend_Soap_AutoDiscoverTestClass1(), + new Zend_Soap_AutoDiscoverTestClass1(), + ); + } + + /** + * @param Zend_Soap_AutoDiscoverTestClass1[] + */ + public function addMultiple($test) + { + + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_Wsdl_ComplexTypeB +{ + /** + * @var string + */ + public $bar; + /** + * @var string + */ + public $foo; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_Wsdl_ComplexTypeA +{ + /** + * @var Zend_Soap_Wsdl_ComplexTypeB[] + */ + public $baz = array(); +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_Wsdl_ComplexTest +{ + /** + * @var int + */ + public $var = 5; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_Wsdl_ComplexObjectStructure +{ + /** + * @var bool + */ + public $boolean = true; + + /** + * @var string + */ + public $string = "Hello World"; + + /** + * @var int + */ + public $int = 10; + + /** + * @var array + */ + public $array = array(1, 2, 3); +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_Wsdl_ComplexObjectWithObjectStructure +{ + /** + * @var Zend_Soap_Wsdl_ComplexTest + */ + public $object; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_AutoDiscover_MyService +{ + /** + * @param string $foo + * @return Zend_Soap_AutoDiscover_MyResponse[] + */ + public function foo($foo) + { + } + /** + * @param string $bar + * @return Zend_Soap_AutoDiscover_MyResponse[] + */ + public function bar($bar) + { + } + + /** + * @param string $baz + * @return Zend_Soap_AutoDiscover_MyResponse[] + */ + public function baz($baz) + { + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_AutoDiscover_MyServiceSequence +{ + /** + * @param string $foo + * @return string[] + */ + public function foo($foo) + { + } + /** + * @param string $bar + * @return string[] + */ + public function bar($bar) + { + } + + /** + * @param string $baz + * @return string[] + */ + public function baz($baz) + { + } + + /** + * @param string $baz + * @return string[][][] + */ + public function bazNested($baz) + { + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_AutoDiscover_MyResponse +{ + /** + * @var string + */ + public $p1; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_AutoDiscover_Recursion +{ + /** + * @var Zend_Soap_AutoDiscover_Recursion + */ + public $recursion; + + /** + * @return Zend_Soap_AutoDiscover_Recursion + */ + public function create() {} +} + +/** + * @param string $message + */ +function Zend_Soap_AutoDiscover_OneWay($message) +{ + +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_AutoDiscover_NoReturnType +{ + /** + * + * @param string $message + */ + public function pushOneWay($message) + { + + } +} diff --git a/test/_files/fulltests/server1.php b/test/_files/fulltests/server1.php new file mode 100644 index 00000000..4483f864 --- /dev/null +++ b/test/_files/fulltests/server1.php @@ -0,0 +1,83 @@ +bar = "bar"; + $b1->foo = "bar"; + $a->baz[] = $b1; + + $b2 = new Zend_Soap_Wsdl_ComplexTypeB(); + $b2->bar = "foo"; + $b2->foo = "foo"; + $a->baz[] = $b2; + + $a->baz[] = $request; + + return array($a); + } +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_Wsdl_ComplexTypeB +{ + /** + * @var string + */ + public $bar; + /** + * @var string + */ + public $foo; +} + +/** + * @category Zend + * @package Zend_Soap + * @subpackage UnitTests + */ +class Zend_Soap_Wsdl_ComplexTypeA +{ + /** + * @var Zend_Soap_Wsdl_ComplexTypeB[] + */ + public $baz = array(); +} + +if (isset($_GET['wsdl'])) { + $server = new Zend_Soap_AutoDiscover(new Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex()); +} else { + $uri = "http://".$_SERVER['HTTP_HOST']."/".$_SERVER['PHP_SELF']."?wsdl"; + $server = new Zend_Soap_Server($uri); +} +$server->setClass('Zend_Soap_Service_Server1'); +$server->handle(); diff --git a/test/_files/fulltests/server2.php b/test/_files/fulltests/server2.php new file mode 100644 index 00000000..55ef9ed2 --- /dev/null +++ b/test/_files/fulltests/server2.php @@ -0,0 +1,60 @@ +bar = $bar; + $b->foo = $foo; + return $b; + } +} + +if (isset($_GET['wsdl'])) { + $server = new Zend_Soap_AutoDiscover(new Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex()); +} else { + $uri = "http://".$_SERVER['HTTP_HOST']."/".$_SERVER['PHP_SELF']."?wsdl"; + $server = new Zend_Soap_Server($uri); +} +$server->setClass('Zend_Soap_Service_Server2'); +$server->handle(); diff --git a/test/_files/wsdl_documentation.wsdl b/test/_files/wsdl_documentation.wsdl new file mode 100644 index 00000000..5538eccd --- /dev/null +++ b/test/_files/wsdl_documentation.wsdl @@ -0,0 +1,106 @@ + + + Definitions + + + Ports + + + + + + + + + + + + + + + + + + + + Bindings + + + + + + + + + Operation1 + + + + + + + + + Operation2 + + + + + + + + + Operation3 + + + + + + + + + Operation4 + + + + + + + + + + + Services + + + + + + + + Message + + + + Message + + + + Message + + + + Message + + + + + Message + + + + + Message + + + \ No newline at end of file diff --git a/test/_files/wsdl_example.wsdl b/test/_files/wsdl_example.wsdl new file mode 100644 index 00000000..4eaa8761 --- /dev/null +++ b/test/_files/wsdl_example.wsdl @@ -0,0 +1,2 @@ + + diff --git a/test/schemas/wsdl.xsd b/test/schemas/wsdl.xsd new file mode 100644 index 00000000..0546b338 --- /dev/null +++ b/test/schemas/wsdl.xsd @@ -0,0 +1,334 @@ + + + + + + + + + + + + + + + This type is extended by component types to allow them to be documented + + + + + + + + + + + + + + This type is extended by component types to allow attributes from other namespaces to be added. + + + + + + + + + + + + + + This type is extended by component types to allow elements from other namespaces to be added. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Any top level optional element allowed to appear more then once - any child of definitions element except wsdl:types. Any extensibility element is allowed in any place. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 09579f3db2b14443b270f71a756c11449e29fec8 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Sun, 24 Feb 2013 10:05:50 +0100 Subject: [PATCH 05/22] Complete rewrite of wsdl generation. Complete rewrite of wsdl generation from strings and simple dom to full object oriented from the begining. It uses dom and proper namespaces. All tests are also rewritten to new structure and now are using xpath versus old string comparison. --- src/AutoDiscover.php | 126 +- .../DiscoveryStrategy/ReflectionDiscovery.php | 3 +- src/Client.php | 171 ++- src/Client/Common.php | 9 +- src/Client/DotNet.php | 4 +- src/Client/Local.php | 5 +- src/Exception/BadMethodCallException.php | 7 + src/Exception/ExceptionInterface.php | 2 + src/Exception/ExtensionNotLoadedException.php | 7 + src/Exception/InvalidArgumentException.php | 7 + src/Exception/RuntimeException.php | 7 + src/Exception/UnexpectedValueException.php | 7 + src/Server.php | 179 ++- src/Server/DocumentLiteralWrapper.php | 3 +- src/Wsdl.php | 173 ++- .../AbstractComplexTypeStrategy.php | 1 + src/Wsdl/ComplexTypeStrategy/AnyType.php | 4 +- .../ArrayOfTypeComplex.php | 24 +- .../ArrayOfTypeSequence.php | 21 +- src/Wsdl/ComplexTypeStrategy/Composite.php | 5 +- .../DefaultComplexType.php | 19 +- test/AutoDiscoverTest.php | 1183 +++++++++-------- test/ClientTest.php | 107 +- test/ServerTest.php | 149 ++- test/TestAsset/commontypes.php | 58 + test/TestAsset/wsdl_example.wsdl | 89 +- test/Wsdl/ArrayOfTypeComplexStrategyTest.php | 214 +-- test/Wsdl/ArrayOfTypeSequenceStrategyTest.php | 238 ++-- test/Wsdl/CompositeStrategyTest.php | 53 +- test/Wsdl/DefaultComplexTypeTest.php | 52 +- test/WsdlTest.php | 1095 ++++++++------- test/WsdlTestHelper.php | 120 ++ test/_files/wsdl_example.wsdl | 89 +- 33 files changed, 2739 insertions(+), 1492 deletions(-) mode change 100644 => 100755 src/AutoDiscover.php mode change 100644 => 100755 src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php mode change 100644 => 100755 src/Client.php mode change 100644 => 100755 src/Client/Common.php mode change 100644 => 100755 src/Client/DotNet.php mode change 100644 => 100755 src/Client/Local.php mode change 100644 => 100755 src/Exception/BadMethodCallException.php mode change 100644 => 100755 src/Exception/ExceptionInterface.php mode change 100644 => 100755 src/Exception/ExtensionNotLoadedException.php mode change 100644 => 100755 src/Exception/InvalidArgumentException.php mode change 100644 => 100755 src/Exception/RuntimeException.php mode change 100644 => 100755 src/Exception/UnexpectedValueException.php mode change 100644 => 100755 src/Server.php mode change 100644 => 100755 src/Server/DocumentLiteralWrapper.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/AnyType.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/Composite.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php mode change 100644 => 100755 test/AutoDiscoverTest.php mode change 100644 => 100755 test/ClientTest.php mode change 100644 => 100755 test/ServerTest.php mode change 100644 => 100755 test/TestAsset/commontypes.php mode change 100644 => 100755 test/TestAsset/wsdl_example.wsdl mode change 100644 => 100755 test/Wsdl/ArrayOfTypeComplexStrategyTest.php mode change 100644 => 100755 test/Wsdl/ArrayOfTypeSequenceStrategyTest.php mode change 100644 => 100755 test/Wsdl/CompositeStrategyTest.php mode change 100644 => 100755 test/Wsdl/DefaultComplexTypeTest.php mode change 100644 => 100755 test/WsdlTest.php create mode 100755 test/WsdlTestHelper.php mode change 100644 => 100755 test/_files/wsdl_example.wsdl diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php old mode 100644 new mode 100755 index 4dc1d016..a9d7c048 --- a/src/AutoDiscover.php +++ b/src/AutoDiscover.php @@ -14,6 +14,7 @@ use Zend\Server\Reflection\AbstractFunction; use Zend\Soap\AutoDiscover\DiscoveryStrategy\DiscoveryStrategyInterface as DiscoveryStrategy; use Zend\Soap\AutoDiscover\DiscoveryStrategy\ReflectionDiscovery; +use Zend\Soap\Exception\InvalidArgumentException; use Zend\Soap\Wsdl; use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy; use Zend\Uri; @@ -68,14 +69,20 @@ class AutoDiscover * * @var array */ - protected $operationBodyStyle = array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"); + protected $operationBodyStyle = array( + 'use' => 'encoded', + 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/" + ); /** * soap:operation style * * @var array */ - protected $bindingStyle = array('style' => 'rpc', 'transport' => 'http://schemas.xmlsoap.org/soap/http'); + protected $bindingStyle = array( + 'style' => 'rpc', + 'transport' => 'http://schemas.xmlsoap.org/soap/http' + ); /** * Name of the class to handle the WSDL creation. @@ -106,10 +113,11 @@ class AutoDiscover * @param string $wsdlClass * @param array $classMap */ - public function __construct(ComplexTypeStrategy $strategy = null, $endpointUri=null, $wsdlClass=null, array $classMap = array()) - { + public function __construct(ComplexTypeStrategy $strategy = null, + $endpointUri=null, $wsdlClass=null, array $classMap = array() + ) { $this->reflection = new Reflection(); - $this->discoveryStrategy = new ReflectionDiscovery(); + $this->setDiscoveryStrategy(new ReflectionDiscovery()); if ($strategy !== null) { $this->setComplexTypeStrategy($strategy); @@ -167,10 +175,19 @@ public function setClassMap($classMap) * Set service name * * @param string $serviceName + * @throws Exception\InvalidArgumentException * @return AutoDiscover */ public function setServiceName($serviceName) { + $matches = array(); + $i = preg_match('/^[a-z\_]/ims', $serviceName, $matches); + if ($i != 1) { + throw new InvalidArgumentException( + 'XML NCName and Service Name must start with letter or _' + ); + } + $this->serviceName = $serviceName; return $this; } @@ -209,9 +226,18 @@ public function setUri($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.' + 'Argument to \Zend\Soap\AutoDiscover::setUri should be string ' + .'or \Zend\Uri\Uri instance.' ); } + + $uri = trim($uri); + $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); + + if (empty($uri)) { + throw new InvalidArgumentException('Uri contains invalid characters or is empty'); + } + $this->uri = $uri; return $this; @@ -226,7 +252,9 @@ public function setUri($uri) public function getUri() { if ($this->uri === null) { - throw new Exception\RuntimeException("Missing uri. You have to explicitly configure the Endpoint Uri by calling AutoDiscover::setUri()."); + throw new Exception\RuntimeException("Missing uri. You have to ' + .'explicitly configure the Endpoint Uri by calling AutoDiscover::setUri()." + ); } if (is_string($this->uri)) { $this->uri = Uri\UriFactory::factory($this->uri); @@ -244,11 +272,12 @@ public function getUri() */ 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.' ); } + $this->wsdlClass = $wsdlClass; return $this; @@ -277,7 +306,9 @@ public function getWsdlClass() public function setOperationBodyStyle(array $operationStyle=array()) { if (!isset($operationStyle['use'])) { - throw new Exception\InvalidArgumentException("Key 'use' is required in Operation soap:body style."); + throw new Exception\InvalidArgumentException( + "Key 'use' is required in Operation soap:body style." + ); } $this->operationBodyStyle = $operationStyle; return $this; @@ -324,6 +355,7 @@ public function setComplexTypeStrategy(ComplexTypeStrategy $strategy) public function setClass($class) { $this->class = $class; + return $this; } @@ -331,11 +363,30 @@ public function setClass($class) * Add a Single or Multiple Functions to the WSDL * * @param string $function Function Name + * @throws Exception\InvalidArgumentException * @return AutoDiscover */ public function addFunction($function) { - $this->functions[] = $function; + if (is_array($function)) { + foreach($function as $row){ + $this->addFunction($row); + } + } elseif (is_string($function)) { + if (function_exists($function)) { + $this->functions[] = $function; + } else { + throw new Exception\InvalidArgumentException('Argument to ' + . '\Zend\Soap\AutoDiscover::addFunction should be a valid function name.' + ); + } + + } else { + throw new Exception\InvalidArgumentException('Argument to ' + . '\Zend\Soap\AutoDiscover::addFunction should be string or array of strings.' + ); + } + return $this; } @@ -375,6 +426,8 @@ protected function _generateWsdl(array $reflectionMethods) $uri = $this->getUri(); $serviceName = $this->getServiceName(); + + /** @var $wsdl \Zend\Soap\Wsdl */ $wsdl = new $this->wsdlClass($serviceName, $uri, $this->strategy, $this->classMap); // The wsdl:types element must precede all other elements (WS-I Basic Profile 1.1 R2023) @@ -383,8 +436,12 @@ protected function _generateWsdl(array $reflectionMethods) $port = $wsdl->addPortType($serviceName . 'Port'); $binding = $wsdl->addBinding($serviceName . 'Binding', 'tns:' . $serviceName . 'Port'); - $wsdl->addSoapBinding($binding, $this->bindingStyle['style'], $this->bindingStyle['transport']); - $wsdl->addService($serviceName . 'Service', $serviceName . 'Port', 'tns:' . $serviceName . 'Binding', $uri); + $wsdl->addSoapBinding($binding, $this->bindingStyle['style'], + $this->bindingStyle['transport'] + ); + $wsdl->addService($serviceName . 'Service', $serviceName . 'Port', + 'tns:' . $serviceName . 'Binding', $uri + ); foreach ($reflectionMethods as $method) { $this->_addFunctionToWsdl($method, $wsdl, $port, $binding); @@ -410,6 +467,7 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) // We only support one prototype: the one with the maximum number of arguments $prototype = null; $maxNumArgumentsOfPrototype = -1; + /** @var $tmpPrototype \Zend\Server\Reflection\Prototype */ foreach ($function->getPrototypes() as $tmpPrototype) { $numParams = count($tmpPrototype->getParameters()); if ($numParams > $maxNumArgumentsOfPrototype) { @@ -418,7 +476,9 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) } } if ($prototype === null) { - throw new Exception\InvalidArgumentException("No prototypes could be found for the '" . $function->getName() . "' function"); + throw new Exception\InvalidArgumentException( + 'No prototypes could be found for the "' . $function->getName() . '" function' + ); } $functionName = $wsdl->translateType($function->getName()); @@ -438,16 +498,22 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) } $sequence[] = $sequenceElement; } + $element = array( - 'name' => $functionName, - 'sequence' => $sequence + 'name' => $functionName, + 'sequence' => $sequence ); + // Add the wrapper element part, which must be named 'parameters' $args['parameters'] = array('element' => $wsdl->addElement($element)); + } else { // RPC style: add each parameter as a typed part + /** @var $param \Zend\Server\Reflection\ReflectionParameter */ foreach ($prototype->getParameters() as $param) { - $args[$param->getName()] = array('type' => $wsdl->getType($this->discoveryStrategy->getFunctionParameterType($param))); + $args[$param->getName()] = array( + 'type' => $wsdl->getType($this->discoveryStrategy->getFunctionParameterType($param)) + ); } } $wsdl->addMessage($functionName . 'In', $args); @@ -463,34 +529,48 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) if ($prototype->getReturnType() != "void") { $sequence[] = array( 'name' => $functionName . 'Result', - 'type' => $wsdl->getType($this->discoveryStrategy->getFunctionReturnType($function, $prototype)) + 'type' => $wsdl->getType( + $this->discoveryStrategy->getFunctionReturnType($function, $prototype) + ) ); } + $element = array( - 'name' => $functionName . 'Response', - 'sequence' => $sequence + 'name' => $functionName . 'Response', + 'sequence' => $sequence ); + // Add the wrapper element part, which must be named 'parameters' $args['parameters'] = array('element' => $wsdl->addElement($element)); + } elseif ($prototype->getReturnType() != "void") { // RPC style: add the return value as a typed part - $args['return'] = array('type' => $wsdl->getType($this->discoveryStrategy->getFunctionReturnType($function, $prototype))); + $args['return'] = array( + 'type' => $wsdl->getType($this->discoveryStrategy->getFunctionReturnType($function, $prototype)) + ); } + $wsdl->addMessage($functionName . 'Out', $args); } // Add the portType operation if ($isOneWayMessage == false) { - $portOperation = $wsdl->addPortOperation($port, $functionName, 'tns:' . $functionName . 'In', 'tns:' . $functionName . 'Out'); + $portOperation = $wsdl->addPortOperation($port, $functionName, + 'tns:' . $functionName . 'In', 'tns:' . $functionName . 'Out' + ); } else { - $portOperation = $wsdl->addPortOperation($port, $functionName, 'tns:' . $functionName . 'In', false); + $portOperation = $wsdl->addPortOperation($port, $functionName, + 'tns:' . $functionName . 'In', false + ); } $desc = $this->discoveryStrategy->getFunctionDocumentation($function); + if (strlen($desc) > 0) { $wsdl->addDocumentation($portOperation, $desc); } - // When using the RPC style, make sure the operation style includes a 'namespace' attribute (WS-I Basic Profile 1.1 R2717) + // When using the RPC style, make sure the operation style includes a 'namespace' + // attribute (WS-I Basic Profile 1.1 R2717) $operationBodyStyle = $this->operationBodyStyle; if ($this->bindingStyle['style'] == 'rpc' && !isset($operationBodyStyle['namespace'])) { $operationBodyStyle['namespace'] = '' . $uri; diff --git a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php old mode 100644 new mode 100755 index 7ba6d0f5..21a56434 --- a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php +++ b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php @@ -15,7 +15,8 @@ use Zend\Server\Reflection\ReflectionParameter; /** - * Describes how types, return values and method details are detected during AutoDiscovery of a WSDL. + * Describes how types, return values and method details are detected during + * AutoDiscovery of a WSDL. * * @category Zend * @package Zend_Soap diff --git a/src/Client.php b/src/Client.php old mode 100644 new mode 100755 index a1833b29..b17b4a35 --- a/src/Client.php +++ b/src/Client.php @@ -50,24 +50,25 @@ class Client implements ServerClient protected $soapVersion = SOAP_1_2; /** Set of other SoapClient options */ - protected $uri = null; - protected $location = null; - protected $style = null; - protected $use = null; - protected $login = null; - protected $password = null; - protected $proxyHost = null; - protected $proxyPort = null; - protected $proxyLogin = null; - protected $proxyPassword = null; - protected $localCert = null; - protected $passphrase = null; - protected $compression = null; - protected $connectionTimeout = null; - protected $streamContext = null; - protected $features = null; - protected $cacheWsdl = null; - protected $userAgent = null; + protected $uri = null; + protected $location = null; + protected $style = null; + protected $use = null; + protected $login = null; + protected $password = null; + protected $proxyHost = null; + protected $proxyPort = null; + protected $proxyLogin = null; + protected $proxyPassword = null; + protected $localCert = null; + protected $passphrase = null; + protected $compression = null; + protected $connectionTimeout = null; + protected $streamContext = null; + protected $features = null; + protected $cacheWsdl = null; + protected $userAgent = null; + protected $typemap = null; /** * WSDL used to access server @@ -169,8 +170,9 @@ public function getWSDL() * Allows setting options as an associative array of option => value pairs. * * @param array|Traversable $options - * @return Client * @throws Exception\InvalidArgumentException + * + * @return Client */ public function setOptions($options) { @@ -179,9 +181,9 @@ public function setOptions($options) } foreach ($options as $key => $value) { - switch ($key) { + switch (strtolower($key)) { case 'classmap': - case 'classMap': + case 'class_map': $this->setClassmap($value); break; case 'encoding': @@ -243,11 +245,15 @@ public function setOptions($options) $this->setWSDLCache($value); break; case 'useragent': - case 'userAgent': case 'user_agent': $this->setUserAgent($value); break; + case 'type_map': + case 'typemap': + $this->setTypemap($value); + break; + // Not used now // case 'connection_timeout': // $this->connectionTimeout = $value; @@ -272,6 +278,7 @@ public function getOptions() $options = array(); $options['classmap'] = $this->getClassmap(); + $options['typemap'] = $this->getTypemap(); $options['encoding'] = $this->getEncoding(); $options['soap_version'] = $this->getSoapVersion(); $options['wsdl'] = $this->getWSDL(); @@ -317,13 +324,16 @@ public function getOptions() * Set SOAP version * * @param int $version One of the SOAP_1_1 or SOAP_1_2 constants + * @throws Exception\InvalidArgumentException with invalid soap version argument + * * @return Client - * @throws Exception\ExceptionInterface with invalid soap version argument */ public function setSoapVersion($version) { if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) { - throw new Exception\InvalidArgumentException('Invalid soap version specified. Use SOAP_1_1 or SOAP_1_2 constants.'); + throw new Exception\InvalidArgumentException('Invalid soap version' + .' specified. Use SOAP_1_1 or SOAP_1_2 constants.' + ); } $this->soapVersion = $version; @@ -346,14 +356,15 @@ public function getSoapVersion() * Set classmap * * @param array $classmap + * @throws Exception\InvalidArgumentException for any invalid class in the class map + * * @return Client - * @throws Exception\ExceptionInterface for any invalid class in the class map */ public function setClassmap(array $classmap) { foreach ($classmap as $class) { if (!class_exists($class)) { - throw new Exception\InvalidArgumentException('Invalid class in class map'); + throw new Exception\InvalidArgumentException('Invalid class in class map: '.$class); } } @@ -373,12 +384,48 @@ public function getClassmap() return $this->classmap; } + /** + * @param array $typeMap + * @throws Exception\InvalidArgumentException + * + * @return Client + */ + public function setTypemap(array $typeMap) { + foreach ($typeMap as $type) { + if (!is_callable($type['from_xml'])) { + throw new Exception\InvalidArgumentException( + 'Invalid from_xml callback for type: '.$type['type_name'] + ); + } + if (!is_callable($type['to_xml'])) { + throw new Exception\InvalidArgumentException( + 'Invalid to_xml callback for type: '.$type['type_name'] + ); + } + } + + $this->typemap = $typeMap; + $this->soapClient = null; + + return $this; +} + + /** + * Retrieve typemap + * + * @return array + */ + public function getTypemap() { + return $this->typemap; + } + /** * Set encoding * * @param string $encoding + * @throws Exception\InvalidArgumentException with invalid encoding argument + * * @return Client - * @throws Exception\ExceptionInterface with invalid encoding argument */ public function setEncoding($encoding) { @@ -387,7 +434,6 @@ public function setEncoding($encoding) } $this->encoding = $encoding; - $this->soapClient = null; return $this; @@ -407,8 +453,9 @@ public function getEncoding() * Check for valid URN * * @param string $urn + * @throws Exception\InvalidArgumentException on invalid URN + * * @return bool - * @throws Exception\ExceptionInterface on invalid URN */ public function validateUrn($urn) { @@ -427,8 +474,9 @@ public function validateUrn($urn) * URI in Web Service the target namespace * * @param string $uri + * @throws Exception\InvalidArgumentException with invalid uri argument + * * @return Client - * @throws Exception\ExceptionInterface with invalid uri argument */ public function setUri($uri) { @@ -456,8 +504,9 @@ public function getUri() * URI in Web Service the target namespace * * @param string $location + * @throws Exception\InvalidArgumentException with invalid uri argument + * * @return Client - * @throws Exception\ExceptionInterface with invalid uri argument */ public function setLocation($location) { @@ -483,13 +532,16 @@ public function getLocation() * Set request style * * @param int $style One of the SOAP_RPC or SOAP_DOCUMENT constants + * @throws Exception\InvalidArgumentException with invalid style argument + * * @return Client - * @throws Exception\ExceptionInterface with invalid style argument */ public function setStyle($style) { if (!in_array($style, array(SOAP_RPC, SOAP_DOCUMENT))) { - throw new Exception\InvalidArgumentException('Invalid request style specified. Use SOAP_RPC or SOAP_DOCUMENT constants.'); + throw new Exception\InvalidArgumentException('Invalid request style' + . ' specified. Use SOAP_RPC or SOAP_DOCUMENT constants.' + ); } $this->style = $style; @@ -513,13 +565,16 @@ public function getStyle() * Set message encoding method * * @param int $use One of the SOAP_ENCODED or SOAP_LITERAL constants + * @throws Exception\InvalidArgumentException with invalid message encoding method argument + * * @return Client - * @throws Exception\ExceptionInterface with invalid message encoding method argument */ public function setEncodingMethod($use) { if (!in_array($use, array(SOAP_ENCODED, SOAP_LITERAL))) { - throw new Exception\InvalidArgumentException('Invalid message encoding method. Use SOAP_ENCODED or SOAP_LITERAL constants.'); + throw new Exception\InvalidArgumentException('Invalid message' + .' encoding method. Use SOAP_ENCODED or SOAP_LITERAL constants.' + ); } $this->use = $use; @@ -683,8 +738,9 @@ public function setProxyPassword($proxyPassword) * Set HTTPS client certificate path * * @param string $localCert local certificate path + * @throws Exception\InvalidArgumentException with invalid local certificate path argument + * * @return Client - * @throws Exception\ExceptionInterface with invalid local certificate path argument */ public function setHttpsCertificate($localCert) { @@ -738,6 +794,7 @@ public function getHttpsCertPassphrase() * Set compression options * * @param int|null $compressionOptions + * * @return Client */ public function setCompressionOptions($compressionOptions) @@ -776,6 +833,8 @@ public function getProxyPassword() * Set Stream Context * * @param resource $context + * @throws Exception\InvalidArgumentException + * * @return Client */ public function setStreamContext($context) @@ -852,6 +911,7 @@ public function getWSDLCache() * Set the string to use in User-Agent header * * @param string|null $userAgent + * * @return Client */ public function setUserAgent($userAgent) @@ -954,13 +1014,18 @@ public function getLastMethod() * @param int $oneWay * @return mixed */ - public function _doRequest(Client\Common $client, $request, $location, $action, $version, $oneWay = null) - { + public function _doRequest(Client\Common $client, $request, $location, + $action, $version, $oneWay = null + ) { // Perform request as is if ($oneWay === null) { - return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version); + return call_user_func(array($client,'SoapClient::__doRequest'), + $request, $location, $action, $version + ); } - return call_user_func(array($client, 'SoapClient::__doRequest'), $request, $location, $action, $version, $oneWay); + return call_user_func(array($client, 'SoapClient::__doRequest'), $request, + $location, $action, $version, $oneWay + ); } /** @@ -975,17 +1040,25 @@ protected function _initSoapClientObject() if ($wsdl == null) { if (!isset($options['location'])) { - throw new Exception\UnexpectedValueException('\'location\' parameter is required in non-WSDL mode.'); + throw new Exception\UnexpectedValueException( + '\'location\' parameter is required in non-WSDL mode.' + ); } if (!isset($options['uri'])) { - throw new Exception\UnexpectedValueException('\'uri\' parameter is required in non-WSDL mode.'); + throw new Exception\UnexpectedValueException( + '\'uri\' parameter is required in non-WSDL mode.' + ); } } else { if (isset($options['use'])) { - throw new Exception\UnexpectedValueException('\'use\' parameter only works in non-WSDL mode.'); + throw new Exception\UnexpectedValueException( + '\'use\' parameter only works in non-WSDL mode.' + ); } if (isset($options['style'])) { - throw new Exception\UnexpectedValueException('\'style\' parameter only works in non-WSDL mode.'); + throw new Exception\UnexpectedValueException( + '\'style\' parameter only works in non-WSDL mode.' + ); } } unset($options['wsdl']); @@ -1113,7 +1186,9 @@ public function call($method, $params = array()) public function getFunctions() { if ($this->getWSDL() == null) { - throw new Exception\UnexpectedValueException(__METHOD__ . ' is available only in WSDL mode.'); + throw new Exception\UnexpectedValueException( + __METHOD__ . ' is available only in WSDL mode.' + ); } $soapClient = $this->getSoapClient(); @@ -1136,7 +1211,9 @@ public function getFunctions() public function getTypes() { if ($this->getWSDL() == null) { - throw new Exception\UnexpectedValueException(__METHOD__ . ' method is available only in WSDL mode.'); + throw new Exception\UnexpectedValueException( + __METHOD__ . ' method is available only in WSDL mode.' + ); } $soapClient = $this->getSoapClient(); @@ -1146,6 +1223,7 @@ public function getTypes() /** * @param SoapClient $soapClient + * * @return Client */ public function setSoapClient(SoapClient $soapClient) @@ -1168,6 +1246,7 @@ public function getSoapClient() /** * @param string $cookieName * @param string $cookieValue + * * @return Client */ public function setCookie($cookieName, $cookieValue=null) diff --git a/src/Client/Common.php b/src/Client/Common.php old mode 100644 new mode 100755 index 7eac81e5..b1505aed --- a/src/Client/Common.php +++ b/src/Client/Common.php @@ -42,7 +42,8 @@ public function __construct($doRequestCallback, $wsdl, $options) /** * Performs SOAP request over HTTP. - * Overridden to implement different transport layers, perform additional XML processing or other purpose. + * Overridden to implement different transport layers, perform additional + * XML processing or other purpose. * * @param string $request * @param string $location @@ -54,10 +55,12 @@ public function __construct($doRequestCallback, $wsdl, $options) public function __doRequest($request, $location, $action, $version, $oneWay = null) { if ($oneWay === null) { - return call_user_func($this->doRequestCallback, $this, $request, $location, $action, $version); + return call_user_func($this->doRequestCallback, $this, $request, + $location, $action, $version); } - return call_user_func($this->doRequestCallback, $this, $request, $location, $action, $version, $oneWay); + return call_user_func($this->doRequestCallback, $this, $request, + $location, $action, $version, $oneWay); } } diff --git a/src/Client/DotNet.php b/src/Client/DotNet.php old mode 100644 new mode 100755 index c0c1298e..dc746dfc --- a/src/Client/DotNet.php +++ b/src/Client/DotNet.php @@ -53,7 +53,9 @@ protected function _preProcessArguments($arguments) if (count($arguments) > 1 || (count($arguments) == 1 && !is_array(reset($arguments))) ) { - throw new Exception\RuntimeException('.Net webservice arguments have to be grouped into array: array(\'a\' => $a, \'b\' => $b, ...).'); + throw new Exception\RuntimeException('.Net webservice arguments have' + ." to be grouped into array: array('a' => \$a, 'b' => \$b, ...)." + ); } // Do nothing diff --git a/src/Client/Local.php b/src/Client/Local.php old mode 100644 new mode 100755 index c2c8dbb8..0b4a12fa --- a/src/Client/Local.php +++ b/src/Client/Local.php @@ -63,8 +63,9 @@ public function __construct(SOAPServer $server, $wsdl, $options = null) * @param int $oneWay * @return mixed */ - public function _doRequest(Common $client, $request, $location, $action, $version, $oneWay = null) - { + public function _doRequest(Common $client, $request, $location, $action, + $version, $oneWay = null + ) { // Perform request as is ob_start(); $this->server->handle($request); diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php old mode 100644 new mode 100755 index e536060c..663a085d --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -10,6 +10,13 @@ namespace Zend\Soap\Exception; +/** + * Exception thrown when method is badly called + * + * @category Zend + * @package Zend_Soap + * @subpackage Exception + */ class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php old mode 100644 new mode 100755 index dca074d6..c98a6b5c --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -11,6 +11,8 @@ namespace Zend\Soap\Exception; /** + * Common Exception interface + * * @category Zend * @package Zend_Soap * @subpackage AutoDiscover diff --git a/src/Exception/ExtensionNotLoadedException.php b/src/Exception/ExtensionNotLoadedException.php old mode 100644 new mode 100755 index 47329f41..e3d08465 --- a/src/Exception/ExtensionNotLoadedException.php +++ b/src/Exception/ExtensionNotLoadedException.php @@ -10,5 +10,12 @@ namespace Zend\Soap\Exception; +/** + * Exception thrown when soap php extension is not loaded + * + * @category Zend + * @package Zend_Soap + * @subpackage Exception + */ class ExtensionNotLoadedException extends RuntimeException {} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php old mode 100644 new mode 100755 index 847b866c..17f22a86 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -10,6 +10,13 @@ namespace Zend\Soap\Exception; +/** + * Exception thrown when arguments to method are invalid + * + * @category Zend + * @package Zend_Soap + * @subpackage Client + */ class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php old mode 100644 new mode 100755 index efc277c1..62da3aae --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -10,6 +10,13 @@ namespace Zend\Soap\Exception; +/** + * Exception thrown when there is an error during program execution + * + * @category Zend + * @package Zend_Soap + * @subpackage Client + */ class RuntimeException extends \RuntimeException implements ExceptionInterface diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php old mode 100644 new mode 100755 index 5a7fe10f..30cb35a2 --- a/src/Exception/UnexpectedValueException.php +++ b/src/Exception/UnexpectedValueException.php @@ -10,6 +10,13 @@ namespace Zend\Soap\Exception; +/** + * Exception thrown when provided arguments are invalid + * + * @category Zend + * @package Zend_Soap + * @subpackage Client + */ class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface diff --git a/src/Server.php b/src/Server.php old mode 100644 new mode 100755 index 53c5eee0..91db8fe2 --- a/src/Server.php +++ b/src/Server.php @@ -56,6 +56,12 @@ class Server implements \Zend\Server\Server */ protected $classmap; + /** + * Array of type mappings + * @var array + */ + protected $typemap; + /** * Encoding * @var string @@ -76,7 +82,6 @@ class Server implements \Zend\Server\Server */ protected $wsdlCache; - /** * Registered fault exceptions * @var array @@ -177,14 +182,20 @@ public function setOptions($options) } foreach ($options as $key => $value) { - switch ($key) { + switch (strtolower($key)) { case 'actor': $this->setActor($value); break; case 'classmap': - case 'classMap': + case 'class_map': $this->setClassmap($value); break; + + case 'typemap': + case 'type_map': + $this->setTypemap($value); + break; + case 'encoding': $this->setEncoding($value); break; @@ -198,14 +209,15 @@ public function setOptions($options) case 'wsdl': $this->setWSDL($value); break; + case 'cache_wsdl': + $this->setWSDLCache($value); + break; + // @todo is missing break really necessary ? case 'featues': trigger_error(__METHOD__ . ': the option "featues" is deprecated as of 1.10.x and will be removed with 2.0.0; use "features" instead', E_USER_NOTICE); case 'features': $this->setSoapFeatures($value); break; - case 'cache_wsdl': - $this->setWSDLCache($value); - break; default: break; } @@ -223,31 +235,35 @@ public function getOptions() { $options = array(); if (null !== $this->actor) { - $options['actor'] = $this->actor; + $options['actor'] = $this->getActor(); } if (null !== $this->classmap) { - $options['classmap'] = $this->classmap; + $options['classmap'] = $this->getClassmap(); + } + + if (null !== $this->typemap) { + $options['typemap'] = $this->getTypemap(); } if (null !== $this->encoding) { - $options['encoding'] = $this->encoding; + $options['encoding'] = $this->getEncoding(); } if (null !== $this->soapVersion) { - $options['soap_version'] = $this->soapVersion; + $options['soap_version'] = $this->getSoapVersion(); } if (null !== $this->uri) { - $options['uri'] = $this->uri; + $options['uri'] = $this->getUri(); } if (null !== $this->features) { - $options['features'] = $this->features; + $options['features'] = $this->getSoapFeatures(); } if (null !== $this->wsdlCache) { - $options['cache_wsdl'] = $this->wsdlCache; + $options['cache_wsdl'] = $this->getWSDLCache(); } return $options; @@ -257,8 +273,9 @@ public function getOptions() * Set encoding * * @param string $encoding - * @return Server * @throws Exception\InvalidArgumentException with invalid encoding argument + * + * @return Server */ public function setEncoding($encoding) { @@ -284,8 +301,9 @@ public function getEncoding() * Set SOAP version * * @param int $version One of the SOAP_1_1 or SOAP_1_2 constants - * @return Server * @throws Exception\InvalidArgumentException with invalid soap version argument + * + * @return Server */ public function setSoapVersion($version) { @@ -311,8 +329,9 @@ public function getSoapVersion() * Check for valid URN * * @param string $urn - * @return true * @throws Exception\InvalidArgumentException on invalid URN + * + * @return bool */ public function validateUrn($urn) { @@ -336,6 +355,7 @@ public function setActor($actor) { $this->validateUrn($actor); $this->actor = $actor; + return $this; } @@ -355,12 +375,14 @@ public function getActor() * URI in SoapServer is actually the target namespace, not a URI; $uri must begin with 'urn:'. * * @param string $uri + * * @return Server */ public function setUri($uri) { $this->validateUrn($uri); $this->uri = $uri; + return $this; } @@ -378,8 +400,9 @@ public function getUri() * Set classmap * * @param array $classmap - * @return Server * @throws Exception\InvalidArgumentException for any invalid class in the class map + * + * @return Server */ public function setClassmap($classmap) { @@ -393,6 +416,7 @@ public function setClassmap($classmap) } $this->classmap = $classmap; + return $this; } @@ -406,6 +430,41 @@ public function getClassmap() return $this->classmap; } + /** + * @param array $typeMap + * @throws Exception\InvalidArgumentException + * + * @return Server + */ + public function setTypemap($typeMap) + { + + if (!is_array($typeMap)) { + throw new Exception\InvalidArgumentException('Typemap must be an array'); + } + + foreach ($typeMap as $type) { + if (!is_callable($type['from_xml'])) { + throw new Exception\InvalidArgumentException('Invalid from_xml callback for type: '.$type['type_name']); + } + if (!is_callable($type['to_xml'])) { + throw new Exception\InvalidArgumentException('Invalid to_xml callback for type: '.$type['type_name']); + } + } + + $this->typemap = $typeMap; + + return $this; + } + + /** + * @return array + */ + public function getTypemap() + { + return $this->typemap; + } + /** * Set wsdl * @@ -494,11 +553,13 @@ public function addFunction($function, $namespace = '') throw new Exception\InvalidArgumentException('One or more invalid functions specified in array'); } } - $this->functions = array_merge($this->functions, $function); + } elseif (is_string($function) && function_exists($function)) { $this->functions[] = $function; + } elseif ($function == SOAP_FUNCTIONS_ALL) { $this->functions = SOAP_FUNCTIONS_ALL; + } else { throw new Exception\InvalidArgumentException('Invalid function specified'); } @@ -528,7 +589,9 @@ public function addFunction($function, $namespace = '') public function setClass($class, $namespace = '', $argv = null) { if (isset($this->class)) { - throw new Exception\InvalidArgumentException('A class has already been registered with this soap server instance'); + throw new Exception\InvalidArgumentException( + 'A class has already been registered with this soap server instance' + ); } if (is_object($class)) { @@ -536,11 +599,15 @@ public function setClass($class, $namespace = '', $argv = null) } if (!is_string($class)) { - throw new Exception\InvalidArgumentException('Invalid class argument (' . gettype($class) . ')'); + throw new Exception\InvalidArgumentException( + 'Invalid class argument (' . gettype($class) . ')' + ); } if (!class_exists($class)) { - throw new Exception\InvalidArgumentException('Class "' . $class . '" does not exist'); + throw new Exception\InvalidArgumentException( + 'Class "' . $class . '" does not exist' + ); } $this->class = $class; @@ -555,20 +622,25 @@ public function setClass($class, $namespace = '', $argv = null) /** * Attach an object to a server * - * Accepts an instanciated object to use when handling requests. + * Accepts an instantiated object to use when handling requests. * * @param object $object * @throws Exception\InvalidArgumentException + * * @return Server */ public function setObject($object) { if (!is_object($object)) { - throw new Exception\InvalidArgumentException('Invalid object argument ('.gettype($object).')'); + throw new Exception\InvalidArgumentException( + 'Invalid object argument ('.gettype($object).')' + ); } if (isset($this->object)) { - throw new Exception\InvalidArgumentException('An object has already been registered with this soap server instance'); + throw new Exception\InvalidArgumentException( + 'An object has already been registered with this soap server instance' + ); } $this->object = $object; @@ -583,7 +655,6 @@ public function setObject($object) * merged with all public methods of the class set with {@link setClass()} * (if any). * - * @access public * @return array */ public function getFunctions() @@ -602,8 +673,9 @@ public function getFunctions() * Unimplemented: Load server definition * * @param array $definition - * @return void * @throws Exception\RuntimeException Unimplemented + * + * @return void */ public function loadFunctions($definition) { @@ -613,8 +685,9 @@ public function loadFunctions($definition) /** * Set server persistence * - * @param int $mode + * @param int $mode SOAP_PERSISTENCE_SESSION or SOAP_PERSISTENCE_REQUEST constants * @throws Exception\InvalidArgumentException + * * @return Server */ public function setPersistence($mode) @@ -624,6 +697,7 @@ public function setPersistence($mode) } $this->persistence = $mode; + return $this; } @@ -653,23 +727,35 @@ public function getPersistence() */ protected function _setRequest($request) { + $xml = null; + if ($request instanceof DOMDocument) { $xml = $request->saveXML(); + } elseif ($request instanceof DOMNode) { $xml = $request->ownerDocument->saveXML(); + } elseif ($request instanceof SimpleXMLElement) { $xml = $request->asXML(); + } elseif (is_object($request) || is_string($request)) { if (is_object($request)) { $xml = $request->__toString(); } else { $xml = $request; } + $xml = trim($xml); + libxml_disable_entity_loader(true); + $dom = new DOMDocument(); - if (strlen($xml) == 0 || !$dom->loadXML($xml)) { + $loadStatus = $dom->loadXML($xml); + + //@todo check libxml errors ? validate document ? + if (strlen($xml) == 0 || !$loadStatus) { throw new Exception\InvalidArgumentException('Invalid XML'); } + foreach ($dom->childNodes as $child) { if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { throw new Exception\InvalidArgumentException( @@ -679,7 +765,9 @@ protected function _setRequest($request) } libxml_disable_entity_loader(false); } + $this->request = $xml; + return $this; } @@ -865,10 +953,40 @@ protected function _initializeSoapErrorContext() */ public function registerFaultException($class) { - $this->faultExceptions = array_merge($this->faultExceptions, (array) $class); + + if (is_array($class)) { + foreach($class as $row) { + $this->registerFaultException($row); + } + + } elseif (is_string($class) && class_exists($class) + && is_subclass_of($class, 'Exception') + ) { + $ref = new \ReflectionClass($class); + + $this->faultExceptions[] = $ref->getName(); + $this->faultExceptions = array_unique($this->faultExceptions); + } else { + throw new Exception\InvalidArgumentException('Argument for' + .' \Zend\Soap\Server::registerFaultException should be string or ' + . 'array of strings with valid exception names' + ); + } + return $this; } + /** + * @param $fault + */ + public function isRegisteredAsFaultException($fault){ + $ref = new \ReflectionClass($fault); + + $classNames = $ref->getName(); + + return in_array($classNames, $this->faultExceptions); + } + /** * Deregister a fault exception from the fault exception stack * @@ -913,8 +1031,7 @@ public function getFaultExceptions() public function fault($fault = null, $code = "Receiver") { if ($fault instanceof \Exception) { - $class = get_class($fault); - if (in_array($class, $this->faultExceptions)) { + if ($this->isRegisteredAsFaultException($fault)) { $message = $fault->getMessage(); $eCode = $fault->getCode(); $code = empty($eCode) ? $code : $eCode; diff --git a/src/Server/DocumentLiteralWrapper.php b/src/Server/DocumentLiteralWrapper.php old mode 100644 new mode 100755 index 205ebe4e..c25905ef --- a/src/Server/DocumentLiteralWrapper.php +++ b/src/Server/DocumentLiteralWrapper.php @@ -161,7 +161,8 @@ protected function _assertOnlyOneArgument($args) if (count($args) != 1) { throw new UnexpectedValueException(sprintf( "Expecting exactly one argument that is the document/literal wrapper, got %d", - count($args))); + count($args)) + ); } } } diff --git a/src/Wsdl.php b/src/Wsdl.php index 6736a2a8..aa1c1d5a 100755 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -12,6 +12,7 @@ use DOMDocument; use DOMElement; +use Zend\Soap\Exception\InvalidArgumentException; use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy; use Zend\Uri\Uri; @@ -62,12 +63,12 @@ class Wsdl */ protected $classMap = array(); - const NS_WSDL = 'http://schemas.xmlsoap.org/wsdl/'; const NS_XMLNS = 'http://www.w3.org/2000/xmlns/'; const NS_SOAP = 'http://schemas.xmlsoap.org/wsdl/soap/'; const NS_SCHEMA = 'http://www.w3.org/2001/XMLSchema'; const NS_S_ENC = 'http://schemas.xmlsoap.org/soap/encoding/'; + /** * Constructor * @@ -82,10 +83,11 @@ public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, a if ($uri instanceof Uri) { $uri = $uri->toString(); } - $this->uri = $uri; + + $this->setUri($uri); $this->classMap = $classMap; - $this->dom = $this->getDOMDocument($uri, $name); + $this->dom = $this->getDOMDocument($name, $this->getUri()); $this->wsdl = $this->dom->documentElement; @@ -99,24 +101,27 @@ public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, a * @param string $name * @return \DOMDocument */ - protected function getDOMDocument($uri, $name) + protected function getDOMDocument($name, $uri = null) { $dom = new \DOMDocument(); $dom->preserveWhiteSpace = true; $dom->formatOutput = true; + $dom->encoding = 'UTF-8'; $definitions = $dom->createElementNS(Wsdl::NS_WSDL, 'definitions'); + $dom->appendChild($definitions); + + $uri = $this->sanitizeUri($uri); + + $definitions->setAttribute('name', $name); + $definitions->setAttribute('targetNamespace', $uri); + + $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:wsdl', Wsdl::NS_WSDL); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:tns', $uri); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:soap', Wsdl::NS_SOAP); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:xsd', Wsdl::NS_SCHEMA); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:soap-enc', Wsdl::NS_S_ENC); - $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:wsdl', Wsdl::NS_WSDL); - - $definitions->setAttributeNS(Wsdl::NS_WSDL, 'name', $name); - $definitions->setAttributeNS(Wsdl::NS_WSDL, 'targetNamespace', $uri); - - $dom->appendChild($definitions); return $dom; } @@ -147,19 +152,70 @@ public function setClassMap($classMap) */ public function setUri($uri) { - if ($uri instanceof Uri) { - $uri = $uri->toString(); - } + $uri = $this->sanitizeUri($uri); + + $oldUri = $this->uri; $this->uri = $uri; if($this->dom instanceof \DOMDocument ) { + // namespace declarations are NOT true attributes $this->dom->documentElement->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:tns', $uri); - $this->dom->documentElement->setAttributeNS(Wsdl::NS_WSDL, 'targetNamespace', $uri); + + + $xpath = new \DOMXPath($this->dom); + $xpath->registerNamespace('unittest', Wsdl::NS_WSDL); + + $xpath->registerNamespace('tns', $uri); + $xpath->registerNamespace('soap', Wsdl::NS_SOAP); + $xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); + $xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); + $xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + + // select only attribute nodes. Data nodes does not contain uri except for documentation node but + // this is for the user to decide + $attributeNodes = $xpath->query('//attribute::*[contains(., "'.$oldUri.'")]'); + + /** @var $node \DOMAttr */ + foreach ($attributeNodes as $node) { +// var_dump(array($oldUri, $uri, $node->nodeValue, str_replace($oldUri, $uri, $node->nodeValue))); + $node->nodeValue = str_replace($oldUri, $uri, $node->nodeValue); + } } return $this; } + /** + * @return string + */ + public function getUri() { + return $this->uri; + } + + /** + * Function for sanitizing uri + * + * @param $uri + * + * @throws Exception\InvalidArgumentException + * @return string + */ + public function sanitizeUri($uri) { + + if ($uri instanceof Uri) { + $uri = $uri->toString(); + } + + $uri = trim($uri); + $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); + + if (empty($uri)) { + throw new InvalidArgumentException('Uri contains invalid characters or is empty'); + } + + return $uri; + } + /** * Set a strategy for complex type detection and handling * @@ -281,11 +337,11 @@ public function addBinding($name, $portType) $binding = $this->dom->createElementNS(Wsdl::NS_WSDL, 'binding'); $this->wsdl->appendChild($binding); - $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, 'name'); + $attr = $this->dom->createAttribute('name'); $attr->value = $name; $binding->appendChild($attr); - $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, 'type'); + $attr = $this->dom->createAttribute('type'); $attr->value = $portType; $binding->appendChild($attr); @@ -306,7 +362,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $operation = $this->dom->createElementNS(Wsdl::NS_WSDL, 'operation'); $binding->appendChild($operation); - $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, 'name'); + $attr = $this->dom->createAttribute('name'); $attr->value = $name; $operation->appendChild($attr); @@ -318,7 +374,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $node->appendChild($soapNode); foreach ($input as $name => $value) { - $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, $name); + $attr = $this->dom->createAttribute($name); $attr->value = $value; $soapNode->appendChild($attr); } @@ -333,7 +389,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $node->appendChild($soapNode); foreach ($output as $name => $value) { - $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, $name); + $attr = $this->dom->createAttribute($name); $attr->value = $value; $soapNode->appendChild($attr); } @@ -344,13 +400,11 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $operation->appendChild($node); foreach ($fault as $name => $value) { - $attr = $this->dom->createAttributeNS(Wsdl::NS_WSDL, $name); + $attr = $this->dom->createAttribute($name); $attr->value = $value; $node->appendChild($attr); } -// $node->appendChild($soapNode); -// $operation->appendChild($node); } return $operation; @@ -366,7 +420,8 @@ public function addBindingOperation($binding, $name, $input = false, $output = f */ public function addSoapBinding($binding, $style = 'document', $transport = 'http://schemas.xmlsoap.org/soap/http') { - $soapBinding = $this->dom->createElement('soap:binding'); + + $soapBinding = $this->dom->createElementNS(WSDL::NS_SOAP, 'binding'); $soapBinding->setAttribute('style', $style); $soapBinding->setAttribute('transport', $transport); @@ -387,7 +442,7 @@ public function addSoapOperation($binding, $soapAction) if ($soapAction instanceof Uri) { $soapAction = $soapAction->toString(); } - $soapOperation = $this->dom->createElement('soap:operation'); + $soapOperation = $this->dom->createElementNS(WSDL::NS_SOAP, 'operation'); $soapOperation->setAttribute('soapAction', $soapAction); $binding->insertBefore($soapOperation, $binding->firstChild); @@ -409,20 +464,21 @@ public function addService($name, $portName, $binding, $location) if ($location instanceof Uri) { $location = $location->toString(); } - $service = $this->dom->createElement('service'); + $service = $this->dom->createElementNS(WSDL::NS_WSDL, 'service'); $service->setAttribute('name', $name); - $port = $this->dom->createElement('port'); + $this->wsdl->appendChild($service); + + $port = $this->dom->createElementNS(WSDL::NS_WSDL, 'port'); $port->setAttribute('name', $portName); $port->setAttribute('binding', $binding); - $soapAddress = $this->dom->createElement('soap:address'); + $service->appendChild($port); + + $soapAddress = $this->dom->createElementNS(WSDL::NS_SOAP, 'address'); $soapAddress->setAttribute('location', $location); $port->appendChild($soapAddress); - $service->appendChild($port); - - $this->wsdl->appendChild($service); return $service; } @@ -446,16 +502,16 @@ public function addDocumentation($inputNode, $documentation) $node = $inputNode; } - $doc = $this->dom->createElement('documentation'); - $docCData = $this->dom->createTextNode(str_replace(array("\r\n", "\r"), "\n", $documentation)); - $doc->appendChild($docCData); - + $doc = $this->dom->createElementNS(WSDL::NS_WSDL, 'documentation'); if ($node->hasChildNodes()) { $node->insertBefore($doc, $node->firstChild); } else { $node->appendChild($doc); } + $docCData = $this->dom->createTextNode(str_replace(array("\r\n", "\r"), "\n", $documentation)); + $doc->appendChild($docCData); + return $doc; } @@ -469,8 +525,8 @@ public function addDocumentation($inputNode, $documentation) public function addTypes($types) { if ($types instanceof \DomDocument) { - $this->dom->importNode($types->documentElement); - $this->wsdl->appendChild($types->documentElement); + $dom = $this->dom->importNode($types->documentElement); + $this->wsdl->appendChild($dom); } elseif ($types instanceof \DomNode || $types instanceof \DomElement || $types instanceof \DomDocumentFragment ) { $dom = $this->dom->importNode($types); $this->wsdl->appendChild($dom); @@ -529,7 +585,7 @@ public function toXML() /** * Return DOM Document * - * @return object DomDocument + * @return \DOMDocument */ public function toDomDocument() { @@ -543,11 +599,15 @@ public function toDomDocument() */ public function dump($filename = false) { + if (!$filename) { echo $this->toXML(); return true; } - return file_put_contents($filename, $this->toXML()); + + $i = file_put_contents($filename, $this->toXML()); + + return $i > 0; } /** @@ -596,12 +656,16 @@ public function getType($type) public function addSchemaTypeSection() { if ($this->schema === null) { - $this->schema = $this->dom->createElement('xsd:schema'); - $this->schema->setAttribute('targetNamespace', $this->uri); - $types = $this->dom->createElement('types'); - $types->appendChild($this->schema); + + $types = $this->dom->createElementNS(Wsdl::NS_WSDL, 'types'); $this->wsdl->appendChild($types); + + $this->schema = $this->dom->createElementNS(WSDL::NS_SCHEMA, 'schema'); + $types->appendChild($this->schema); + + $this->schema->setAttribute('targetNamespace', $this->getUri()); } + return $this; } @@ -617,16 +681,15 @@ public function translateType($type) return $this->classMap[$type]; } - if ($type[0] == '\\') { - $type = substr($type, 1); - } + $type = trim($type,'\\'); + // remove namespace, $pos = strrpos($type, '\\'); if ($pos) { $type = substr($type, $pos+1); } - return str_replace('\\', '.', $type); + return $type; } /** @@ -661,26 +724,26 @@ private function _parseElement($element) throw new Exception\RuntimeException("The 'element' parameter needs to be an associative array."); } - $elementXml = $this->dom->createElement('xsd:element'); + $elementXML = $this->dom->createElementNS(Wsdl::NS_SCHEMA, 'element'); foreach ($element as $key => $value) { if (in_array($key, array('sequence', 'all', 'choice'))) { if (is_array($value)) { - $complexType = $this->dom->createElement('xsd:complexType'); + $complexType = $this->dom->createElementNS(Wsdl::NS_SCHEMA, 'complexType'); if (count($value) > 0) { - $container = $this->dom->createElement('xsd:' . $key); - foreach ($value as $subelement) { - $subelementXml = $this->_parseElement($subelement); - $container->appendChild($subelementXml); + $container = $this->dom->createElementNS(Wsdl::NS_SCHEMA, $key); + foreach ($value as $subElement) { + $subElementXML = $this->_parseElement($subElement); + $container->appendChild($subElementXML); } $complexType->appendChild($container); } - $elementXml->appendChild($complexType); + $elementXML->appendChild($complexType); } } else { - $elementXml->setAttribute($key, $value); + $elementXML->setAttribute($key, $value); } } - return $elementXml; + return $elementXML; } /** diff --git a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php old mode 100644 new mode 100755 index 5b779e12..b83c2967 --- a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php +++ b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php @@ -55,6 +55,7 @@ public function getContext() */ public function scanRegisteredTypes($phpType) { + if (array_key_exists($phpType, $this->getContext()->getTypes())) { $soapTypes = $this->getContext()->getTypes(); return $soapTypes[$phpType]; diff --git a/src/Wsdl/ComplexTypeStrategy/AnyType.php b/src/Wsdl/ComplexTypeStrategy/AnyType.php old mode 100644 new mode 100755 index 658b3fc9..f887e04d --- a/src/Wsdl/ComplexTypeStrategy/AnyType.php +++ b/src/Wsdl/ComplexTypeStrategy/AnyType.php @@ -25,9 +25,7 @@ class AnyType implements ComplexTypeStrategyInterface * @param \Zend\Soap\Wsdl $context */ public function setContext(\Zend\Soap\Wsdl $context) - { - - } + {} /** * Returns xsd:anyType regardless of the input. diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php old mode 100644 new mode 100755 index f1bde27b..fb171dbe --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php @@ -11,6 +11,7 @@ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; use Zend\Soap\Exception; +use Zend\Soap\Wsdl; /** * ArrayOfTypeComplex strategy @@ -22,7 +23,8 @@ class ArrayOfTypeComplex extends DefaultComplexType { /** - * Add an ArrayOfType based on the xsd:complexType syntax if type[] is detected in return value doc comment. + * Add an ArrayOfType based on the xsd:complexType syntax if type[] is + * detected in return value doc comment. * * @param string $type * @throws Exception\InvalidArgumentException @@ -51,7 +53,8 @@ public function addComplexType($type) } /** - * Add an ArrayOfType based on the xsd:complexType syntax if type[] is detected in return value doc comment. + * Add an ArrayOfType based on the xsd:complexType syntax if type[] is + * detected in return value doc comment. * * @param string $singularType e.g. '\MyNamespace\MyClassname' * @param string $type e.g. '\MyNamespace\MyClassname[]' @@ -76,23 +79,24 @@ protected function _addArrayOfComplexType($singularType, $type) // Add array type structure to WSDL document $dom = $this->getContext()->toDomDocument(); - $complexType = $dom->createElement('xsd:complexType'); + $complexType = $dom->createElementNS(Wsdl::NS_SCHEMA, 'complexType'); + $this->getContext()->getSchema()->appendChild($complexType); + $complexType->setAttribute('name', $xsdComplexTypeName); - $complexContent = $dom->createElement('xsd:complexContent'); + $complexContent = $dom->createElementNS(Wsdl::NS_SCHEMA, 'complexContent'); $complexType->appendChild($complexContent); - $xsdRestriction = $dom->createElement('xsd:restriction'); + $xsdRestriction = $dom->createElementNS(Wsdl::NS_SCHEMA, 'restriction'); $xsdRestriction->setAttribute('base', 'soap-enc:Array'); $complexContent->appendChild($xsdRestriction); - $xsdAttribute = $dom->createElement('xsd:attribute'); - $xsdAttribute->setAttribute('ref', 'soap-enc:arrayType'); - $xsdAttribute->setAttribute('wsdl:arrayType', - 'tns:' . $this->getContext()->translateType($singularType) . '[]'); + $xsdAttribute = $dom->createElementNS(Wsdl::NS_SCHEMA, 'attribute'); $xsdRestriction->appendChild($xsdAttribute); - $this->getContext()->getSchema()->appendChild($complexType); + $xsdAttribute->setAttribute('ref', 'soap-enc:arrayType'); + $xsdAttribute->setAttributeNS(Wsdl::NS_WSDL, 'arrayType', + 'tns:' . $this->getContext()->translateType($singularType) . '[]'); return $xsdComplexType; } diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php old mode 100644 new mode 100755 index 03a81d2e..ea81eb2c --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php @@ -10,6 +10,8 @@ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; +use Zend\Soap\Wsdl; + /** * Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence * @@ -20,7 +22,8 @@ class ArrayOfTypeSequence extends DefaultComplexType { /** - * Add an unbounded ArrayOfType based on the xsd:sequence syntax if type[] is detected in return value doc comment. + * Add an unbounded ArrayOfType based on the xsd:sequence syntax if + * type[] is detected in return value doc comment. * * @param string $type * @return string tns:xsd-type @@ -31,6 +34,7 @@ public function addComplexType($type) if ($nestedCounter > 0) { $singularType = $this->_getSingularType($type); + $complexType = ''; for ($i = 1; $i <= $nestedCounter; $i++) { $complexType = $this->_getTypeBasedOnNestingLevel($singularType, $i); @@ -51,7 +55,8 @@ public function addComplexType($type) } /** - * Return the ArrayOf or simple type name based on the singular xsdtype and the nesting level + * Return the ArrayOf or simple type name based on the singular xsdtype + * and the nesting level * * @param string $singularType * @param int $level @@ -111,19 +116,19 @@ protected function _addSequenceType($arrayType, $childType, $phpArrayType) $arrayTypeName = substr($arrayType, strpos($arrayType, ':') + 1); - $complexType = $dom->createElement('xsd:complexType'); + $complexType = $dom->createElementNS(Wsdl::NS_SCHEMA, 'complexType'); $complexType->setAttribute('name', $arrayTypeName); - $sequence = $dom->createElement('xsd:sequence'); + $sequence = $dom->createElementNS(Wsdl::NS_SCHEMA, 'sequence'); + $complexType->appendChild($sequence); + + $element = $dom->createElementNS(Wsdl::NS_SCHEMA, 'element'); + $sequence->appendChild($element); - $element = $dom->createElement('xsd:element'); $element->setAttribute('name', 'item'); $element->setAttribute('type', $childType); $element->setAttribute('minOccurs', 0); $element->setAttribute('maxOccurs', 'unbounded'); - $sequence->appendChild($element); - - $complexType->appendChild($sequence); $this->getContext()->getSchema()->appendChild($complexType); } diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php old mode 100644 new mode 100755 index cac9f02d..8dda7c8b --- a/src/Wsdl/ComplexTypeStrategy/Composite.php +++ b/src/Wsdl/ComplexTypeStrategy/Composite.php @@ -50,8 +50,9 @@ class Composite implements ComplexTypeStrategy * @param array $typeMap * @param string|ComplexTypeStrategy $defaultStrategy */ - public function __construct(array $typeMap=array(), $defaultStrategy='\Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType') - { + public function __construct(array $typeMap=array(), + $defaultStrategy='\Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType' + ) { foreach ($typeMap AS $type => $strategy) { $this->connectTypeToStrategy($type, $strategy); } diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php old mode 100644 new mode 100755 index 78f14829..51cdbb68 --- a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php +++ b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php @@ -11,6 +11,7 @@ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; use Zend\Soap\Exception; +use Zend\Soap\Wsdl; /** * Zend_Soap_Wsdl_Strategy_DefaultComplexType @@ -33,7 +34,8 @@ public function addComplexType($type) if (!class_exists($type)) { throw new Exception\InvalidArgumentException(sprintf( 'Cannot add a complex type %s that is not an object or where ' - . 'class could not be found in \'DefaultComplexType\' strategy.', $type + . 'class could not be found in \'DefaultComplexType\' strategy.', + $type )); } @@ -53,19 +55,22 @@ public function addComplexType($type) $defaultProperties = $class->getDefaultProperties(); - $complexType = $dom->createElement('xsd:complexType'); + $complexType = $dom->createElementNS(Wsdl::NS_SCHEMA, 'complexType'); $complexType->setAttribute('name', $soapTypeName); - $all = $dom->createElement('xsd:all'); + $all = $dom->createElementNS(Wsdl::NS_SCHEMA, 'all'); foreach ($class->getProperties() as $property) { - if ($property->isPublic() && preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches)) { + if ($property->isPublic() + && preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches) + ) { /** - * @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType' - * node for describing other classes used as attribute types for current class + * @todo check if 'xsd:element' must be used here (it may not be + * compatible with using 'complexType' node for describing other + * classes used as attribute types for current class */ - $element = $dom->createElement('xsd:element'); + $element = $dom->createElementNS(Wsdl::NS_SCHEMA, 'element'); $element->setAttribute('name', $propertyName = $property->getName()); $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0]))); diff --git a/test/AutoDiscoverTest.php b/test/AutoDiscoverTest.php old mode 100644 new mode 100755 index 098511c9..631ed1f4 --- a/test/AutoDiscoverTest.php +++ b/test/AutoDiscoverTest.php @@ -13,7 +13,10 @@ /** Include Common TestTypes */ require_once 'TestAsset/commontypes.php'; +use Zend\Di\Exception\RuntimeException; use Zend\Soap\AutoDiscover; +use Zend\Soap\Wsdl; +use Zend\Uri\Uri; /** PHPUnit Test Case */ @@ -27,19 +30,59 @@ */ class AutoDiscoverTest extends \PHPUnit_Framework_TestCase { - protected function createAutodiscoverService() + + /** + * @var AutoDiscover + */ + protected $server; + + /** + * @var string + */ + protected $defaultServiceName = 'MyService'; + + /** + * @var string + */ + protected $defaultServiceUri = 'http://localhost/MyService.php'; + + /** + * @var \DOMDocument + */ + protected $dom; + + /** + * @var \DOMXPath + */ + protected $xpath; + + public function setUp() { - $server = new AutoDiscover(); - $server->setUri('http://localhost/my_script.php'); - $server->setServiceName('TestService'); - return $server; + $this->server = new AutoDiscover(); + $this->server->setUri($this->defaultServiceUri); + $this->server->setServiceName($this->defaultServiceName); } - protected function sanitizeWsdlXmlOutputForOsCompability($xmlstring) + public function bindWsdl(Wsdl $wsdl, $documentNamespace = null) { - $xmlstring = str_replace(array("\r", "\n"), "", $xmlstring); - $xmlstring = preg_replace('/(>[\s]{1,}<)/', '', $xmlstring); - return $xmlstring; + $this->dom = new \DOMDocument(); + $this->dom->formatOutput = true; + $this->dom->preserveWhiteSpace = false; + $this->dom->loadXML($wsdl->toXML()); + + if (empty($documentNamespace)) { + $documentNamespace = $this->defaultServiceUri; + } + + $this->xpath = new \DOMXPath($this->dom); + + $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); + + $this->xpath->registerNamespace('tns', $documentNamespace); + $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); + $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); + $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); + $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); } /** @@ -50,6 +93,7 @@ protected function sanitizeWsdlXmlOutputForOsCompability($xmlstring) protected function assertValidWSDL(\DOMDocument $dom) { // this code is necessary to support some libxml stupidities. + // @todo memory streams ? $file = __DIR__.'/TestAsset/validate.wsdl'; if (file_exists($file)) { unlink($file); @@ -63,238 +107,326 @@ protected function assertValidWSDL(\DOMDocument $dom) unlink($file); } - public function testSetClass() + /** + * @param \DOMElement $element + */ + public function testDocumentNodes($element = null) { - $scriptUri = 'http://localhost/my_script.php'; + if (!($this->dom instanceof \DOMDocument)) { + return; + } + + if (is_null($element)) { + $element = $this->dom->documentElement; + } + + /** @var $node \DOMElement */ + foreach ($element->childNodes as $node) { + if (in_array($node->nodeType, array(XML_ELEMENT_NODE))) { + $this->assertNotEmpty($node->namespaceURI, 'Document element: ' . $node->nodeName . ' has no valid namespace. Line: ' . $node->getLineNo()); + $this->testDocumentNodes($node); + } + } + } + + /** + * @dataProvider dataProviderValidUris + */ + public function testAutoDiscoverConstructorUri($uri) { + $server = new AutoDiscover(null, $uri); + + //@todo Uri::toString returns encoded uri + $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); + $this->assertEquals($uri, $server->getUri()->toString()); + } + + /** + * @dataProvider dataProviderForAutoDiscoverConstructorStrategy + */ + public function testAutoDiscoverConstructorStrategy($strategy) { + $server = new AutoDiscover($strategy); + + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $server->setServiceName('TestService'); + $server->setUri('http://example.com'); + $wsdl = $server->generate(); + + $this->assertEquals(get_class($strategy), get_class($wsdl->getComplexTypeStrategy())); + } + + /** + * @return array + */ + public function dataProviderForAutoDiscoverConstructorStrategy() { + return array( + array(new Wsdl\ComplexTypeStrategy\AnyType()), + array(new Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex()), + array(new Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence()), + array(new Wsdl\ComplexTypeStrategy\Composite()), + array(new Wsdl\ComplexTypeStrategy\DefaultComplexType()), + ); + } + + /** + */ + public function testGetDiscoveryStrategy() { + $server = new AutoDiscover(); + + $this->assertEquals('Zend\Soap\AutoDiscover\DiscoveryStrategy\ReflectionDiscovery', + get_class($server->getDiscoveryStrategy()) + ); + } + + /** + */ + public function testAutoDiscoverConstructorWsdlClass() { + $server = new AutoDiscover(null, null, '\Zend\Soap\Wsdl'); + + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $server->setServiceName('TestService'); + $server->setUri('http://example.com'); + $wsdl = $server->generate(); + + $this->assertEquals('Zend\Soap\Wsdl', trim(get_class($wsdl), '\\')); + $this->assertEquals('Zend\Soap\Wsdl', trim($server->getWsdlClass(), '\\')); + } + + /** + * @expectedException \Zend\Soap\Exception\InvalidArgumentException + */ + public function testAutoDiscoverConstructorWsdlClassException() { + $server = new AutoDiscover(); + $server->setWsdlClass(new \stdClass()); + } + + /** + * @dataProvider dataProviderForSetServiceName + */ + public function testSetServiceName($newName, $shouldBeValid) { + + if ($shouldBeValid == false) { + $this->setExpectedException('InvalidArgumentException'); + } + + $this->server->setServiceName($newName); + $this->bindWsdl($this->server->generate()); + $this->assertSpecificNodeNumberInXPath(1, '/wsdl:definitions[@name="'.$newName.'"]'); + } + + /** + * @return array + */ + public function dataProviderForSetServiceName() { + return array( + array('MyServiceName123', true), + array('1MyServiceName123', false), + array('$MyServiceName123', false), + array('!MyServiceName123', false), + array('&MyServiceName123', false), + array('(MyServiceName123', false), + array('\MyServiceName123', false), + ); + } + + public function testGetServiceName() { + $server = new AutoDiscover(); - $server = $this->createAutodiscoverService(); $server->setClass('\ZendTest\Soap\TestAsset\Test'); - $dom = $server->generate()->toDomDocument(); - - $wsdl = '' - . '' - . '' - . '' - . '' - . '' - . '' - . 'Test Function 1' - . '' - . '' - . '' - . '' - . 'Test Function 2' - . '' - . '' - . '' - . '' - . 'Test Function 3' - . '' - . '' - . '' - . 'Test Function 4' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . ''; - - $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); - $this->assertValidWSDL($dom); + + $this->assertEquals('Test', $server->getServiceName()); + } + + /** + * @expectedException \Zend\Soap\Exception\RuntimeException + */ + public function testGetServiceNameException() { + $server = new AutoDiscover(); + + $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + + $this->assertEquals('Test', $server->getServiceName()); + } + + /** + * @expectedException \Zend\Soap\Exception\InvalidArgumentException + */ + public function testSetUriException() { + $server = new AutoDiscover(); + + $server->setUri(' '); + } + + /** + * @expectedException \Zend\Soap\Exception\RuntimeException + */ + public function testGetUriException() { + $server = new AutoDiscover(); + $server->getUri(); + } + + public function testClassMap() { + + $classMap = array( + 'TestClass' => 'test_class' + ); + + $this->server->setClassMap($classMap); + + $this->assertEquals($classMap, $this->server->getClassMap()); + } + + public function testSetClass() + { + $this->server->setClass('\ZendTest\Soap\TestAsset\Test'); + + $this->bindWsdl($this->server->generate()); + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]', 'Invalid schema definition'); + + for($i = 1; $i <= 4; $i++) { + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]', 'Invalid func'.$i.' operation definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:documentation', 'Invalid func'.$i.' port definition - documentation node'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:input[@message="tns:testFunc'.$i.'In"]', 'Invalid func'.$i.' port definition - input node'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:output[@message="tns:testFunc'.$i.'Out"]', 'Invalid func'.$i.' port definition - output node'); + } + + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]', 'Invalid service binding definition'); + $this->assertEquals('tns:MyServicePort', $nodes->item(0)->getAttribute('type'), 'Invalid type attribute value in service binding definition'); + + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/soap:binding', 'Invalid service binding definition'); + $this->assertEquals('rpc', $nodes->item(0)->getAttribute('style'), 'Invalid style attribute value in service binding definition'); + $this->assertEquals('http://schemas.xmlsoap.org/soap/http', $nodes->item(0)->getAttribute('transport'), 'Invalid transport attribute value in service binding definition'); + + for($i = 1; $i <= 4; $i++) { + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]', 'Invalid func'.$i.' operation binding definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#testFunc'.$i.'"]', 'Invalid func'.$i.' operation action binding definition'); + } + + $xpath = '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[wsdl:input or wsdl:output]/*/soap:body'; + $this->assertSpecificNodeNumberInXPath(8, $xpath); + $nodes = $this->xpath->query($xpath); + $this->assertAttributesOfNodes(array( + "use" => "encoded", + "encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/", + "namespace" => "http://localhost/MyService.php" + ), $nodes); + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]', 'Invalid service definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]', 'Invalid service port definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Invalid service address definition'); + + + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc1In"]', 'Invalid message definition'); + $this->assertFalse($nodes->item(0)->hasChildNodes()); + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc2In"]', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc2In"]/wsdl:part[@name="who" and @type="xsd:string"]', 'Invalid message definition'); + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc2Out"]', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc2Out"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Invalid message definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc3In"]', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath(2, '//wsdl:message[@name="testFunc3In"][(wsdl:part[@name="who" and @type="xsd:string"]) or (wsdl:part[@name="when" and @type="xsd:int"])]/wsdl:part', 'Invalid message definition'); + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc3Out"]', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc3Out"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Invalid message definition'); + + + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc4In"]', 'Invalid message definition'); + $this->assertFalse($nodes->item(0)->hasChildNodes()); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc4Out"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Invalid message definition'); + + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } public function testSetClassWithDifferentStyles() { - $scriptUri = 'http://localhost/my_script.php'; + $this->server->setBindingStyle(array('style' => 'document', 'transport' => $this->defaultServiceUri)); + $this->server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => $this->defaultServiceUri)); + $this->server->setClass('\ZendTest\Soap\TestAsset\Test'); + + $this->bindWsdl($this->server->generate()); + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]', 'Missing test func1 definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]/xsd:complexType', 'Missing test func1 type definition'); + $this->assertSpecificNodeNumberInXPath(0, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]/xsd:complexType/*', 'Test func1 does not have children'); + + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1Response"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func1 return element is invalid'); + $this->assertAttributesOfNodes(array( + 'name' => "testFunc1Result", + 'type' => "xsd:string", + ), $nodes); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]', 'Missing test func2 definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]/xsd:complexType', 'Missing test func2 type definition'); + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func2 does not have children'); + $this->assertAttributesOfNodes(array( + 'name' => "who", + 'type' => "xsd:string", + ), $nodes); + + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2Response"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func2 return element is invalid'); + $this->assertAttributesOfNodes(array( + 'name' => "testFunc2Result", + 'type' => "xsd:string", + ), $nodes); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]', 'Missing test func3 definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType', 'Missing test func3 type definition'); + $this->assertSpecificNodeNumberInXPath(2, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func3 does not have children'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/xsd:sequence/xsd:element[@name="who" and @type="xsd:string"]', 'Test func3 does not have children'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/xsd:sequence/xsd:element[@name="when" and @type="xsd:int"]', 'Test func3 does not have children'); + + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3Response"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func3 return element is invalid'); + $this->assertAttributesOfNodes(array( + 'name' => "testFunc3Result", + 'type' => "xsd:string", + ), $nodes); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]', 'Missing test func1 definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]/xsd:complexType', 'Missing test func1 type definition'); + $this->assertSpecificNodeNumberInXPath(0, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]/xsd:complexType/*', 'Test func1 does not have children'); + + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4Response"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func1 return element is invalid'); + $this->assertAttributesOfNodes(array( + 'name' => "testFunc4Result", + 'type' => "xsd:string", + ), $nodes); + + + for ($i = 1; $i <= 4; $i++) { + $this->assertSpecificNodeNumberInXPath(3, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/*', 'Missing test func'.$i.' port definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:documentation', 'Missing test func'.$i.' port documentation'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:input[@message="tns:testFunc'.$i.'In"]', 'Missing test func'.$i.' port input message'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:output[@message="tns:testFunc'.$i.'Out"]', 'Missing test func'.$i.' port output message'); + } - $server = $this->createAutodiscoverService(); - $server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com')); - $server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com')); - $server->setClass('\ZendTest\Soap\TestAsset\Test'); - $dom = $server->generate()->toDomDocument(); - - $wsdl = '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . 'Test Function 1' - . '' - . '' - . '' - . '' - . 'Test Function 2' - . '' - . '' - . '' - . '' - . 'Test Function 3' - . '' - . '' - . '' - . 'Test Function 4' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . ''; - - $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); - $this->assertValidWSDL($dom); + + for ($i = 1; $i <= 4; $i++) { + $this->assertSpecificNodeNumberInXPath(3, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/*', 'Missing test func'.$i.' binding definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#testFunc'.$i.'"]', 'Missing test func'.$i.' binding operation definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:input/soap:body[@use="literal" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing test func'.$i.' binding input message'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:output/soap:body[@use="literal" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing test func'.$i.' binding input message'); + } + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]'); + + + for ($i = 1; $i <= 4; $i++) { + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc'.$i.'In"]/wsdl:part[@name="parameters" and @element="tns:testFunc'.$i.'"]', 'Missing test testFunc'.$i.' input message definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc'.$i.'Out"]/wsdl:part[@name="parameters" and @element="tns:testFunc'.$i.'Response"]', 'Missing test testFunc'.$i.' output message definition'); + } + + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** @@ -302,99 +434,103 @@ public function testSetClassWithDifferentStyles() */ public function testSetClassWithResponseReturnPartCompabilityMode() { - $scriptUri = 'http://localhost/my_script.php'; + $this->server->setClass('\ZendTest\Soap\TestAsset\Test'); + $this->bindWsdl($this->server->generate()); + + + for ($i = 1; $i <= 4; $i++) { + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc'.$i.'Out"]/wsdl:part[@name="return"]'); + } - $server = $this->createAutodiscoverService(); - $server->setClass('\ZendTest\Soap\TestAsset\Test'); - $dom = $server->generate()->toDomDocument(); - $dom->save(__DIR__.'/TestAsset/setclass.wsdl'); - $this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); - $this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); - $this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); - $this->assertContains('sanitizeWsdlXmlOutputForOsCompability($dom->saveXML())); + $this->assertValidWSDL($this->dom); + } + + /** + * @expectedException \Zend\Soap\Exception\InvalidArgumentException + * @dataProvider dataProviderForAddFunctionException + */ + public function testAddFunctionException($function){ + $this->server->addFunction($function); + } - unlink(__DIR__.'/TestAsset/setclass.wsdl'); + /** + * @return array + */ + public function dataProviderForAddFunctionException(){ + return array( + array('InvalidFunction'), + array(1), + array(array(1,2)), + ); } public function testAddFunctionSimple() { - $scriptUri = 'http://localhost/my_script.php'; + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $this->bindWsdl($this->server->generate()); - $server = $this->createAutodiscoverService(); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); - $dom = $server->generate()->toDomDocument(); - - $name = "TestService"; - - $wsdl = ''. - ''. - ''. - ''. - 'Test Function'. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''; - $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated"); - $this->assertValidWSDL($dom); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:documentation', 'Missing service port definition documentation'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input', 'Missing service port definition input message'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output', 'Missing service port definition input message'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service binding definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', 'Missing service binding transport definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#TestFunc"]', 'Missing service operation action definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input body definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input body definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="who" and @type="xsd:string"]', 'Missing test testFunc input message definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Missing test testFunc input message definition'); + + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } public function testAddFunctionSimpleWithDifferentStyle() { - $scriptUri = 'http://localhost/my_script.php'; + $this->server->setBindingStyle(array('style' => 'document', 'transport' => $this->defaultServiceUri)); + $this->server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => $this->defaultServiceUri)); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $this->bindWsdl($this->server->generate()); - $server = $this->createAutodiscoverService(); - $server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com')); - $server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com')); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); - $dom = $server->generate()->toDomDocument(); - - $name = "TestService"; - $wsdl = ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - 'Test Function'. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''; - $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated"); - $this->assertValidWSDL($dom); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]/xsd:element[@name="TestFunc"]/xsd:complexType/xsd:sequence/xsd:element[@name="who" and @type="xsd:string"]', 'Missing complex type definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]/xsd:element[@name="TestFuncResponse"]/xsd:complexType/xsd:sequence/xsd:element[@name="TestFuncResult" and @type="xsd:string"]', 'Missing complex type definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:documentation', 'Missing service port definition documentation'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input', 'Missing service port definition input message'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output', 'Missing service port definition input message'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service binding definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/soap:binding[@style="document" and @transport="'.$this->defaultServiceUri.'"]', 'Missing service binding transport definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#TestFunc"]', 'Missing service operation action definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="literal" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input body definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="literal" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input body definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="parameters" and @element="tns:TestFunc"]', 'Missing test testFunc input message definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="parameters" and @element="tns:TestFuncResponse"]', 'Missing test testFunc input message definition'); + + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** @@ -402,184 +538,150 @@ public function testAddFunctionSimpleWithDifferentStyle() */ public function testAddFunctionSimpleInReturnNameCompabilityMode() { - $scriptUri = 'http://localhost/my_script.php'; + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $this->bindWsdl($this->server->generate()); - $server = $this->createAutodiscoverService(); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:documentation', 'Missing service port definition documentation'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input', 'Missing service port definition input message'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output', 'Missing service port definition input message'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service binding definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', 'Missing service binding transport definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#TestFunc"]', 'Missing service operation action definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="http://localhost/MyService.php"]', 'Missing operation input body definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="http://localhost/MyService.php"]', 'Missing operation input body definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); - $dom = $server->generate()->toDomDocument(); - $name = "TestService"; + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="who" and @type="xsd:string"]', 'Missing test testFunc input message definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Missing test testFunc input message definition'); - $wsdl = $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()); - $this->assertContains('', $wsdl); - $this->assertNotContains('assertValidWSDL($dom); + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } public function testAddFunctionMultiple() { - $scriptUri = 'http://localhost/my_script.php'; + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc2'); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc3'); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc4'); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc5'); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc6'); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc7'); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc9'); - $server = $this->createAutodiscoverService(); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc2'); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc3'); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc4'); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc5'); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc6'); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc7'); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc9'); - - $dom = $server->generate()->toDomDocument(); - - $name = "TestService"; - - $wsdl = ''. - ''. - ''. - ''. - 'Test Function'. - 'Test Function 2'. - 'Return false'. - 'Return true'. - 'Return integer'. - 'Return string'. - 'Return array'. - 'Multiple Args'. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''; - $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Generated WSDL did not match expected XML"); - $this->assertValidWSDL($dom); - } + $this->bindWsdl($this->server->generate()); - /** - * @group ZF-4117 - */ - public function testChangeWsdlUriInConstructor() - { - $scriptUri = 'http://localhost/my_script.php'; - $server = new AutoDiscover(null, "http://example.com/service.php"); - $server->setServiceName("TestService"); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); - $wsdlOutput = $server->toXml(); - $this->assertNotContains($scriptUri, $wsdlOutput); - $this->assertContains("http://example.com/service.php", $wsdlOutput); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', 'Missing service port definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + + foreach(array('', 2,3, 4, 5, 6, 7, 9) as $i) { + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]', 'Missing service port definition for TestFunc'.$i.''); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:documentation', 'Missing service port definition documentation for TestFunc'.$i.''); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:input[@message="tns:TestFunc'.$i.'In"]', 'Missing service port definition input message for TestFunc'.$i.''); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#TestFunc'.$i.'"]', 'Missing service operation action definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:input/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input for TestFunc'.$i.' body definition'); + + + if ($i != 2) { + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:output[@message="tns:TestFunc'.$i.'Out"]', 'Missing service port definition input message for TestFunc'.$i.''); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:output/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input for TestFunc'.$i.' body definition'); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFunc'.$i.'In"]', 'Missing test testFunc'.$i.' input message definition'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFunc'.$i.'Out"]', 'Missing test testFunc'.$i.' input message definition'); + } + } + + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** * @group ZF-4117 + * + * @dataProvider dataProviderValidUris */ - public function testChangeWsdlUriViaSetUri() + public function testChangeWsdlUriInConstructor($uri) { - $scriptUri = 'http://localhost/my_script.php'; + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $this->server->setUri($uri); + $this->bindWsdl($this->server->generate()); - $server = $this->createAutodiscoverService(); - $server->setUri("http://example.com/service.php"); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); - $wsdlOutput = $server->toXml(); + $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); + $this->assertEquals($uri, $this->dom->documentElement->getAttribute('targetNamespace')); + $this->assertNotContains($this->defaultServiceUri, $this->dom->saveXML()); - $this->assertNotContains($scriptUri, $wsdlOutput); - $this->assertContains("http://example.com/service.php", $wsdlOutput); + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } public function testSetNonStringNonZendUriUriThrowsException() { - $server = $this->createAutodiscoverService(); - $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'No uri given to'); + $server = new AutoDiscover(); + + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', + 'Argument to \Zend\Soap\AutoDiscover::setUri should be string ' + .'or \Zend\Uri\Uri instance.' + ); $server->setUri(array("bogus")); } /** * @group ZF-4117 + * @dataProvider dataProviderValidUris */ - public function testChangingWsdlUriAfterGenerationIsPossible() + public function testChangingWsdlUriAfterGenerationIsPossible($uri) { - $scriptUri = 'http://localhost/my_script.php'; - - $server = $this->createAutodiscoverService(); - $server->setUri("http://example.com/service.php"); - $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); - - $wsdlOutput = $server->toXml(); - - $this->assertNotContains($scriptUri, $wsdlOutput); - $this->assertContains("http://example.com/service.php", $wsdlOutput); - - $server->setUri("http://example2.com/service2.php"); - - $wsdlOutput = $server->toXml(); + $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); + $wsdl = $this->server->generate(); + $wsdl->setUri($uri); + + //@todo string retrieved this way contains decoded entities +// $this->assertEquals($uri, $wsdl->toDomDocument()->documentElement->getAttribute('targetNamespace')); + $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); + $this->assertContains($uri, $wsdl->toXML()); + $this->assertNotContains($this->defaultServiceUri, $wsdl->toXML()); + + $this->assertValidWSDL($wsdl->toDomDocument()); + $this->testDocumentNodes(); + } - $this->assertNotContains($scriptUri, $wsdlOutput); - $this->assertNotContains("http://example.com/service.php", $wsdlOutput); - $this->assertContains("http://example2.com/service2.php", $wsdlOutput); + /** + * @return array + */ + public function dataProviderValidUris() { + return array( + array('http://example.com/service.php'), + array('http://example.com/?a=b&b=c'), + array('http://example.com/?a=b&b=c'), + array('urn:uuid:550e8400-e29b-41d4-a716-446655440000'), + array('urn:acme:servicenamespace'), + array(new Uri('http://example.com/service.php')) + ); } /** @@ -587,17 +689,18 @@ public function testChangingWsdlUriAfterGenerationIsPossible() * @group ZF-4125 * */ - public function testUsingClassWithMultipleMethodPrototypesProducesValidWsdl() + public function testUsingClassWithMethodsWithMultipleDefaultParameterValues() { - $scriptUri = 'http://localhost/my_script.php'; + $this->server->setClass('\ZendTest\Soap\TestAsset\TestFixingMultiplePrototypes'); + $this->bindWsdl($this->server->generate()); - $server = $this->createAutodiscoverService(); - $server->setClass('\ZendTest\Soap\TestAsset\TestFixingMultiplePrototypes'); - $wsdlOutput = $server->toXml(); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFuncIn"]'); + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFuncOut"]'); - $this->assertEquals(1, substr_count($wsdlOutput, '')); - $this->assertEquals(1, substr_count($wsdlOutput, '')); + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** @@ -605,28 +708,20 @@ public function testUsingClassWithMultipleMethodPrototypesProducesValidWsdl() */ public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce() { - $server = $this->createAutodiscoverService(); - $server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); - $server->setClass('\ZendTest\Soap\TestAsset\AutoDiscoverTestClass2'); + $this->server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + $this->server->setClass('\ZendTest\Soap\TestAsset\AutoDiscoverTestClass2'); + $this->bindWsdl($this->server->generate()); - $wsdlOutput = $server->toXml(); - $this->assertEquals(1, - substr_count($wsdlOutput, 'wsdl:arrayType="tns:AutoDiscoverTestClass1[]"'), - 'wsdl:arrayType definition of TestClass1 has to occour once.' - ); - $this->assertEquals(1, - substr_count($wsdlOutput, ''), - '\ZendTest\Soap\TestAsset\AutoDiscoverTestClass1 has to be defined once.' - ); - $this->assertEquals(1, - substr_count($wsdlOutput, ''), - '\ZendTest\Soap\TestAsset\AutoDiscoverTestClass1 should be defined once.' - ); - $this->assertTrue( - substr_count($wsdlOutput, '') >= 1, - '\ZendTest\Soap\TestAsset\AutoDiscoverTestClass1 appears once or more than once in the message parts section.' - ); + $this->assertSpecificNodeNumberInXPath(1, '//xsd:attribute[@wsdl:arrayType="tns:AutoDiscoverTestClass1[]"]', 'Definition of TestClass1 has to occour once.'); + $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="AutoDiscoverTestClass1"]', 'AutoDiscoverTestClass1 has to be defined once.'); + $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfAutoDiscoverTestClass1"]', 'AutoDiscoverTestClass1 should be defined once.'); + $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:part[@name="test" and @type="tns:AutoDiscoverTestClass1"]', 'AutoDiscoverTestClass1 appears once or more than once in the message parts section.'); + $this->assertTrue($nodes->length >= 1, 'AutoDiscoverTestClass1 appears once or more than once in the message parts section.'); + + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** @@ -634,14 +729,17 @@ public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce() */ public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayComplex() { - $autodiscover = $this->createAutodiscoverService(); - $autodiscover->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); - $autodiscover->setClass('\ZendTest\Soap\TestAsset\MyService'); - $wsdl = $autodiscover->toXml(); + $this->server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + $this->server->setClass('\ZendTest\Soap\TestAsset\MyService'); + $this->bindWsdl($this->server->generate()); + - $this->assertEquals(1, substr_count($wsdl, '')); + $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfMyResponse"]'); + $this->assertSpecificNodeNumberInXPath(0, '//wsdl:part[@type="tns:My_Response[]"]'); - $this->assertEquals(0, substr_count($wsdl, 'tns:My_Response[]')); + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** @@ -649,30 +747,21 @@ public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayC */ public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArraySequence() { - $autodiscover = $this->createAutodiscoverService(); - $autodiscover->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); - $autodiscover->setClass('\ZendTest\Soap\TestAsset\MyServiceSequence'); - $wsdl = $autodiscover->toXml(); + $this->server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); + $this->server->setClass('\ZendTest\Soap\TestAsset\MyServiceSequence'); + $this->bindWsdl($this->server->generate()); - $this->assertEquals(1, substr_count($wsdl, '')); - $this->assertEquals(1, substr_count($wsdl, '')); - $this->assertEquals(1, substr_count($wsdl, '')); - $this->assertEquals(0, substr_count($wsdl, 'tns:string[]')); - } + $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfString"]'); + $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfArrayOfString"]'); + $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfArrayOfArrayOfString"]'); - /** - * @group ZF-5736 - */ - public function testAmpersandInUrlIsCorrectlyEncoded() - { - $autodiscover = new AutoDiscover(); - $autodiscover->setUri("http://example.com/?a=b&b=c"); - $autodiscover->setClass('\ZendTest\Soap\TestAsset\Test'); - $wsdl = $autodiscover->toXml(); + $this->assertNotContains('tns:string[]', $this->dom->saveXML()); + - $this->assertContains("http://example.com/?a=b&b=c", $wsdl); + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** @@ -680,14 +769,16 @@ public function testAmpersandInUrlIsCorrectlyEncoded() */ public function testNoReturnIsOneWayCallInSetClass() { - $autodiscover = $this->createAutodiscoverService(); - $autodiscover->setClass('\ZendTest\Soap\TestAsset\NoReturnType'); - $wsdl = $autodiscover->toXml(); + $this->server->setClass('\ZendTest\Soap\TestAsset\NoReturnType'); + $this->bindWsdl($this->server->generate()); - $this->assertContains( - '@param string $message', - $wsdl - ); + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType/wsdl:operation[@name="pushOneWay"]/wsdl:input'); + $this->assertSpecificNodeNumberInXPath(0, '//wsdl:portType/wsdl:operation[@name="pushOneWay"]/wsdl:output'); + + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** @@ -695,15 +786,16 @@ public function testNoReturnIsOneWayCallInSetClass() */ public function testNoReturnIsOneWayCallInAddFunction() { - $autodiscover = $this->createAutodiscoverService(); - $autodiscover->setServiceName('TestService'); - $autodiscover->addFunction('\ZendTest\Soap\TestAsset\OneWay'); - $wsdl = $autodiscover->toXml(); - - $this->assertContains( - '@param string $message', - $wsdl - ); + $this->server->addFunction('\ZendTest\Soap\TestAsset\OneWay'); + $this->bindWsdl($this->server->generate()); + + + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType/wsdl:operation[@name="OneWay"]/wsdl:input'); + $this->assertSpecificNodeNumberInXPath(0, '//wsdl:portType/wsdl:operation[@name="OneWay"]/wsdl:output'); + + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); } /** @@ -712,32 +804,53 @@ public function testNoReturnIsOneWayCallInAddFunction() */ public function testRecursiveWsdlDependencies() { - $autodiscover = $this->createAutodiscoverService(); - $autodiscover->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); - $autodiscover->setClass('\ZendTest\Soap\TestAsset\Recursion'); - $wsdl = $autodiscover->toXml(); + $this->server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); + $this->server->setClass('\ZendTest\Soap\TestAsset\Recursion'); + + $this->bindWsdl($this->server->generate()); + // // // // // + $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:complexType[@name="Recursion"]/xsd:all/xsd:element[@name="recursion" and @type="tns:Recursion"]'); + + $this->assertValidWSDL($this->dom); + $this->testDocumentNodes(); + } + + /** + * @param int $n + * @param string $xpath + * @param string $msg + * @return \DOMNodeList + */ + public function assertSpecificNodeNumberInXPath($n, $xpath, $msg = null) + { + + $nodes = $this->xpath->query($xpath); + if (!($nodes instanceof \DOMNodeList)) { + $this->fail('Nodes not found. Invalid XPath expression ?'); + } + $this->assertEquals($n, $nodes->length, $msg); - $path = '//wsdl:types/xsd:schema/xsd:complexType[@name="Recursion"]/xsd:all/xsd:element[@name="recursion" and @type="tns:Recursion"]'; - $this->assertWsdlPathExists($wsdl, $path); + return $nodes; } - public function assertWsdlPathExists($xml, $path) + public function assertAttributesOfNodes($attributes, $nodeList) { - $doc = new \DOMDocument('UTF-8'); - $doc->loadXML($xml); - $xpath = new \DOMXPath($doc); - $xpath->registerNamespace('wsdl', 'http://schemas.xmlsoap.org/wsdl/'); + $c = count($attributes); - $nodes = $xpath->query($path); + $keys = array_keys($attributes); - $this->assertTrue($nodes->length >= 1, "Could not assert that XML Document contains a node that matches the XPath Expression: " . $path); + foreach($nodeList as $node) { + for($i = 0; $i < $c; $i++) { + $this->assertEquals($attributes[$keys[$i]], $node->getAttribute($keys[$i]), 'Invalid attribute value.'); + } + } } } diff --git a/test/ClientTest.php b/test/ClientTest.php old mode 100644 new mode 100755 index 2c3a7222..f068a69c --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -12,8 +12,10 @@ require_once __DIR__ . '/TestAsset/commontypes.php'; +use Zend\Soap\AutoDiscover; use Zend\Soap\Client; use Zend\Soap\Server; +use Zend\Soap\Wsdl; /** * @category Zend @@ -41,6 +43,21 @@ public function testSetOptions() $ctx = stream_context_create(); + $typeMap = array( + array( + 'type_name' => 'dateTime', + 'type_ns' => 'http://www.w3.org/2001/XMLSchema', + 'from_xml' => 'strtotime', + 'to_xml' => 'strtotime', + ), + array( + 'type_name' => 'date', + 'type_ns' => 'http://www.w3.org/2001/XMLSchema', + 'from_xml' => 'strtotime', + 'to_xml' => 'strtotime', + ) + ); + $nonWSDLOptions = array('soap_version' => SOAP_1_1, 'classmap' => array('TestData1' => '\ZendTest\Soap\TestAsset\TestData1', 'TestData2' => '\ZendTest\Soap\TestAsset\TestData2',), @@ -65,7 +82,9 @@ public function testSetOptions() 'cache_wsdl' => 8, 'features' => 4, - 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5); + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5, + 'typemap' => $typeMap + ); $client->setOptions($nonWSDLOptions); $this->assertTrue($client->getOptions() == $nonWSDLOptions); @@ -96,7 +115,9 @@ public function testSetOptions() 'stream_context' => $ctx, - 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5); + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5, + 'typemap' => $typeMap + ); $client1->setOptions($wsdlOptions); $this->assertTrue($client1->getOptions() == $wsdlOptions); @@ -108,6 +129,21 @@ public function testGetOptions() $this->assertTrue($client->getOptions() == array('encoding' => 'UTF-8', 'soap_version' => SOAP_1_2)); + $typeMap = array( + array( + 'type_name' => 'dateTime', + 'type_ns' => 'http://www.w3.org/2001/XMLSchema', + 'from_xml' => 'strtotime', + 'to_xml' => 'strtotime', + ), + array( + 'type_name' => 'date', + 'type_ns' => 'http://www.w3.org/2001/XMLSchema', + 'from_xml' => 'strtotime', + 'to_xml' => 'strtotime', + ) + ); + $options = array('soap_version' => SOAP_1_1, 'wsdl' => __DIR__.'/TestAsset/wsdl_example.wsdl', @@ -130,7 +166,9 @@ public function testGetOptions() 'local_cert' => __DIR__.'/TestAsset/cert_file', 'passphrase' => 'some pass phrase', - 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5); + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5, + 'typemap' => $typeMap + ); $client->setOptions($options); $this->assertTrue($client->getOptions() == $options); @@ -243,24 +281,50 @@ public function testGetFunctions() } /** - * @todo Implement testGetTypes(). */ public function testGetTypes() { - // Remove the following line when you implement this test. - $this->markTestIncomplete( - "This test has not been implemented yet." - ); + $wsdlFilename = __DIR__ . '/TestAsset/GetTypesWsdlTest.wsdl'; + + $autodiscover = new AutoDiscover(); + $autodiscover->setServiceName('ExampleService'); + $autodiscover->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + $autodiscover->setClass('\ZendTest\Soap\TestAsset\AutoDiscoverTestClass2'); + $autodiscover->setUri('http://example.com'); + $wsdl = $autodiscover->generate(); + $wsdl->dump($wsdlFilename); + + $server = new Server($wsdlFilename); + $server->setClass('\ZendTest\Soap\TestAsset\AutoDiscoverTestClass2'); + + $client = new Client\Local($server, $wsdlFilename); + $soapClient = $client->getSoapClient(); + + $typesArray = $soapClient->__getTypes(); + + $this->assertCount(2, $typesArray); + + $count = 0; + foreach ($typesArray as $element) { + if (strpos($element, 'struct AutoDiscoverTestClass1') === 0 OR strpos($element, 'AutoDiscoverTestClass1 ArrayOfAutoDiscoverTestClass1') === 0) { + $count++; + } + } + $this->assertEquals(2, $count, 'Invalid types'); + + unlink($wsdlFilename); } + /** + * @outputBuffering enabled + */ public function testGetLastRequest() { - if (headers_sent()) { - $this->markTestSkipped('Cannot run testGetLastRequest() when headers have already been sent; enable output buffering to run this test'); + if (headers_sent($file, $line)) { + $this->markTestSkipped('Cannot run testGetLastRequest() when headers have already been sent. Output started in '.$file.'@'.$line.' enable output buffering to run this test'); return; } - $server = new Server(__DIR__ . '/TestAsset/wsdl_example.wsdl'); $server->setClass('\ZendTest\Soap\TestAsset\TestClass'); @@ -520,4 +584,25 @@ public function testSetSoapClient() $this->assertSame($clientMock, $soap->getSoapClient()); } + + /** + * @expectedException \Zend\Soap\Exception\UnexpectedValueException + * @dataProvider dataProviderForInitSoapClientObjectException + */ + public function testInitSoapClientObjectException($wsdl, $options){ + $client = new Client($wsdl, $options); + $client->getSoapClient(); + } + + /** + * @return array + */ + public function dataProviderForInitSoapClientObjectException() { + return array( + array(null, array()), + array(null, array('location'=>'http://example.com')), + array(__DIR__ . './TestAsset/wsdl_example.wsdl', array('use'=>SOAP_ENCODED)), + array(__DIR__ . './TestAsset/wsdl_example.wsdl', array('style'=>SOAP_DOCUMENT)) + ); + } } diff --git a/test/ServerTest.php b/test/ServerTest.php old mode 100644 new mode 100755 index 8183b4ae..5f0231a2 --- a/test/ServerTest.php +++ b/test/ServerTest.php @@ -12,6 +12,7 @@ require_once __DIR__ . '/TestAsset/commontypes.php'; +use Zend\Soap\AutoDiscover; use Zend\Soap\Server; /** @@ -649,89 +650,115 @@ public function testHandle() } /** - * @todo Implement testRegisterFaultException(). + * @dataProvider dataProviderForRegisterFaultException + * + * @param string|array $exception */ - public function testRegisterFaultException() + public function testRegisterFaultException($exception) { $server = new Server(); - $server->registerFaultException("Zend_Soap_Server_Exception"); - $server->registerFaultException(array("OutOfBoundsException", "BogusException")); + $server->registerFaultException($exception); - $this->assertEquals(array( - 'Zend_Soap_Server_Exception', - 'OutOfBoundsException', - 'BogusException', - ), $server->getFaultExceptions()); + if (!is_array($exception)) { + $this->assertContains($exception, $server->getFaultExceptions()); + } else { + foreach($exception as $row) { + $this->assertContains($row, $server->getFaultExceptions()); + } + } } /** - * @todo Implement testDeregisterFaultException(). + * @dataProvider dataProviderForRegisterFaultException + * + * @param string|array $exception */ - public function testDeregisterFaultException() + public function testDeregisterFaultException($exception) { $server = new Server(); - $server->registerFaultException(array("OutOfBoundsException", "BogusException")); - $ret = $server->deregisterFaultException("BogusException"); - $this->assertTrue($ret); + $server->registerFaultException($exception); + if (is_array($exception)) { + $exception = array_shift($exception); + } - $this->assertEquals(array( - 'OutOfBoundsException', - ), $server->getFaultExceptions()); + $this->assertTrue($server->deregisterFaultException($exception)); - $ret = $server->deregisterFaultException("NonRegisteredException"); - $this->assertFalse($ret); + $this->assertNotContains($exception, $server->getFaultExceptions()); } /** - * @todo Implement testGetFaultExceptions(). + * @dataProvider dataProviderForRegisterFaultException + * + * @param string|array $exception */ - public function testGetFaultExceptions() - { + public function testIsRegisteredAsFaultException($exception) { + $server = new Server(); + $server->registerFaultException($exception); + + + if (!is_array($exception)) { + $this->assertTrue($server->isRegisteredAsFaultException($exception)); + } else { + foreach($exception as $row) { + $this->assertTrue($server->isRegisteredAsFaultException($row)); + } + } + } - $this->assertEquals(array(), $server->getFaultExceptions()); - $server->registerFaultException("Exception"); - $this->assertEquals(array("Exception"), $server->getFaultExceptions()); + /** + * @return array + */ + public function dataProviderForRegisterFaultException() + { + return array( + array('Zend\Soap\Exception\InvalidArgumentException'), + array('InvalidArgumentException'), + array('Zend\Server\Exception\RuntimeException'), + array(array('Zend\Server\Exception\RuntimeException')), + array(array('Zend\Server\Exception\RuntimeException', 'InvalidArgumentException')), + ); } public function testFaultWithTextMessage() { $server = new Server(); - $fault = $server->fault("Faultmessage!"); + $fault = $server->fault('FaultMessage!'); - $this->assertTrue($fault instanceof \SOAPFault); - $this->assertContains("Faultmessage!", $fault->getMessage()); + $this->assertTrue($fault instanceof \SoapFault); + $this->assertContains('FaultMessage!', $fault->getMessage()); } public function testFaultWithUnregisteredException() { $server = new Server(); - $fault = $server->fault(new \Exception("MyException")); + $fault = $server->fault(new \Exception('MyException')); - $this->assertTrue($fault instanceof \SOAPFault); - $this->assertContains("Unknown error", $fault->getMessage()); - $this->assertNotContains("MyException", $fault->getMessage()); + $this->assertTrue($fault instanceof \SoapFault); + $this->assertContains('Unknown error', $fault->getMessage()); + $this->assertNotContains('MyException', $fault->getMessage()); } public function testFaultWithRegisteredException() { $server = new Server(); - $server->registerFaultException("Exception"); - $fault = $server->fault(new \Exception("MyException")); + $server->registerFaultException('\Zend\Soap\Exception\RuntimeException'); + $server->registerFaultException('\Zend\Soap\Exception\InvalidArgumentException'); + $fault = $server->fault(new \Zend\Soap\Exception\RuntimeException('MyException')); - $this->assertTrue($fault instanceof \SOAPFault); - $this->assertNotContains("Unknown error", $fault->getMessage()); - $this->assertContains("MyException", $fault->getMessage()); + $this->assertTrue($fault instanceof \SoapFault); + $this->assertNotContains('Unknown error', $fault->getMessage()); + $this->assertContains('MyException', $fault->getMessage()); } - public function testFautlWithBogusInput() + public function testFaultWithBogusInput() { $server = new Server(); - $fault = $server->fault(array("Here", "There", "Bogus")); + $fault = $server->fault(array('Here', 'There', 'Bogus')); - $this->assertContains("Unknown error", $fault->getMessage()); + $this->assertContains('Unknown error', $fault->getMessage()); } /** @@ -740,22 +767,48 @@ public function testFautlWithBogusInput() public function testFaultWithIntegerFailureCodeDoesNotBreakClassSoapFault() { $server = new Server(); - $fault = $server->fault("Faultmessage!", 5000); + $fault = $server->fault("FaultMessage!", 5000); - $this->assertTrue($fault instanceof \SOAPFault); + $this->assertTrue($fault instanceof \SoapFault); } /** - * @todo Implement testHandlePhpErrors(). + * @expectedExcepti on \SoapFault */ public function testHandlePhpErrors() { - $server = new Server(); + if (headers_sent()) { + $this->markTestSkipped('Cannot run ' . __METHOD__ . '() when headers have already been sent; enable output buffering to run this test'); + return; + } - // Remove the following line when you implement this test. - $this->markTestIncomplete( - "This test has not been implemented yet." - ); + $wsdlFilename = __DIR__ . '/TestAsset/testHandlePhpErrors.wsdl'; + $autodiscover = new AutoDiscover(); + $autodiscover->setOperationBodyStyle(array( + 'use' => 'literal', + )); + + $autodiscover->setBindingStyle(array( + 'style' => 'document', + 'transport' => 'http://schemas.xmlsoap.org/soap/http' + )); + + + $autodiscover->setServiceName('ExampleService'); + $autodiscover->setUri('http://example.com'); + + + $autodiscover->setClass('\ZendTest\Soap\TestAsset\errorClass'); + + $wsdl = $autodiscover->generate(); + $wsdl->dump($wsdlFilename); + + $server = new Server($wsdlFilename); + + $server->setClass('\ZendTest\Soap\TestAsset\errorClass'); + + $client = new \Zend\Soap\Client\Local($server, $wsdlFilename); + $client->triggerError(); } public function testLoadFunctionsIsNotImplemented() diff --git a/test/TestAsset/commontypes.php b/test/TestAsset/commontypes.php old mode 100644 new mode 100755 index 0317eb33..23237ec6 --- a/test/TestAsset/commontypes.php +++ b/test/TestAsset/commontypes.php @@ -634,3 +634,61 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0 } } + +class SequenceTest +{ + /** + * @var int + */ + public $var = 5; +} + + + +class Book +{ + /** + * @var int + */ + public $somevar; +} +class Cookie +{ + /** + * @var int + */ + public $othervar; +} +class Anything +{ +} + + + +class PublicPrivateProtected +{ + const PROTECTED_VAR_NAME = 'bar'; + const PRIVATE_VAR_NAME = 'baz'; + + /** + * @var string + */ + public $foo; + + /** + * @var string + */ + protected $bar; + + /** + * @var string + */ + private $baz; +} + +class errorClass { + + public function triggerError() { + trigger_error('TestError', E_USER_ERROR); + } +} diff --git a/test/TestAsset/wsdl_example.wsdl b/test/TestAsset/wsdl_example.wsdl old mode 100644 new mode 100755 index 129f28de..41412402 --- a/test/TestAsset/wsdl_example.wsdl +++ b/test/TestAsset/wsdl_example.wsdl @@ -1,2 +1,89 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Wsdl/ArrayOfTypeComplexStrategyTest.php b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php old mode 100644 new mode 100755 index 72405fb1..793b20e5 --- a/test/Wsdl/ArrayOfTypeComplexStrategyTest.php +++ b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php @@ -10,10 +10,11 @@ namespace ZendTest\Soap\Wsdl; -require_once __DIR__."/../TestAsset/commontypes.php"; +require_once __DIR__ . "/../TestAsset/commontypes.php"; use Zend\Soap\Wsdl; use Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex; +use ZendTest\Soap\WsdlTestHelper; /** * @category Zend @@ -22,18 +23,14 @@ * @group Zend_Soap * @group Zend_Soap_Wsdl */ -class ArrayOfTypeComplexStrategyTest extends \PHPUnit_Framework_TestCase +class ArrayOfTypeComplexStrategyTest extends WsdlTestHelper { - /** @var \Zend\Soap\Wsdl */ - private $wsdl; - - /** @var \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex */ - private $strategy; public function setUp() { $this->strategy = new ArrayOfTypeComplex(); - $this->wsdl = new Wsdl('MyService', 'http://localhost/MyService.php', $this->strategy); + + parent::setUp(); } public function testNestingObjectsDeepMakesNoSenseThrowingException() @@ -53,30 +50,34 @@ public function testAddComplexTypeOfNonExistingClassThrowsException() */ public function testArrayOfSimpleObject() { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTest[]'); $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTest[]'); $this->assertEquals("tns:ArrayOfComplexTest", $return); - $wsdl = $this->wsdl->toXML(); + // single element + $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ComplexTest"]/xsd:all/xsd:element'); + $this->assertEquals(1, $nodes->length, 'Unable to find complex type in wsdl.'); + + $this->assertEquals('var', $nodes->item(0)->getAttribute('name'), 'Invalid attribute name'); + $this->assertEquals('xsd:int', $nodes->item(0)->getAttribute('type'), 'Invalid type name'); + + // array of elements + $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexTest"]/xsd:complexContent/xsd:restriction'); + $this->assertEquals(1, $nodes->length, 'Unable to find complex type array definition in wsdl.'); + $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), 'Invalid base encoding in complex type.'); - $this->assertContains( - '', - $wsdl, - $wsdl - ); + $nodes = $this->xpath->query('xsd:attribute', $nodes->item(0)); - $this->assertContains( - '', - $wsdl - ); + $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.'); + $this->assertEquals('tns:ComplexTest[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), 'Invalid array type reference.'); + + $this->testDocumentNodes(); } public function testThatOverridingStrategyIsReset() { $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTest[]'); $this->assertEquals("tns:ArrayOfComplexTest", $return); - // $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplexStrategy); - - $wsdl = $this->wsdl->toXML(); } /** @@ -87,18 +88,32 @@ public function testArrayOfComplexObjects() $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectStructure[]'); $this->assertEquals("tns:ArrayOfComplexObjectStructure", $return); - $wsdl = $this->wsdl->toXML(); + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="ComplexObjectStructure"]/xsd:all'); + $this->assertEquals(4, $nodes->item(0)->childNodes->length, 'Invalid complex object definition.'); + + foreach (array( + 'boolean' => 'xsd:boolean', + 'string' => 'xsd:string', + 'int' => 'xsd:int', + 'array' => 'soap-enc:Array' + ) as $name => $type) { + $node = $this->xpath->query('xsd:element[@name="'.$name.'"]', $nodes->item(0)); + $this->assertEquals($name, $node->item(0)->getAttribute('name'), 'Invalid name attribute value in complex object definition'); + $this->assertEquals($type, $node->item(0)->getAttribute('type'), 'Invalid type name in complex object definition'); + } + + // array of elements + $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexObjectStructure"]/xsd:complexContent/xsd:restriction'); + $this->assertEquals(1, $nodes->length, 'Unable to find complex type array definition in wsdl.'); + $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), 'Invalid base encoding in complex type.'); - $this->assertContains( - '', - $wsdl, - $wsdl - ); + $nodes = $this->xpath->query('xsd:attribute', $nodes->item(0)); - $this->assertContains( - '', - $wsdl - ); + $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.'); + $this->assertEquals('tns:ComplexObjectStructure[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), 'Invalid array type reference.'); + + + $this->testDocumentNodes(); } public function testArrayOfObjectWithObject() @@ -106,23 +121,32 @@ public function testArrayOfObjectWithObject() $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); $this->assertEquals("tns:ArrayOfComplexObjectWithObjectStructure", $return); - $wsdl = $this->wsdl->toXML(); + // single element + $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ComplexTest"]/xsd:all/xsd:element'); + $this->assertEquals(1, $nodes->length, 'Unable to find complex type in wsdl.'); + + $this->assertEquals('var', $nodes->item(0)->getAttribute('name'), 'Invalid attribute name'); + $this->assertEquals('xsd:int', $nodes->item(0)->getAttribute('type'), 'Invalid type name'); + + // single object element + $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ComplexObjectWithObjectStructure"]/xsd:all/xsd:element'); + $this->assertEquals(1, $nodes->length, 'Unable to find complex object in wsdl.'); + + $this->assertEquals('object', $nodes->item(0)->getAttribute('name'), 'Invalid attribute name'); + $this->assertEquals('tns:ComplexTest', $nodes->item(0)->getAttribute('type'), 'Invalid type name'); + $this->assertEquals('true', $nodes->item(0)->getAttribute('nillable'), 'Invalid nillable attribute value'); - $this->assertContains( - '', - $wsdl - ); + // array of elements + $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]/xsd:complexContent/xsd:restriction'); + $this->assertEquals(1, $nodes->length, 'Unable to find complex type array definition in wsdl.'); + $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), 'Invalid base encoding in complex type.'); - $this->assertContains( - '', - $wsdl, - $wsdl - ); + $nodes = $this->xpath->query('xsd:attribute', $nodes->item(0)); - $this->assertContains( - '', - $wsdl - ); + $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.'); + $this->assertEquals('tns:ComplexObjectWithObjectStructure[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), 'Invalid array type reference.'); + + $this->testDocumentNodes(); } /** @@ -133,17 +157,17 @@ public function testAddingTypesMultipleTimesIsSavedOnlyOnce() $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); - $wsdl = $this->wsdl->toXML(); - - $this->assertEquals(1, - substr_count($wsdl, 'wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"') - ); - $this->assertEquals(1, - substr_count($wsdl, '') - ); - $this->assertEquals(1, - substr_count($wsdl, '') - ); + // this xpath is proper version of simpler: //*[wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"] - namespaces in attributes and xpath + $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::NS_WSDL.'" and local-name()="arrayType"]="tns:ComplexObjectWithObjectStructure[]"]'); + $this->assertEquals(1, $nodes->length, 'Invalid array of complex type array type reference detected'); + + $nodes = $this->xpath->query('//xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]'); + $this->assertEquals(1, $nodes->length, 'Invalid array complex type detected'); + + $nodes = $this->xpath->query('//xsd:complexType[@name="ComplexTest"]'); + $this->assertEquals(1, $nodes->length, 'Invalid complex type detected'); + + $this->testDocumentNodes(); } /** @@ -154,27 +178,17 @@ public function testAddingSingularThenArrayTypeIsRecognizedCorretly() $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure'); $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); - $wsdl = $this->wsdl->toXML(); - - $this->assertEquals(1, - substr_count($wsdl, 'wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"') - ); - $this->assertEquals(1, - substr_count($wsdl, '') - ); - $this->assertEquals(1, - substr_count($wsdl, '') - ); - } + // this xpath is proper version of simpler: //*[wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"] - namespaces in attributes and xpath + $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::NS_WSDL.'" and local-name()="arrayType"]="tns:ComplexObjectWithObjectStructure[]"]'); + $this->assertEquals(1, $nodes->length, 'Invalid array of complex type array type reference detected'); - /** - * @group ZF-5149 - */ - public function testArrayOfComplexNestedObjectsIsCoveredByStrategy() - { - $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTypeA'); - $wsdl = $this->wsdl->toXml(); - $this->assertTrue(is_string($wsdl)); // no exception was thrown + $nodes = $this->xpath->query('//xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]'); + $this->assertEquals(1, $nodes->length, 'Invalid array complex type detected'); + + $nodes = $this->xpath->query('//xsd:complexType[@name="ComplexTest"]'); + $this->assertEquals(1, $nodes->length, 'Invalid complex type detected'); + + $this->testDocumentNodes(); } /** @@ -183,19 +197,39 @@ public function testArrayOfComplexNestedObjectsIsCoveredByStrategy() public function testArrayOfComplexNestedObjectsIsCoveredByStrategyAndAddsAllTypesRecursivly() { $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTypeA'); - $wsdl = $this->wsdl->toXml(); - - $this->assertEquals(1, - substr_count($wsdl, ''), - 'No definition of complex type A found.' - ); - $this->assertEquals(1, - substr_count($wsdl, ''), - 'No definition of complex type B array found.' - ); - $this->assertEquals(1, - substr_count($wsdl, 'wsdl:arrayType="tns:ComplexTypeB[]"'), - 'No usage of Complex Type B array found.' - ); + $this->assertEquals("tns:ComplexTypeA", $return); + + + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="ComplexTypeB"]/xsd:all'); + $this->assertEquals(2, $nodes->item(0)->childNodes->length, 'Invalid complex object definition.'); + + foreach (array( + 'bar' => 'xsd:string', + 'foo' => 'xsd:string', + ) as $name => $type) { + $node = $this->xpath->query('xsd:element[@name="'.$name.'"]', $nodes->item(0)); + $this->assertEquals($name, $node->item(0)->getAttribute('name'), 'Invalid name attribute value in complex object definition'); + $this->assertEquals($type, $node->item(0)->getAttribute('type'), 'Invalid type name in complex object definition'); + $this->assertEquals('true', $node->item(0)->getAttribute('nillable'), 'Invalid nillable attribute value'); + } + + // single object element + $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ComplexTypeA"]/xsd:all/xsd:element'); + $this->assertEquals(1, $nodes->length, 'Unable to find complex object in wsdl.'); + + $this->assertEquals('baz', $nodes->item(0)->getAttribute('name'), 'Invalid attribute name'); + $this->assertEquals('tns:ArrayOfComplexTypeB', $nodes->item(0)->getAttribute('type'), 'Invalid type name'); + + // array of elements + $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexTypeB"]/xsd:complexContent/xsd:restriction'); + $this->assertEquals(1, $nodes->length, 'Unable to find complex type array definition in wsdl.'); + $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), 'Invalid base encoding in complex type.'); + + $nodes = $this->xpath->query('xsd:attribute', $nodes->item(0)); + + $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.'); + $this->assertEquals('tns:ComplexTypeB[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), 'Invalid array type reference.'); + + $this->testDocumentNodes(); } } diff --git a/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php old mode 100644 new mode 100755 index 69898f91..8079691b --- a/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php +++ b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php @@ -10,6 +10,8 @@ namespace ZendTest\Soap\Wsdl; +use ZendTest\Soap\WsdlTestHelper; + require_once __DIR__ . '/../TestAsset/commontypes.php'; /** @@ -19,118 +21,196 @@ * @group Zend_Soap * @group Zend_Soap_Wsdl */ -class ArrayOfTypeSequenceStrategyTest extends \PHPUnit_Framework_TestCase +class ArrayOfTypeSequenceStrategyTest extends WsdlTestHelper { - private $wsdl; - private $strategy; - public function setUp() { $this->strategy = new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence(); - $this->wsdl = new \Zend\Soap\Wsdl('MyService', 'http://localhost/MyService.php', $this->strategy); + + parent::setUp(); } - public function testFunctionReturningSimpleArrayOfInts() + /** + * @dataProvider dataProviderForFunctionReturningSimpleArrayOfBasicTypes + * + * @param $type + * @param $arrayTypeName + */ + public function testFunctionReturningSimpleArrayOfBasicTypes($type, $arrayTypeName) { - $this->wsdl->addComplexType('int[]'); + $this->wsdl->addComplexType($type.'[]'); + // test duplicates also + $this->wsdl->addComplexType($type.'[]'); - $this->assertContains( - ''. - ''. - '', - $this->wsdl->toXML() - ); - } + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="'.$arrayTypeName.'"]'); + $this->assertEquals(1, $nodes->length, 'Missing complex type declaration'); - public function testFunctionReturningSimpleArrayOfString() - { - $this->wsdl->addComplexType('string[]'); + $nodes = $this->xpath->query('xsd:sequence/xsd:element', $nodes->item(0)); + $this->assertEquals(1, $nodes->length, 'Missing complex type element declaration'); + + $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), 'Wrong complex type element name attribute'); + $this->assertEquals('xsd:'.$type, $nodes->item(0)->getAttribute('type'), 'Wrong complex type type attribute value'); + $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), 'Wrong complex type minOccurs attribute value'); + $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), 'Wrong complex type maxOccurs attribute value'); + + $this->testDocumentNodes(); + } - $this->assertContains( - ''. - ''. - '', - $this->wsdl->toXML() + public function dataProviderForFunctionReturningSimpleArrayOfBasicTypes(){ + return array( + array('int', 'ArrayOfInt'), + array('string', 'ArrayOfString'), + array('boolean', 'ArrayOfBoolean'), + array('float', 'ArrayOfFloat'), + array('double', 'ArrayOfDouble'), ); } - public function testFunctionReturningNestedArrayOfString() + /** + * @dataProvider dataProviderForNestedTypesDefinitions + * + * @param $stringDefinition + * @param $nestedTypeNames + */ + public function testNestedTypesDefinitions($stringDefinition, $definedTypeName, $nestedTypeNames) { - $return = $this->wsdl->addComplexType('string[][]'); - $this->assertEquals('tns:ArrayOfArrayOfString', $return); + $return = $this->wsdl->addComplexType($stringDefinition); + $this->assertEquals('tns:'.$definedTypeName, $return); - $wsdl = $this->wsdl->toXML(); + foreach ($nestedTypeNames as $nestedTypeName => $typeName) { - // Check for ArrayOfArrayOfString - $this->assertContains( - '', - $wsdl - ); - // Check for ArrayOfString - $this->assertContains( - '', - $wsdl - ); - } + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="'.$nestedTypeName.'"]'); + $this->assertEquals(1, $nodes->length, 'Invalid first level of nested element definition'); - public function testFunctionReturningMultipleNestedArrayOfType() - { - $return = $this->wsdl->addComplexType('string[][][]'); - $this->assertEquals('tns:ArrayOfArrayOfArrayOfString', $return); + $nodes = $this->xpath->query('xsd:sequence/xsd:element', $nodes->item(0)); + $this->assertEquals(1, $nodes->length, 'Invalid element in first level of nested element definition'); - $wsdl = $this->wsdl->toXML(); + $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), 'Wrong complex type element name attribute'); + $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), 'Wrong complex type minOccurs attribute value'); + $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), 'Wrong complex type maxOccurs attribute value'); + $this->assertEquals($typeName, $nodes->item(0)->getAttribute('type'), 'Wrong complex type type attribute value'); + } - // Check for ArrayOfArrayOfArrayOfString - $this->assertContains( - '', - $wsdl - ); - // Check for ArrayOfArrayOfString - $this->assertContains( - '', - $wsdl - ); - // Check for ArrayOfString - $this->assertContains( - '', - $wsdl - ); + $this->testDocumentNodes(); } + /** + * @return array + */ + public function dataProviderForNestedTypesDefinitions() { + return array( + array( + 'string[][]', + 'ArrayOfArrayOfString', + array( + 'ArrayOfString' =>'xsd:string', + 'ArrayOfArrayOfString' =>'tns:ArrayOfString' + ) + ), + + array( + 'string[][][]', + 'ArrayOfArrayOfArrayOfString', + array( + 'ArrayOfString' =>'xsd:string', + 'ArrayOfArrayOfString' =>'tns:ArrayOfString', + 'ArrayOfArrayOfArrayOfString' =>'tns:ArrayOfArrayOfString' + ) + ), + + array( + 'string[][][][]', + 'ArrayOfArrayOfArrayOfArrayOfString', + array( + 'ArrayOfString' =>'xsd:string', + 'ArrayOfArrayOfString' =>'tns:ArrayOfString', + 'ArrayOfArrayOfArrayOfString' =>'tns:ArrayOfArrayOfString', + 'ArrayOfArrayOfArrayOfArrayOfString' =>'tns:ArrayOfArrayOfArrayOfString' + ) + ), + + array( + 'int[][]', + 'ArrayOfArrayOfInt', + array( + 'ArrayOfInt' =>'xsd:int', + 'ArrayOfArrayOfInt' =>'tns:ArrayOfInt' + ) + ), + ); + } public function testAddComplexTypeObject() { - $return = $this->wsdl->addComplexType('\ZendTest\Soap\Wsdl\SequenceTest'); + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\SequenceTest'); $this->assertEquals('tns:SequenceTest', $return); - $wsdl = $this->wsdl->toXML(); + $nodes = $this->xpath->query('//xsd:complexType[@name="SequenceTest"]'); + $this->assertEquals(1, $nodes->length, 'Missing complex type: SequenceTest'); - $this->assertContains( - '', - $wsdl - ); + $nodes = $this->xpath->query('xsd:all/xsd:element', $nodes->item(0)); + $this->assertEquals(1, $nodes->length, 'Missing element definition in complex type: SequenceTest'); + + $this->assertEquals('var', $nodes->item(0)->getAttribute('name'), 'Invalid name attribute value'); + $this->assertEquals('xsd:int', $nodes->item(0)->getAttribute('type'), 'Invalid type attribute value'); + + $this->testDocumentNodes(); } public function testAddComplexTypeArrayOfObject() { + $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTypeA[]'); + $this->assertEquals('tns:ArrayOfComplexTypeA', $return); + + + // class a + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="ComplexTypeA"]'); + $this->assertEquals(1, $nodes->length, 'Missing complex type definition.'); + + $nodes = $this->xpath->query('xsd:all/xsd:element', $nodes->item(0)); + + $this->assertEquals(1, $nodes->length, 'Missing complex type element declaration'); + + $this->assertEquals('baz', $nodes->item(0)->getAttribute('name'), 'Wrong complex type element name attribute'); + $this->assertEquals('tns:ArrayOfComplexTypeB', $nodes->item(0)->getAttribute('type'), 'Wrong complex type type attribute value'); - $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTypeA[]'); - $this->assertEquals('tns:ArrayOfComplexTypeA', $return); + // class b + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="ComplexTypeB"]'); + $this->assertEquals(1, $nodes->length, 'Missing complex type definition.'); - $wsdl = $this->wsdl->toXML(); + foreach (array( + 'bar' => 'xsd:string', + 'foo' => 'xsd:string', + ) as $name => $type) { + $node = $this->xpath->query('xsd:all/xsd:element[@name="'.$name.'"]', $nodes->item(0)); - $this->assertContains( - '', - $wsdl, - $wsdl - ); + $this->assertEquals($name, $node->item(0)->getAttribute('name'), 'Invalid name attribute value in complex object definition'); + $this->assertEquals($type, $node->item(0)->getAttribute('type'), 'Invalid type name in complex object definition'); + $this->assertEquals('true', $node->item(0)->getAttribute('nillable'), 'Invalid nillable attribute value'); + } - $this->assertContains( - '', - $wsdl - ); + + // array of class a and class b + foreach(array( + 'ArrayOfComplexTypeB' => 'ComplexTypeB', + 'ArrayOfComplexTypeA' => 'ComplexTypeA' + ) as $arrayTypeName => $typeName) { + + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="'.$arrayTypeName.'"]'); + $this->assertEquals(1, $nodes->length, 'Missing complex type definition.'); + + $nodes = $this->xpath->query('xsd:sequence/xsd:element', $nodes->item(0)); + $this->assertEquals(1, $nodes->length, 'Missing complex type element declaration'); + + $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), 'Wrong complex type element name attribute'); + $this->assertEquals('tns:'.$typeName, $nodes->item(0)->getAttribute('type'), 'Wrong complex type type attribute value'); + $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), 'Wrong complex type minOccurs attribute value'); + $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), 'Wrong complex type maxOccurs attribute value'); + } + + $this->testDocumentNodes(); } public function testAddComplexTypeOfNonExistingClassThrowsException() @@ -139,11 +219,3 @@ public function testAddComplexTypeOfNonExistingClassThrowsException() $this->wsdl->addComplexType('ZendTest\Soap\Wsdl\UnknownClass[]'); } } - -class SequenceTest -{ - /** - * @var int - */ - public $var = 5; -} diff --git a/test/Wsdl/CompositeStrategyTest.php b/test/Wsdl/CompositeStrategyTest.php old mode 100644 new mode 100755 index 090adf03..94224fe7 --- a/test/Wsdl/CompositeStrategyTest.php +++ b/test/Wsdl/CompositeStrategyTest.php @@ -8,13 +8,14 @@ * @package Zend_Soap */ -namespace ZendTest\Soap\Wsdl; +namespace ZendTest\Soap\Wsdl\ComplexTypeStrategy; use Zend\Soap\Wsdl\ComplexTypeStrategy; use Zend\Soap\Wsdl; use Zend\Soap\Wsdl\ComplexTypeStrategy\Composite; use Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex; use Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence; +use ZendTest\Soap\WsdlTestHelper; /** * @package Zend_Soap @@ -32,8 +33,13 @@ * @group Zend_Soap * @group Zend_Soap_Wsdl */ -class CompositeStrategyTest extends \PHPUnit_Framework_TestCase +class CompositeStrategyTest extends WsdlTestHelper { + + public function setUp() { + // override parent setup because it is needed only in one method + } + public function testCompositeApiAddingStragiesToTypes() { $strategy = new Composite(array(), new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); @@ -85,20 +91,19 @@ public function testCompositeThrowsExceptionOnInvalidStrategyPart2() $book = $strategy->getStrategyOfType('Anything'); } - - public function testCompositeDelegatesAddingComplexTypesToSubStrategies() { - $strategy = new ComplexTypeStrategy\Composite(array(), new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); - $strategy->connectTypeToStrategy('\ZendTest\Soap\Wsdl\Book', new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); - $strategy->connectTypeToStrategy('\ZendTest\Soap\Wsdl\Cookie', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); + $this->strategy = new ComplexTypeStrategy\Composite(array(), new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); + $this->strategy->connectTypeToStrategy('\ZendTest\Soap\TestAsset\Book', new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + $this->strategy->connectTypeToStrategy('\ZendTest\Soap\TestAsset\Cookie', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); - $wsdl = new Wsdl('SomeService', 'http://example.com'); - $strategy->setContext($wsdl); + parent::setUp(); - $this->assertEquals('tns:Book', $strategy->addComplexType('\ZendTest\Soap\Wsdl\Book')); - $this->assertEquals('tns:Cookie', $strategy->addComplexType('\ZendTest\Soap\Wsdl\Cookie')); - $this->assertEquals('xsd:anyType', $strategy->addComplexType('\ZendTest\Soap\Wsdl\Anything')); + $this->assertEquals('tns:Book', $this->strategy->addComplexType('\ZendTest\Soap\TestAsset\Book')); + $this->assertEquals('tns:Cookie', $this->strategy->addComplexType('\ZendTest\Soap\TestAsset\Cookie')); + $this->assertEquals('xsd:anyType', $this->strategy->addComplexType('\ZendTest\Soap\TestAsset\Anything')); + + $this->testDocumentNodes(); } public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrowsException() @@ -108,22 +113,16 @@ public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrows $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Cannot add complex type \'Test\''); $strategy->addComplexType('Test'); } -} -class Book -{ - /** - * @var int - */ - public $somevar; -} -class Cookie -{ /** - * @var int + * */ - public $othervar; -} -class Anything -{ + public function testGetDefaultStrategy() { + $strategyClass = 'Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType'; + + $strategy = new Composite(array(), $strategyClass); + + $this->assertEquals($strategyClass, get_class($strategy->getDefaultStrategy())); + } } + diff --git a/test/Wsdl/DefaultComplexTypeTest.php b/test/Wsdl/DefaultComplexTypeTest.php old mode 100644 new mode 100755 index 39479d76..a420aa52 --- a/test/Wsdl/DefaultComplexTypeTest.php +++ b/test/Wsdl/DefaultComplexTypeTest.php @@ -12,6 +12,10 @@ use Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType; use Zend\Soap\Wsdl; +use ZendTest\Soap\TestAsset\PublicPrivateProtected; +use ZendTest\Soap\WsdlTestHelper; + +require_once __DIR__ . '/../TestAsset/commontypes.php'; /** * @category Zend @@ -20,24 +24,18 @@ * @group Zend_Soap * @group Zend_Soap_Wsdl */ -class DefaultComplexTypeTest extends \PHPUnit_Framework_TestCase +class DefaultComplexTypeTest extends WsdlTestHelper { /** - * @var Zend_Soap_Wsdl + * @var DefaultComplexType */ - private $wsdl; - - /** - * @var Zend_Soap_Wsdl_Strategy_DefaultComplexType - */ - private $strategy; + protected $strategy; public function setUp() { $this->strategy = new DefaultComplexType(); - $this->wsdl = new Wsdl("TestService", "http://framework.zend.com/soap/unittests"); - $this->wsdl->setComplexTypeStrategy($this->strategy); - $this->strategy->setContext($this->wsdl); + + parent::setUp(); } /** @@ -45,31 +43,15 @@ public function setUp() */ public function testOnlyPublicPropertiesAreDiscoveredByStrategy() { - $this->strategy->addComplexType('\ZendTest\Soap\Wsdl\PublicPrivateProtected'); - - $xml = $this->wsdl->toXML(); - $this->assertNotContains( PublicPrivateProtected::PROTECTED_VAR_NAME, $xml); - $this->assertNotContains( PublicPrivateProtected::PRIVATE_VAR_NAME, $xml); - } -} - -class PublicPrivateProtected -{ - const PROTECTED_VAR_NAME = 'bar'; - const PRIVATE_VAR_NAME = 'baz'; + $this->strategy->addComplexType('ZendTest\Soap\TestAsset\PublicPrivateProtected'); - /** - * @var string - */ - public $foo; + $nodes = $this->xpath->query('//xsd:element[@name="'.(PublicPrivateProtected::PROTECTED_VAR_NAME).'"]'); + $this->assertEquals(0, $nodes->length, 'Document should not contain protected fields'); - /** - * @var string - */ - protected $bar; + $nodes = $this->xpath->query('//xsd:element[@name="'.(PublicPrivateProtected::PRIVATE_VAR_NAME).'"]'); + $this->assertEquals(0, $nodes->length, 'Document should not contain private fields'); - /** - * @var string - */ - private $baz; + $this->testDocumentNodes(); + } } + diff --git a/test/WsdlTest.php b/test/WsdlTest.php old mode 100644 new mode 100755 index 213749f3..a6e4f4a5 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -9,566 +9,648 @@ */ namespace ZendTest\Soap; +use Zend\Soap\Wsdl, + Zend\Soap\Wsdl\ComplexTypeStrategy; -use Zend\Soap\Wsdl; -use Zend\Soap\Wsdl\ComplexTypeStrategy; +use Zend\Uri\Uri; /** - * Test cases for Zend_Soap_Wsdl + * Zend_Soap_Server * * @category Zend * @package Zend_Soap * @subpackage UnitTests * @group Zend_Soap * @group Zend_Soap_Wsdl - */ -class WsdlTest extends \PHPUnit_Framework_TestCase + **/ +class WsdlTest extends WsdlTestHelper { - protected function sanitizeWsdlXmlOutputForOsCompability($xmlstring) + + function testConstructor() { - $xmlstring = str_replace(array("\r", "\n"), "", $xmlstring); - $xmlstring = preg_replace('/(>[\s]{1,}<)/', '', $xmlstring); - return $xmlstring; + $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri(null)); + $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); + $this->assertEquals($this->defaultServiceUri, $this->dom->lookupNamespaceUri('tns')); + $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); + $this->assertEquals(Wsdl::NS_SCHEMA, $this->dom->lookupNamespaceUri('xsd')); + $this->assertEquals(Wsdl::NS_S_ENC, $this->dom->lookupNamespaceUri('soap-enc')); + $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri('wsdl')); + + $this->assertEquals(Wsdl::NS_WSDL, $this->dom->documentElement->namespaceURI); + + $this->assertEquals($this->defaultServiceName, $this->dom->documentElement->getAttribute('name')); + $this->assertEquals($this->defaultServiceUri, $this->dom->documentElement->getAttribute('targetNamespace')); + + $this->testDocumentNodes(); } - public function swallowIncludeNotices($errno, $errstr) + /** + * @dataProvider dataProviderForURITesting + * + * @param string $uri + */ + public function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes($uri) { - if ($errno != E_WARNING || !strstr($errstr, 'failed')) { - return false; + if ($uri instanceof Uri) { + $uri = $uri->toString(); } + + $this->wsdl->setUri($uri); + + $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); + $this->assertEquals($uri, $this->dom->lookupNamespaceUri('tns')); + + //@todo string retrieved this way contains decoded entities +// $this->assertEquals($uri, $this->dom->documentElement->getAttribute('targetNamespace')); + $this->assertContains($uri, $this->wsdl->toXML()); + + $this->testDocumentNodes(); } - public function testConstructor() + /** + * @dataProvider dataProviderForURITesting + * + * @param string $uri + */ + public function testSetUriWithZendUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes($uri) { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl->setUri(new Uri($uri)); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' ); + $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); + $this->assertEquals($uri, $this->dom->lookupNamespaceUri('tns')); + + //@todo string retrieved this way contains decoded entities +// $this->assertEquals($uri, $this->dom->documentElement->getAttribute('targetNamespace')); + $this->assertContains($uri, $this->wsdl->toXML()); + + $this->testDocumentNodes(); } - public function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes() + /** + * @dataProvider dataProviderForURITesting + * + * @param string $uri + */ + public function testObjectConstructionWithDifferentURI($uri) { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->setUri('http://localhost/MyNewService.php'); + $wsdl = new Wsdl($this->defaultServiceName, $uri); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' ); + $dom = $this->registerNamespaces($wsdl->toDomDocument(), $uri); + + $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); + $this->assertEquals($uri, $dom->lookupNamespaceUri('tns')); + $this->assertEquals($uri, $dom->documentElement->getAttribute('targetNamespace')); + + $this->testDocumentNodes(); + } + + /** + * Data provider for uri testing + * + * @return array + */ + public function dataProviderForURITesting() + { + return array( + array('http://localhost/MyService.php'), + array('http://localhost/MyNewService.php'), + array(new Uri('http://localhost/MyService.php')), + /** + * @bug ZF-5736 + */ + array('http://localhost/MyService.php?a=b&b=c'), + + /** + * @bug ZF-5736 + */ + array('http://localhost/MyService.php?a=b&b=c'), + ); } - public function testAddMessage() + /** + * @dataProvider dataProviderForAddMessage + * + * @param array $parameters message parameters + */ + function testAddMessage($parameters) { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $messageParts = array(); + foreach($parameters as $i => $parameter) { + $messageParts['parameter'.$i] = $this->wsdl->getType($parameter); + } + + $messageName = 'myMessage'; + + $this->wsdl->addMessage($messageName, $messageParts); + + $messageNodes = $this->xpath->query('//wsdl:definitions/wsdl:message'); + + $this->assertGreaterThan(0, $messageNodes->length, 'Missing message node in definitions node.'); + + $this->assertEquals($messageName, $messageNodes->item(0)->getAttribute('name')); + + foreach ($messageParts as $parameterName => $parameterType) { + $part = $this->xpath->query('wsdl:part[@name="'.$parameterName.'"]', $messageNodes->item(0)); + $this->assertEquals($parameterType, $part->item(0)->getAttribute('type')); + } + $this->testDocumentNodes(); + } + + /** + * @dataProvider dataProviderForAddMessage + * + * @param array $parameters complex message parameters + */ + public function testAddComplexMessage($parameters) + { $messageParts = array(); - $messageParts['parameter1'] = $wsdl->getType('int'); - $messageParts['parameter2'] = $wsdl->getType('string'); - $messageParts['parameter3'] = $wsdl->getType('mixed'); + foreach($parameters as $i => $parameter) { + $messageParts['parameter'.$i] = array( + 'type' => $this->wsdl->getType($parameter), + 'name' => 'parameter'.$i + ); + } - $wsdl->addMessage('myMessage', $messageParts); + $messageName = 'myMessage'; - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' ); + $this->wsdl->addMessage($messageName, $messageParts); + + $messageNodes = $this->xpath->query('//wsdl:definitions/wsdl:message'); + + $this->assertGreaterThan(0, $messageNodes->length, 'Missing message node in definitions node.'); + + foreach ($messageParts as $parameterName => $parameterDefinition) { + $part = $this->xpath->query('wsdl:part[@name="'.$parameterName.'"]', $messageNodes->item(0)); + $this->assertEquals($parameterDefinition['type'], $part->item(0)->getAttribute('type')); + $this->assertEquals($parameterDefinition['name'], $part->item(0)->getAttribute('name')); + } + + $this->testDocumentNodes(); } - public function testAddPortType() + /** + * @return array + */ + public function dataProviderForAddMessage() + { + return array( + array(array('int', 'int', 'int')), + array(array('string', 'string', 'string', 'string')), + array(array('mixed')), + array(array('int', 'int', 'string', 'string')), + array(array('int', 'string', 'int', 'string')), + ); + } + + function testAddPortType() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $portName = 'myPortType'; + $this->wsdl->addPortType($portName); - $wsdl->addPortType('myPortType'); + $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' ); + $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); + + $this->assertTrue($portTypeNodes->item(0)->hasAttribute('name')); + $this->assertEquals($portName, $portTypeNodes->item(0)->getAttribute('name')); + + $this->testDocumentNodes(); } - public function testAddPortOperation() + /** + * @dataProvider dataProviderForAddPortOperation + * + * @param string $operationName + */ + function testAddPortOperation($operationName, $inputRequest = null, $outputResponse = null, $fail = null) { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $portName = 'myPortType'; + $portType = $this->wsdl->addPortType($portName); - $portType = $wsdl->addPortType('myPortType'); + $this->wsdl->addPortOperation($portType, $operationName, $inputRequest, $outputResponse, $fail); - $wsdl->addPortOperation($portType, 'operation1'); - $wsdl->addPortOperation($portType, 'operation2', 'tns:operation2Request', 'tns:operation2Response'); - $wsdl->addPortOperation($portType, 'operation3', 'tns:operation3Request', 'tns:operation3Response', 'tns:operation3Fault'); + $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType[@name="'.$portName.'"]'); + $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' ); + + $operationNodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $portTypeNodes->item(0)); + $this->assertGreaterThan(0, $operationNodes->length); + + if (empty($inputRequest) AND empty($outputResponse) AND empty($fail)) { + $this->assertFalse($operationNodes->item(0)->hasChildNodes()); + } else { + $this->assertTrue($operationNodes->item(0)->hasChildNodes()); + } + + if (!empty($inputRequest)) { + $inputNodes = $operationNodes->item(0)->getElementsByTagName('input'); + $this->assertEquals($inputRequest, $inputNodes->item(0)->getAttribute('message')); + } + + if (!empty($outputResponse)) { + $outputNodes = $operationNodes->item(0)->getElementsByTagName('output'); + $this->assertEquals($outputResponse, $outputNodes->item(0)->getAttribute('message')); + } + + if (!empty($fail)) { + $faultNodes = $operationNodes->item(0)->getElementsByTagName('fault'); + $this->assertEquals($fail, $faultNodes->item(0)->getAttribute('message')); + } + + $this->testDocumentNodes(); } - public function testAddBinding() + /** + * + */ + function dataProviderForAddPortOperation() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + return array( + array('operation'), + array('operation', 'tns:operationRequest', 'tns:operationResponse'), + array('operation', 'tns:operationRequest', 'tns:operationResponse', 'tns:operationFault'), + array('operation', 'tns:operationRequest', null, 'tns:operationFault'), + array('operation', null, null, 'tns:operationFault'), + array('operation', null, 'tns:operationResponse', 'tns:operationFault'), + array('operation', null, 'tns:operationResponse'), + ); + } - $wsdl->addPortType('myPortType'); - $wsdl->addBinding('MyServiceBinding', 'myPortType'); + function testAddBinding() + { + $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + $this->wsdl->toDomDocument()->formatOutput = true; - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' ); + $bindingNodes = $this->xpath->query('//wsdl:definitions/wsdl:binding'); + + if ($bindingNodes->length === 0) { + $this->fail('Missing binding node in definitions node.'.$bindingNodes->length); + } + + $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttribute('name')); + $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttribute('type')); + + $this->testDocumentNodes(); } - public function testAddBindingOperation() + /** + * @dataProvider dataProviderForAddBindingOperation + * + * @param $operationName + * @param null $input + * @param null $inputEncoding + * @param null $output + * @param null $outputEncoding + * @param null $fault + * @param null $faultEncoding + * @param null $faultName + */ + function testAddBindingOperation($operationName, + $input = null, $inputEncoding = null, + $output = null, $outputEncoding = null, + $fault = null, $faultEncoding = null, $faultName = null) { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $wsdl->addPortType('myPortType'); - $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); + $inputArray = array(); + if (!empty($input) AND !empty($inputEncoding)) { + $inputArray = array('use' => $input, 'encodingStyle' => $inputEncoding); + } - $wsdl->addBindingOperation($binding, 'operation1'); - $wsdl->addBindingOperation($binding, - 'operation2', - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") - ); - $wsdl->addBindingOperation($binding, - 'operation3', - 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/") - ); + $outputArray = array(); + if (!empty($output) AND !empty($outputEncoding)) { + $outputArray = array('use' => $output, 'encodingStyle' => $outputEncoding); + } - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' ); - } - - public function testAddSoapBinding() - { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - - $wsdl->addPortType('myPortType'); - $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); - - $wsdl->addSoapBinding($binding); - - $wsdl->addBindingOperation($binding, 'operation1'); - $wsdl->addBindingOperation($binding, - 'operation2', - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") - ); - - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' ); - - $wsdl1 = new Wsdl('MyService', 'http://localhost/MyService.php'); - - $wsdl1->addPortType('myPortType'); - $binding = $wsdl1->addBinding('MyServiceBinding', 'myPortType'); - - $wsdl1->addSoapBinding($binding, 'rpc'); - - $wsdl1->addBindingOperation($binding, 'operation1'); - $wsdl1->addBindingOperation($binding, - 'operation2', - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") - ); - - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl1->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' ); + $faultArray = array(); + if (!empty($fault) AND !empty($faultEncoding) AND !empty($faultName)) { + $faultArray = array('use' => $fault, 'encodingStyle' => $faultEncoding, 'name'=>$faultName); + } + + $this->wsdl->addBindingOperation($binding, + $operationName, + $inputArray, + $outputArray, + $faultArray + ); + + $bindingNodes = $this->xpath->query('//wsdl:binding'); + + $this->assertGreaterThan(0, $bindingNodes->length, 'Missing binding node in definition.'); + + $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttribute('name')); + $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttribute('type')); + + $operationNodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $bindingNodes->item(0)); + $this->assertEquals(1, $operationNodes->length, 'Missing operation node in definition.'); + + if (empty($inputArray) AND empty($outputArray) AND empty($faultArray)) { + $this->assertFalse($operationNodes->item(0)->hasChildNodes()); + } + + foreach (array( + '//wsdl:input/soap:body' => $inputArray, + '//wsdl:output/soap:body' => $outputArray, + '//wsdl:fault' => $faultArray + ) as $query => $ar) { + + if (!empty($ar)) { + $nodes = $this->xpath->query($query); + + $this->assertGreaterThan(0, $nodes->length, 'Missing operation body.'); + + foreach ($ar as $key => $val) { + $this->assertEquals($ar[$key], $nodes->item(0)->getAttribute($key), + 'Bad attribute in operation definition: '.$key); + } + } + } + + $this->testDocumentNodes(); } + /** + * + */ + public function dataProviderForAddBindingOperation() + { + + $enc = 'http://schemas.xmlsoap.org/soap/encoding/'; + + return array( + array('operation'), + array('operation', 'encoded', $enc, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), + array('operation', null, null, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), + array('operation', null, null, 'encoded', $enc, 'encoded'), + array('operation', 'encoded', $enc), + array('operation', null, null, null, null, 'encoded', $enc, 'myFaultName'), + array('operation', 'encoded1', $enc.'1', 'encoded2', $enc.'2', 'encoded3', $enc.'3', 'myFaultName'), + + ); + } - public function testAddSoapOperation() + /** + * @dataProvider dataProviderForSoapBindingStyle + */ + function testAddSoapBinding($style) { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl->addPortType('myPortType'); + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $wsdl->addPortType('myPortType'); - $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); + $this->wsdl->addSoapBinding($binding, $style); - $wsdl->addSoapOperation($binding, 'http://localhost/MyService.php#myOperation'); - $wsdl->addBindingOperation($binding, 'operation1'); - $wsdl->addBindingOperation($binding, - 'operation2', - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), - array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/") - ); + $nodes = $this->xpath->query('//soap:binding'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' ); + $this->assertGreaterThan(0, $nodes->length); + $this->assertEquals($style, $nodes->item(0)->getAttribute('style')); + + $this->testDocumentNodes(); } - public function testAddService() + public function dataProviderForSoapBindingStyle() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + return array( + array('document'), + array('rpc'), + ); + } - $wsdl->addPortType('myPortType'); - $wsdl->addBinding('MyServiceBinding', 'myPortType'); + /** + * @dataProvider dataProviderForAddSoapOperation + */ + function testAddSoapOperation($operationUrl) + { + $this->wsdl->addPortType('myPortType'); + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', 'http://localhost/MyService.php'); + $this->wsdl->addSoapOperation($binding, $operationUrl); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' ); + $node = $this->xpath->query('//soap:operation'); + $this->assertGreaterThan(0, $node->length); + $this->assertEquals($operationUrl, $node->item(0)->getAttribute('soapAction')); + + $this->testDocumentNodes(); + } + + public function dataProviderForAddSoapOperation() + { + return array( + array('http://localhost/MyService.php#myOperation'), + array(new Uri('http://localhost/MyService.php#myOperation')) + ); } - public function testAddDocumentation() + /** + * @dataProvider dataProviderForAddService + */ + function testAddService($serviceUrl) { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl->addPortType('myPortType'); + $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $portType = $wsdl->addPortType('myPortType'); + $this->wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', $serviceUrl); - $wsdl->addDocumentation($portType, 'This is a description for Port Type node.'); + $nodes = $this->xpath->query('//wsdl:service[@name="Service1"]/wsdl:port/soap:address'); + $this->assertGreaterThan(0, $nodes->length); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' - . '' - . 'This is a description for Port Type node.' - . '' - . '' ); + $this->assertEquals($serviceUrl, $nodes->item(0)->getAttribute('location')); + + $this->testDocumentNodes(); } - public function testAddDocumentationToSetInsertsBefore() + public function dataProviderForAddService() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + return array( + array('http://localhost/MyService.php'), + array(new Uri('http://localhost/MyService.php')) + ); + } - $messageParts = array(); - $messageParts['parameter1'] = $wsdl->getType('int'); - $messageParts['parameter2'] = $wsdl->getType('string'); - $messageParts['parameter3'] = $wsdl->getType('mixed'); + function testAddDocumentation() + { + $doc = 'This is a description for Port Type node.'; + $this->wsdl->addDocumentation($this->wsdl, $doc); - $message = $wsdl->addMessage('myMessage', $messageParts); - $wsdl->addDocumentation($message, "foo"); + $nodes = $this->wsdl->toDomDocument()->childNodes; + $this->assertEquals(1, $nodes->length); + $this->assertEquals($doc, $nodes->item(0)->nodeValue); - $this->assertEquals( - '' . - '' - . '' - . 'foo' - . '' - . '' - . '' - . '' - . '', - $this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()) - ); + $this->testDocumentNodes(); } - public function testToXml() + function testAddDocumentationToSomeElmenet() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $portType = $this->wsdl->addPortType('myPortType'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), - '' . - '' ); + $doc = 'This is a description for Port Type node.'; + $this->wsdl->addDocumentation($portType, $doc); + + $nodes = $this->xpath->query('//wsdl:portType[@name="myPortType"]/wsdl:documentation'); + $this->assertEquals(1, $nodes->length); + $this->assertEquals($doc, $nodes->item(0)->nodeValue); + + $this->testDocumentNodes(); } - public function testToDomDocument() + public function testAddDocumentationToSetInsertsBefore() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $dom = $wsdl->toDomDocument(); + $messageParts = array(); + $messageParts['parameter1'] = $this->wsdl->getType('int'); + $messageParts['parameter2'] = $this->wsdl->getType('string'); + $messageParts['parameter3'] = $this->wsdl->getType('mixed'); - $this->assertTrue($dom instanceOf \DOMDocument); + $message = $this->wsdl->addMessage('myMessage', $messageParts); + $this->wsdl->addDocumentation($message, "foo"); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), - '' . - '' ); + $nodes = $this->xpath->query('//wsdl:message[@name="myMessage"]/*[1]'); + $this->assertEquals('documentation', $nodes->item(0)->nodeName); + + $this->testDocumentNodes(); + } + + public function testDumpToFile() + { + $file = tempnam(sys_get_temp_dir(), 'zfunittest'); + + $dumpStatus = $this->wsdl->dump($file); + + $fileContent = file_get_contents($file); + unlink($file); + + $this->assertTrue($dumpStatus, 'WSDL Dump fail'); + + $this->checkXMLContent($fileContent); } - public function testDump() + public function testDumpToOutput() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); ob_start(); - $wsdl->dump(); - $wsdlDump = ob_get_clean(); + $dumpStatus = $this->wsdl->dump(); + $screenContent = ob_get_clean(); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdlDump), - '' . - '' ); + $this->assertTrue($dumpStatus, 'Dump to output failed'); - $wsdl->dump(__DIR__ . '/TestAsset/dumped.wsdl'); - $dumpedContent = file_get_contents(__DIR__ . '/TestAsset/dumped.wsdl'); + $this->checkXMLContent($screenContent); + } - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($dumpedContent), - '' . - '' ); + public function checkXMLContent($content) + { + libxml_use_internal_errors(true); + libxml_disable_entity_loader(false); + $xml = new \DOMDocument(); + $xml->loadXML($content); - unlink(__DIR__ . '/TestAsset/dumped.wsdl'); + $errors = libxml_get_errors(); + $this->assertEmpty($errors, 'Libxml parsing errors: '.print_r($errors, 1)); + + $this->dom = $this->registerNamespaces($xml); + + $this->testConstructor(); + + $this->testDocumentNodes(); } public function testGetType() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - - $this->assertEquals('xsd:string', $wsdl->getType('string'), 'xsd:string detection failed.'); - $this->assertEquals('xsd:string', $wsdl->getType('str'), 'xsd:string detection failed.'); - $this->assertEquals('xsd:int', $wsdl->getType('int'), 'xsd:int detection failed.'); - $this->assertEquals('xsd:int', $wsdl->getType('integer'), 'xsd:int detection failed.'); - $this->assertEquals('xsd:float', $wsdl->getType('float'), 'xsd:float detection failed.'); - $this->assertEquals('xsd:double', $wsdl->getType('double'), 'xsd:double detection failed.'); - $this->assertEquals('xsd:boolean', $wsdl->getType('boolean'), 'xsd:boolean detection failed.'); - $this->assertEquals('xsd:boolean', $wsdl->getType('bool'), 'xsd:boolean detection failed.'); - $this->assertEquals('soap-enc:Array', $wsdl->getType('array'), 'soap-enc:Array detection failed.'); - $this->assertEquals('xsd:struct', $wsdl->getType('object'), 'xsd:struct detection failed.'); - $this->assertEquals('xsd:anyType', $wsdl->getType('mixed'), 'xsd:anyType detection failed.'); - $this->assertEquals('', $wsdl->getType('void'), 'void detection failed.'); + $this->assertEquals('xsd:string', $this->wsdl->getType('string'), 'xsd:string detection failed.'); + $this->assertEquals('xsd:string', $this->wsdl->getType('str'), 'xsd:string detection failed.'); + $this->assertEquals('xsd:int', $this->wsdl->getType('int'), 'xsd:int detection failed.'); + $this->assertEquals('xsd:int', $this->wsdl->getType('integer'), 'xsd:int detection failed.'); + $this->assertEquals('xsd:float', $this->wsdl->getType('float'), 'xsd:float detection failed.'); + $this->assertEquals('xsd:double', $this->wsdl->getType('double'), 'xsd:double detection failed.'); + $this->assertEquals('xsd:boolean', $this->wsdl->getType('boolean'), 'xsd:boolean detection failed.'); + $this->assertEquals('xsd:boolean', $this->wsdl->getType('bool'), 'xsd:boolean detection failed.'); + $this->assertEquals('soap-enc:Array', $this->wsdl->getType('array'), 'soap-enc:Array detection failed.'); + $this->assertEquals('xsd:struct', $this->wsdl->getType('object'), 'xsd:struct detection failed.'); + $this->assertEquals('xsd:anyType', $this->wsdl->getType('mixed'), 'xsd:anyType detection failed.'); + $this->assertEquals('', $this->wsdl->getType('void'), 'void detection failed.'); } - public function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() + function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals('tns:WsdlTestClass', $wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); + $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); + $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); -// $wsdl2 = new Wsdl('MyService', 'http://localhost/MyService.php', false); -// $this->assertEquals('xsd:anyType', $wsdl2->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); -// $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof ComplexTypeStrategy\AnyType); + $this->testDocumentNodes(); } - public function testGetComplexTypeBasedOnStrategiesStringNames() + function testGetComplexTypeBasedOnStrategiesStringNames() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); - $this->assertEquals('tns:WsdlTestClass', $wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); + $this->wsdl = new Wsdl($this->defaultServiceName, 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); + $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); + $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); - $wsdl2 = new Wsdl('MyService', 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); + $wsdl2 = new Wsdl($this->defaultServiceName, $this->defaultServiceUri, new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); $this->assertEquals('xsd:anyType', $wsdl2->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof ComplexTypeStrategy\AnyType); + + $this->testDocumentNodes(); } - public function testAddingSameComplexTypeMoreThanOnceIsIgnored() + function testAddingSameComplexTypeMoreThanOnceIsIgnored() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:SomeTypeName'); - $wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:AnotherTypeName'); - $types = $wsdl->getTypes(); + $this->wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:SomeTypeName'); + $this->wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:AnotherTypeName'); + $types = $this->wsdl->getTypes(); $this->assertEquals(1, count($types)); - $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:SomeTypeName'), - $types); + $this->assertEquals( + array( + '\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:SomeTypeName' + ), + $types + ); + + $this->testDocumentNodes(); + } + + function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition() + { + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $this->assertEquals( + array( + '\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:WsdlTestClass' + ), + $this->wsdl->getTypes() + ); + + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $this->assertEquals( + array( + '\ZendTest\Soap\TestAsset\WsdlTestClass' => 'tns:WsdlTestClass' + ), + $this->wsdl->getTypes() + ); + + $this->testDocumentNodes(); } - public function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition() + public function testGetSchema() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); - $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => - 'tns:WsdlTestClass'), - $wsdl->getTypes()); + $schema = $this->wsdl->getSchema(); - $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); - $this->assertEquals(array('\ZendTest\Soap\TestAsset\WsdlTestClass' => - 'tns:WsdlTestClass'), - $wsdl->getTypes()); + $this->assertEquals($this->defaultServiceUri, $schema->getAttribute('targetNamespace')); } - public function testAddComplexType() + function testAddComplexType() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType/xsd:all/*'); - $wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $this->assertGreaterThan(0, $nodes->length, 'Unable to find object properties in wsdl'); - $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()), + $this->testDocumentNodes(); +// print $nodes->length; +// print_r($nodes->item(0)->firstChild); +// print_r($this->wsdl->toXML()); +// +//exit; +// $this->markTestIncomplete(); + + /*$this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), '' . '' . '' . '' - . '' ); + . '' );*/ } + public function testAddTypesFromDocument() + { + $dom = new \DOMDocument(); + $types = $dom->createElementNS(WSDL::NS_WSDL, 'types'); + $dom->appendChild($types); + + $this->wsdl->addTypes($dom); + + $nodes = $this->xpath->query('//wsdl:types'); + $this->assertGreaterThanOrEqual(1, $nodes->length); + + $this->testDocumentNodes(); + } + + public function testAddTypesFromNode() + { + $dom = $this->dom->createElementNS(WSDL::NS_WSDL, 'types'); + + $this->wsdl->addTypes($dom); + + $nodes = $this->xpath->query('//wsdl:types'); + $this->assertGreaterThanOrEqual(1, $nodes->length); + + $this->testDocumentNodes(); + } + + public function testTranslateTypeFromClassMap() + { + $this->wsdl->setClassMap(array( + 'SomeType'=>'SomeOtherType' + )); + + $this->assertEquals('SomeOtherType', $this->wsdl->translateType('SomeType')); + } + + /** + * @dataProvider dataProviderForTranslateType + */ + public function testTranslateType($type, $expected) { + $this->assertEquals($expected, $this->wsdl->translateType($type)); + } + + public function dataProviderForTranslateType() { + return array( + array('\\SomeType','SomeType'), + array('SomeType\\','SomeType'), + array('\\SomeType\\','SomeType'), + array('\\SomeNamespace\SomeType\\','SomeType'), + ); + } + + /** * @group ZF-3910 */ - public function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() + function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - - $this->assertEquals("xsd:string", $wsdl->getType("StrIng")); - $this->assertEquals("xsd:string", $wsdl->getType("sTr")); - $this->assertEquals("xsd:int", $wsdl->getType("iNt")); - $this->assertEquals("xsd:int", $wsdl->getType("INTEGER")); - $this->assertEquals("xsd:float", $wsdl->getType("FLOAT")); - $this->assertEquals("xsd:double", $wsdl->getType("douBLE")); + $this->assertEquals("xsd:string", $this->wsdl->getType("StrIng")); + $this->assertEquals("xsd:string", $this->wsdl->getType("sTr")); + $this->assertEquals("xsd:int", $this->wsdl->getType("iNt")); + $this->assertEquals("xsd:int", $this->wsdl->getType("INTEGER")); + $this->assertEquals("xsd:float", $this->wsdl->getType("FLOAT")); + $this->assertEquals("xsd:double", $this->wsdl->getType("douBLE")); } /** @@ -610,8 +742,7 @@ public function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() */ public function testWsdlGetTypeWillAllowLongType() { - $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); - $this->assertEquals("xsd:long", $wsdl->getType("long")); + $this->assertEquals("xsd:long", $this->wsdl->getType("long")); } /** @@ -619,37 +750,65 @@ public function testWsdlGetTypeWillAllowLongType() */ public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceBySequenceStrategy() { - $wsdl = new Wsdl("MyService", "http://localhost/MyService.php"); - $wsdl->setComplexTypeStrategy(new ComplexTypeStrategy\ArrayOfTypeSequence()); + $this->wsdl->setComplexTypeStrategy(new ComplexTypeStrategy\ArrayOfTypeSequence()); - $wsdl->addComplexType("string[]"); - $wsdl->addComplexType("int[]"); - $wsdl->addComplexType("string[]"); + $this->wsdl->addComplexType("string[]"); + $this->wsdl->addComplexType("int[]"); + $this->wsdl->addComplexType("string[]"); - $xml = $wsdl->toXml(); + $xml = $this->wsdl->toXml(); $this->assertEquals(1, substr_count($xml, "ArrayOfString"), "ArrayOfString should appear only once."); $this->assertEquals(1, substr_count($xml, "ArrayOfInt"), "ArrayOfInt should appear only once."); + + $this->testDocumentNodes(); } - const URI_WITH_EXPANDED_AMP = "http://localhost/MyService.php?a=b&b=c"; - const URI_WITHOUT_EXPANDED_AMP = "http://localhost/MyService.php?a=b&b=c"; + public function testClassMap() + { + $this->wsdl->setClassMap(array('foo'=>'bar')); + + $this->assertArrayHasKey('foo', $this->wsdl->getClassMap()); + } /** - * @group ZF-5736 + * @expectedException RuntimeException */ - public function testHtmlAmpersandInUrlInConstructorIsEncodedCorrectly() + public function testAddElementException () { - $wsdl = new Wsdl("MyService", self::URI_WITH_EXPANDED_AMP); - $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML()); + $this->wsdl->addElement(1); } - /** - * @group ZF-5736 - */ - public function testHtmlAmpersandInUrlInSetUriIsEncodedCorrectly() + public function testAddElement() { - $wsdl = new Wsdl("MyService", "http://example.com"); - $wsdl->setUri(self::URI_WITH_EXPANDED_AMP); - $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML()); + $element = array( + 'name' => 'MyElement', + 'sequence' => array( + array('name' => 'myString', 'type' => 'string'), + array('name' => 'myInt', 'type' => 'int') + ) + ); + + $newElementName = $this->wsdl->addElement($element); + + $this->assertEquals('tns:'.$element['name'], $newElementName); + + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:element[@name="'.$element['name'].'"]/xsd:complexType'); + + $this->assertEquals(1, $nodes->length); + + $this->assertEquals('sequence', $nodes->item(0)->firstChild->localName); + + $n = 0; + foreach($element['sequence'] as $elementDefinition) { + $n++; + $elementNode = $this->xpath->query('xsd:element[@name="'.$elementDefinition['name'].'"]', $nodes->item(0)->firstChild); + $this->assertEquals($elementDefinition['type'], $elementNode->item(0)->getAttribute('type')); + } + + $this->assertEquals(count($element['sequence']), $n); + + $this->testDocumentNodes(); } + + } diff --git a/test/WsdlTestHelper.php b/test/WsdlTestHelper.php new file mode 100755 index 00000000..50f5685d --- /dev/null +++ b/test/WsdlTestHelper.php @@ -0,0 +1,120 @@ +strategy) OR !($this->strategy instanceof ComplexTypeStrategyInterface)) { + $this->strategy = new Wsdl\ComplexTypeStrategy\DefaultComplexType(); + } + + $this->wsdl = new Wsdl($this->defaultServiceName, $this->defaultServiceUri, $this->strategy); + + if ($this->strategy instanceof ComplexTypeStrategyInterface) { + $this->strategy->setContext($this->wsdl); + } + + $this->dom = $this->wsdl->toDomDocument(); + $this->dom = $this->registerNamespaces($this->dom); + } + + /** + * @param \DOMDocument $obj + * @param string $documentNamespace + * @return \DOMDocument + */ + public function registerNamespaces($obj, $documentNamespace = null) + { + + if (empty($documentNamespace)) { + $documentNamespace = $this->defaultServiceUri; + } + + $this->xpath = new \DOMXPath($obj); + $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); + + $this->xpath->registerNamespace('tns', $documentNamespace); + $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); + $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); + $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); + $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + + return $obj; + } + + /** + * @param \DOMElement $element + */ + public function testDocumentNodes($element = null) + { + if (!($this->wsdl instanceof Wsdl)) { + return; + } + + if (is_null($element)) { + $element = $this->wsdl->toDomDocument()->documentElement; + } + + /** @var $node \DOMElement */ + foreach ($element->childNodes as $node) { + if (in_array($node->nodeType, array(XML_ELEMENT_NODE))) { + $this->assertNotEmpty($node->namespaceURI, 'Document element: ' . $node->nodeName . ' has no valid namespace. Line: ' . $node->getLineNo()); + $this->testDocumentNodes($node); + } + } + } +} diff --git a/test/_files/wsdl_example.wsdl b/test/_files/wsdl_example.wsdl old mode 100644 new mode 100755 index 4eaa8761..19dc6878 --- a/test/_files/wsdl_example.wsdl +++ b/test/_files/wsdl_example.wsdl @@ -1,2 +1,89 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 10899031bc41973f01d088b725a5ffc6c06b53ac Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Sun, 24 Feb 2013 10:43:59 +0100 Subject: [PATCH 06/22] Quick fix in test. When runing clean from command line one test was failing. Fixed. --- test/ServerTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/ServerTest.php b/test/ServerTest.php index 5f0231a2..77329f19 100755 --- a/test/ServerTest.php +++ b/test/ServerTest.php @@ -495,8 +495,7 @@ public function testGetLastRequest() $server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass'); $request = - '' . "\n" - . 'World' . '' . '' - . '' . "\n"; + . ''; $response = $server->handle($request); @@ -773,7 +772,7 @@ public function testFaultWithIntegerFailureCodeDoesNotBreakClassSoapFault() } /** - * @expectedExcepti on \SoapFault + * @expectedException \SoapFault */ public function testHandlePhpErrors() { From 6894c86629b5f2955164859f606ab882b366152d Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 28 Feb 2013 01:19:34 +0100 Subject: [PATCH 07/22] Further improvements to the code. Code formating in accordance with Coding Style. More tests. Integration of recent code changes from ayastreb and weierophinney. Even more tests and test data. --- src/AutoDiscover.php | 22 +- .../DiscoveryStrategyInterface.php | 4 - .../DiscoveryStrategy/ReflectionDiscovery.php | 4 - src/Client.php | 12 +- src/Client/Common.php | 4 - src/Client/DotNet.php | 171 ++- src/Client/Local.php | 5 - src/Exception/BadMethodCallException.php | 4 - src/Exception/ExceptionInterface.php | 4 - src/Exception/ExtensionNotLoadedException.php | 4 - src/Exception/InvalidArgumentException.php | 4 - src/Exception/RuntimeException.php | 4 - src/Exception/UnexpectedValueException.php | 4 - src/Server.php | 17 +- src/Server/DocumentLiteralWrapper.php | 6 +- src/Wsdl.php | 128 +- .../AbstractComplexTypeStrategy.php | 4 - src/Wsdl/ComplexTypeStrategy/AnyType.php | 4 - .../ArrayOfTypeComplex.php | 4 - .../ArrayOfTypeSequence.php | 4 - .../ComplexTypeStrategyInterface.php | 4 - src/Wsdl/ComplexTypeStrategy/Composite.php | 4 - .../DefaultComplexType.php | 4 - test/AutoDiscoverTest.php | 1105 +++++++++++++---- test/ClientTest.php | 6 +- test/ServerTest.php | 4 +- test/TestAsset/commontypes.php | 5 +- test/TestAsset/testHandlePhpErrors.wsdl | 33 + test/Wsdl/ArrayOfTypeComplexStrategyTest.php | 169 ++- test/Wsdl/ArrayOfTypeSequenceStrategyTest.php | 72 +- test/Wsdl/CompositeStrategyTest.php | 28 +- test/WsdlTest.php | 252 ++-- test/WsdlTestHelper.php | 9 +- 33 files changed, 1553 insertions(+), 555 deletions(-) mode change 100644 => 100755 src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php create mode 100644 test/TestAsset/testHandlePhpErrors.wsdl diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php index a9d7c048..a2fdaf62 100755 --- a/src/AutoDiscover.php +++ b/src/AutoDiscover.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap; @@ -22,9 +21,6 @@ /** * \Zend\Soap\AutoDiscover * - * @category Zend - * @package Zend_Soap - * @subpackage AutoDiscover */ class AutoDiscover { @@ -195,8 +191,8 @@ public function setServiceName($serviceName) /** * Get service name * - * @return string * @throws Exception\RuntimeException + * @return string */ public function getServiceName() { @@ -219,8 +215,8 @@ public function getServiceName() * Set the location at which the WSDL file will be availabe. * * @param Uri\Uri|string $uri - * @return AutoDiscover * @throws Exception\InvalidArgumentException + * @return AutoDiscover */ public function setUri($uri) { @@ -246,8 +242,8 @@ public function setUri($uri) /** * Return the current Uri that the SOAP WSDL Service will be located at. * - * @return Uri\Uri * @throws Exception\RuntimeException + * @return Uri\Uri */ public function getUri() { @@ -267,8 +263,8 @@ public function getUri() * Set the name of the WSDL handling class. * * @param string $wsdlClass - * @return AutoDiscover * @throws Exception\InvalidArgumentException + * @return AutoDiscover */ public function setWsdlClass($wsdlClass) { @@ -300,8 +296,8 @@ public function getWsdlClass() * 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/". * * @param array $operationStyle - * @return AutoDiscover * @throws Exception\InvalidArgumentException + * @return AutoDiscover */ public function setOperationBodyStyle(array $operationStyle=array()) { @@ -578,7 +574,9 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) // Add the binding operation if ($isOneWayMessage == false) { - $operation = $wsdl->addBindingOperation($binding, $functionName, $operationBodyStyle, $operationBodyStyle); + $operation = $wsdl->addBindingOperation($binding, $functionName, + $operationBodyStyle, $operationBodyStyle + ); } else { $operation = $wsdl->addBindingOperation($binding, $functionName, $operationBodyStyle); } @@ -594,7 +592,9 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) public function generate() { if ($this->class && $this->functions) { - throw new Exception\RuntimeException("Can either dump functions or a class as a service, not both."); + throw new Exception\RuntimeException( + "Can either dump functions or a class as a service, not both." + ); } if ($this->class) { diff --git a/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php b/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php old mode 100644 new mode 100755 index ef3ec757..5c042b63 --- a/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php +++ b/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\AutoDiscover\DiscoveryStrategy; @@ -17,9 +16,6 @@ /** * Describes how types, return values and method details are detected during AutoDiscovery of a WSDL. * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ interface DiscoveryStrategyInterface { diff --git a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php index 21a56434..b9f4ff97 100755 --- a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php +++ b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\AutoDiscover\DiscoveryStrategy; @@ -18,9 +17,6 @@ * Describes how types, return values and method details are detected during * AutoDiscovery of a WSDL. * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ class ReflectionDiscovery implements DiscoveryStrategyInterface diff --git a/src/Client.php b/src/Client.php index b17b4a35..ee8b4d45 100755 --- a/src/Client.php +++ b/src/Client.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap; @@ -19,9 +18,6 @@ /** * \Zend\Soap\Client * - * @category Zend - * @package Zend_Soap - * @subpackage Client */ class Client implements ServerClient { @@ -390,7 +386,8 @@ public function getClassmap() * * @return Client */ - public function setTypemap(array $typeMap) { + public function setTypemap(array $typeMap) + { foreach ($typeMap as $type) { if (!is_callable($type['from_xml'])) { throw new Exception\InvalidArgumentException( @@ -415,7 +412,8 @@ public function setTypemap(array $typeMap) { * * @return array */ - public function getTypemap() { + public function getTypemap() + { return $this->typemap; } @@ -1145,7 +1143,7 @@ public function getLastSoapOutputHeaderObjects() */ public function __call($name, $arguments) { - if(!is_array($arguments)) { + if (!is_array($arguments)) { $arguments = array($arguments); } $soapClient = $this->getSoapClient(); diff --git a/src/Client/Common.php b/src/Client/Common.php index b1505aed..d9c820c2 100755 --- a/src/Client/Common.php +++ b/src/Client/Common.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Client; @@ -13,9 +12,6 @@ if (extension_loaded('soap')) { /** - * @category Zend - * @package Zend_Soap - * @subpackage Client */ class Common extends \SoapClient { diff --git a/src/Client/DotNet.php b/src/Client/DotNet.php index dc746dfc..b46ac3c6 100755 --- a/src/Client/DotNet.php +++ b/src/Client/DotNet.php @@ -5,25 +5,60 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Client; +use Zend\Http\Client\Adapter\Curl as CurlClient; +use Zend\Http\Response as HttpResponse; use Zend\Soap\Client as SOAPClient; +use Zend\Soap\Client\Common as CommonClient; use Zend\Soap\Exception; +use Zend\Uri\Http as HttpUri; /** * .NET SOAP client * * Class is intended to be used with .Net Web Services. * - * @category Zend - * @package Zend_Soap - * @subpackage Client */ class DotNet extends SOAPClient { + /** + * Curl HTTP client adapter. + * + * @var \Zend\Http\Client\Adapter\Curl + */ + private $curlClient = null; + + /** + * The last request headers. + * + * @var string + */ + private $lastRequestHeaders = ''; + + /** + * The last response headers. + * + * @var string + */ + private $lastResponseHeaders = ''; + + /** + * SOAP client options. + * + * @var array + */ + private $options = array(); + + /** + * Should NTLM authentication be used? + * + * @var boolean + */ + private $useNtlm = false; + /** * Constructor * @@ -38,6 +73,117 @@ public function __construct($wsdl = null, $options = null) parent::__construct($wsdl, $options); } + /** + * Do request proxy method. + * + * @param CommonClient $client Actual SOAP client. + * @param string $request The request body. + * @param string $location The SOAP URI. + * @param string $action The SOAP action to call. + * @param integer $version The SOAP version to use. + * @param integer $one_way (Optional) The number 1 if a response is not expected. + * @return string The XML SOAP response. + */ + public function _doRequest(CommonClient $client, $request, $location, $action, $version, $one_way = null) + { + if (!$this->useNtlm) { + return parent::_doRequest($client, $request, $location, $action, $version, $one_way); + } + + $curlClient = $this->getCurlClient(); + //@todo persistent connection ? + $headers = array('Content-Type' => 'text/xml; charset=utf-8', + 'Method' => 'POST', + 'SOAPAction' => '"' . $action . '"', + 'User-Agent' => 'PHP-SOAP-CURL'); + $uri = new HttpUri($location); + + //@todo use parent set options for ssl certificate authorization + $curlClient->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_NTLM) + ->setCurlOption(CURLOPT_SSL_VERIFYHOST, false) + ->setCurlOption(CURLOPT_SSL_VERIFYPEER, false) + ->setCurlOption(CURLOPT_USERPWD, $this->options['login'] . ':' . $this->options['password']); + + // Perform the cURL request and get the response + $curlClient->connect($uri->getHost(), $uri->getPort()); + $curlClient->write('POST', $uri, 1.1, $headers, $request); + $response = HttpResponse::fromString($curlClient->read()); + //@todo persistent connection ? + $curlClient->close(); + + // Save headers + $this->lastRequestHeaders = $this->flattenHeaders($headers); + $this->lastResponseHeaders = $response->getHeaders()->toString(); + + // Return only the XML body + return $response->getBody(); + } + + /** + * Returns the cURL client that is being used. + * + * @return \Zend\Http\Client\Adapter\Curl The cURL client. + */ + public function getCurlClient() + { + if ($this->curlClient === null) { + $this->curlClient = new CurlClient(); + } + + return $this->curlClient; + } + + /** + * Retrieve request headers. + * + * @return string Request headers. + */ + public function getLastRequestHeaders() + { + return $this->lastRequestHeaders; + } + + /** + * Retrieve response headers (as string) + * + * @return string Response headers. + */ + public function getLastResponseHeaders() + { + return $this->lastResponseHeaders; + } + + /** + * Sets the cURL client to use. + * + * @param CurlClient $curlClient The cURL client. + * @return self Fluent interface. + */ + public function setCurlClient(CurlClient $curlClient) + { + $this->curlClient = $curlClient; + return $this; + } + + /** + * Sets options. + * + * Allows setting options as an associative array of option => value pairs. + * + * @param array|\Traversable $options Options. + * @throws \InvalidArgumentException If an unsupported option is passed. + * @return self Fluent interface. + */ + public function setOptions($options) + { + if (isset($options['authentication']) && $options['authentication'] === 'ntlm') { + $this->useNtlm = true; + unset($options['authentication']); + } + + $this->options = $options; + return parent::setOptions($options); + } /** * Perform arguments pre-processing @@ -76,4 +222,21 @@ protected function _preProcessResult($result) return $result->$resultProperty; } + + /** + * Flattens an HTTP headers array into a string. + * + * @param array $headers The headers to flatten. + * @return string The headers string. + */ + private function flattenHeaders(array $headers) + { + $result = ''; + + foreach ($headers as $name => $value) { + $result .= $name . ': ' . $value . "\r\n"; + } + + return $result; + } } diff --git a/src/Client/Local.php b/src/Client/Local.php index 0b4a12fa..e3404991 100755 --- a/src/Client/Local.php +++ b/src/Client/Local.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Client; @@ -20,10 +19,6 @@ * with a provided Server object. * * Could be used for development or testing purposes. - * - * @category Zend - * @package Zend_Soap - * @subpackage Client */ class Local extends SOAPClient { diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index 663a085d..eadbf193 100755 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Exception; @@ -13,9 +12,6 @@ /** * Exception thrown when method is badly called * - * @category Zend - * @package Zend_Soap - * @subpackage Exception */ class BadMethodCallException extends \BadMethodCallException diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index c98a6b5c..2612fef8 100755 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Exception; @@ -13,9 +12,6 @@ /** * Common Exception interface * - * @category Zend - * @package Zend_Soap - * @subpackage AutoDiscover */ interface ExceptionInterface {} diff --git a/src/Exception/ExtensionNotLoadedException.php b/src/Exception/ExtensionNotLoadedException.php index e3d08465..40d81740 100755 --- a/src/Exception/ExtensionNotLoadedException.php +++ b/src/Exception/ExtensionNotLoadedException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Exception; @@ -13,9 +12,6 @@ /** * Exception thrown when soap php extension is not loaded * - * @category Zend - * @package Zend_Soap - * @subpackage Exception */ class ExtensionNotLoadedException extends RuntimeException {} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 17f22a86..9e9d12f3 100755 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Exception; @@ -13,9 +12,6 @@ /** * Exception thrown when arguments to method are invalid * - * @category Zend - * @package Zend_Soap - * @subpackage Client */ class InvalidArgumentException extends \InvalidArgumentException diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 62da3aae..b9080286 100755 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Exception; @@ -13,9 +12,6 @@ /** * Exception thrown when there is an error during program execution * - * @category Zend - * @package Zend_Soap - * @subpackage Client */ class RuntimeException extends \RuntimeException diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php index 30cb35a2..b17433e7 100755 --- a/src/Exception/UnexpectedValueException.php +++ b/src/Exception/UnexpectedValueException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Exception; @@ -13,9 +12,6 @@ /** * Exception thrown when provided arguments are invalid * - * @category Zend - * @package Zend_Soap - * @subpackage Client */ class UnexpectedValueException extends \UnexpectedValueException diff --git a/src/Server.php b/src/Server.php index 91db8fe2..8e48d132 100755 --- a/src/Server.php +++ b/src/Server.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap; @@ -21,9 +20,6 @@ /** * Zend_Soap_Server * - * @category Zend - * @package Zend_Soap - * @subpackage Server */ class Server implements \Zend\Server\Server { @@ -173,6 +169,7 @@ public function __construct($wsdl = null, array $options = null) * Allows setting options as an associative array of option => value pairs. * * @param array|Traversable $options + * * @return \Zend\Soap\Server */ public function setOptions($options) @@ -199,7 +196,7 @@ public function setOptions($options) case 'encoding': $this->setEncoding($value); break; - case 'soapVersion': + case 'soapversion': case 'soap_version': $this->setSoapVersion($value); break; @@ -212,9 +209,14 @@ public function setOptions($options) case 'cache_wsdl': $this->setWSDLCache($value); break; + // @todo is missing break really necessary ? case 'featues': - trigger_error(__METHOD__ . ': the option "featues" is deprecated as of 1.10.x and will be removed with 2.0.0; use "features" instead', E_USER_NOTICE); + trigger_error(__METHOD__ . ': the option "featues" is deprecated'. + ' as of 1.10.x and will be removed with 2.0.0; use "features" instead', + E_USER_NOTICE + ); + case 'features': $this->setSoapFeatures($value); break; @@ -979,7 +981,8 @@ public function registerFaultException($class) /** * @param $fault */ - public function isRegisteredAsFaultException($fault){ + public function isRegisteredAsFaultException($fault) + { $ref = new \ReflectionClass($fault); $classNames = $ref->getName(); diff --git a/src/Server/DocumentLiteralWrapper.php b/src/Server/DocumentLiteralWrapper.php index c25905ef..c034d529 100755 --- a/src/Server/DocumentLiteralWrapper.php +++ b/src/Server/DocumentLiteralWrapper.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Server; @@ -66,10 +65,6 @@ * $soap = new \Zend\Soap\Server($wsdlFile); * $soap->setObject(new \Zend\Soap\Server\DocumentLiteralWrapper($service)); * $soap->handle(); - * - * @category Zend - * @package Zend_Soap - * @subpackage Server */ class DocumentLiteralWrapper { @@ -123,6 +118,7 @@ public function __call($method, $args) protected function _parseArguments($method, $document) { $reflMethod = $this->reflection->getMethod($method); + /* @var \Zend\Server\Reflection\ReflectionParameter[] $params */ $params = array(); foreach ($reflMethod->getParameters() as $param) { $params[$param->getName()] = $param; diff --git a/src/Wsdl.php b/src/Wsdl.php index 09474212..7e980ba1 100755 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap; @@ -19,8 +18,6 @@ /** * \Zend\Soap\Wsdl * - * @category Zend - * @package Zend_Soap */ class Wsdl { @@ -66,6 +63,7 @@ class Wsdl const NS_WSDL = 'http://schemas.xmlsoap.org/wsdl/'; const NS_XMLNS = 'http://www.w3.org/2000/xmlns/'; const NS_SOAP = 'http://schemas.xmlsoap.org/wsdl/soap/'; + const NS_SOAP12 = 'http://schemas.xmlsoap.org/wsdl/soap12/'; const NS_SCHEMA = 'http://www.w3.org/2001/XMLSchema'; const NS_S_ENC = 'http://schemas.xmlsoap.org/soap/encoding/'; @@ -106,22 +104,23 @@ protected function getDOMDocument($name, $uri = null) $dom = new \DOMDocument(); $dom->preserveWhiteSpace = true; $dom->formatOutput = true; + $dom->resolveExternals = false; $dom->encoding = 'UTF-8'; + $dom->substituteEntities = false; $definitions = $dom->createElementNS(Wsdl::NS_WSDL, 'definitions'); - $dom->appendChild($definitions); $uri = $this->sanitizeUri($uri); - - $definitions->setAttribute('name', $name); - $definitions->setAttribute('targetNamespace', $uri); + $this->setAttributeWithSanitization($definitions, 'name', $name); + $this->setAttributeWithSanitization($definitions, 'targetNamespace', $uri); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:wsdl', Wsdl::NS_WSDL); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:tns', $uri); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:soap', Wsdl::NS_SOAP); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:xsd', Wsdl::NS_SCHEMA); $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:soap-enc', Wsdl::NS_S_ENC); + $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:soap12', Wsdl::NS_SOAP12); return $dom; } @@ -157,7 +156,7 @@ public function setUri($uri) $oldUri = $this->uri; $this->uri = $uri; - if($this->dom instanceof \DOMDocument ) { + if ($this->dom instanceof \DOMDocument ) { // namespace declarations are NOT true attributes $this->dom->documentElement->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:tns', $uri); @@ -167,6 +166,7 @@ public function setUri($uri) $xpath->registerNamespace('tns', $uri); $xpath->registerNamespace('soap', Wsdl::NS_SOAP); + $xpath->registerNamespace('soap12', Wsdl::NS_SOAP12); $xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); $xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); $xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); @@ -177,8 +177,8 @@ public function setUri($uri) /** @var $node \DOMAttr */ foreach ($attributeNodes as $node) { -// var_dump(array($oldUri, $uri, $node->nodeValue, str_replace($oldUri, $uri, $node->nodeValue))); - $node->nodeValue = str_replace($oldUri, $uri, $node->nodeValue); + $attributeValue = $this->dom->createTextNode(str_replace($oldUri, $uri, $node->nodeValue)); + $node->replaceChild($attributeValue, $node->childNodes->item(0)); } } @@ -261,11 +261,9 @@ public function addMessage($messageName, $parts) $part = $this->dom->createElementNS(Wsdl::NS_WSDL, 'part'); $part->setAttribute('name', $name); if (is_array($type)) { - foreach ($type as $key => $value) { - $part->setAttribute($key, $value); - } + $this->arrayToAttributes($part, $type); } else { - $part->setAttribute('type', $type); + $this->setAttributeWithSanitization($part, 'type', $type); } $message->appendChild($part); } @@ -308,18 +306,18 @@ public function addPortOperation($portType, $name, $input = false, $output = fal if (is_string($input) && (strlen(trim($input)) >= 1)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'input'); - $node->setAttribute('message', $input); $operation->appendChild($node); + $node->setAttribute('message', $input); } if (is_string($output) && (strlen(trim($output)) >= 1)) { $node= $this->dom->createElementNS(Wsdl::NS_WSDL, 'output'); - $node->setAttribute('message', $output); $operation->appendChild($node); + $node->setAttribute('message', $output); } if (is_string($fault) && (strlen(trim($fault)) >= 1)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'fault'); - $node->setAttribute('message', $fault); $operation->appendChild($node); + $node->setAttribute('message', $fault); } $portType->appendChild($operation); @@ -368,8 +366,8 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $binding->appendChild($operation); $attr = $this->dom->createAttribute('name'); - $attr->value = $name; $operation->appendChild($attr); + $attr->value = $name; if (is_array($input) AND !empty($input)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'input'); @@ -378,12 +376,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $soapNode = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); $node->appendChild($soapNode); - foreach ($input as $name => $value) { - $attr = $this->dom->createAttribute($name); - $attr->value = $value; - $soapNode->appendChild($attr); - } - + $this->arrayToAttributes($soapNode, $input); } if (is_array($output) AND !empty($output)) { @@ -393,23 +386,14 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $soapNode = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); $node->appendChild($soapNode); - foreach ($output as $name => $value) { - $attr = $this->dom->createAttribute($name); - $attr->value = $value; - $soapNode->appendChild($attr); - } + $this->arrayToAttributes($soapNode, $output); } if (is_array($fault) AND !empty($fault)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'fault'); $operation->appendChild($node); - foreach ($fault as $name => $value) { - $attr = $this->dom->createAttribute($name); - $attr->value = $value; - - $node->appendChild($attr); - } + $this->arrayToAttributes($node, $fault); } return $operation; @@ -448,7 +432,7 @@ public function addSoapOperation($binding, $soapAction) $soapAction = $soapAction->toString(); } $soapOperation = $this->dom->createElementNS(WSDL::NS_SOAP, 'operation'); - $soapOperation->setAttribute('soapAction', $soapAction); + $this->setAttributeWithSanitization($soapOperation, 'soapAction', $soapAction); $binding->insertBefore($soapOperation, $binding->firstChild); @@ -481,7 +465,7 @@ public function addService($name, $portName, $binding, $location) $service->appendChild($port); $soapAddress = $this->dom->createElementNS(WSDL::NS_SOAP, 'address'); - $soapAddress->setAttribute('location', $location); + $this->setAttributeWithSanitization($soapAddress, 'location', $location); $port->appendChild($soapAddress); @@ -584,7 +568,9 @@ public function getSchema() */ public function toXML() { - return $this->dom->saveXML(); + $this->dom->normalizeDocument(); + + return $this->dom->saveXML(); } /** @@ -594,6 +580,8 @@ public function toXML() */ public function toDomDocument() { + $this->dom->normalizeDocument(); + return $this->dom; } @@ -604,6 +592,7 @@ public function toDomDocument() */ public function dump($filename = false) { + $this->dom->normalizeDocument(); if (!$filename) { echo $this->toXML(); @@ -751,6 +740,69 @@ private function _parseElement($element) return $elementXML; } + /** + * @param string $name + * @param mixed $value + * @return string safe value or original $value + */ + private function sanitizeAttributeValueByName($name, $value) + { + switch (strtolower($name)) { + case 'targetnamespace': + case 'encodingstyle': + case 'soapaction': + case 'location': + return trim(htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false)); + break; + + default: + return $value; + break; + } + } + + /** + * + * @param \DOMNode $node + * @param array $attributes + * @param bool $withSanitizer + */ + private function arrayToAttributes(\DOMNode $node, array $attributes, $withSanitizer = true) + { + foreach($attributes as $attributeName => $attributeValue) { + if ($withSanitizer) { + $this->setAttributeWithSanitization($node, $attributeName, $attributeValue); + } else { + $this->setAttribute($node, $attributeName, $attributeValue); + } + } + } + + /** + * @param \DOMNode $node + * @param $attributeName + * @param $attributeValue + */ + private function setAttributeWithSanitization(\DOMNode $node, $attributeName, $attributeValue) + { + $attributeValue = $this->sanitizeAttributeValueByName($attributeName, $attributeValue); + $this->setAttribute($node, $attributeName, $attributeValue); + } + + /** + * @param \DOMNode $node + * @param $attributeName + * @param $attributeValue + */ + private function setAttribute(\DOMNode $node, $attributeName, $attributeValue) + { + $attributeNode = $node->ownerDocument->createAttribute($attributeName); + $node->appendChild($attributeNode); + + $attributeNodeValue = $node->ownerDocument->createTextNode($attributeValue); + $attributeNode->appendChild($attributeNodeValue); + } + /** * Add an xsd:element represented as an array to the schema. * diff --git a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php index b83c2967..a81f6ba2 100755 --- a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php +++ b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; @@ -13,9 +12,6 @@ /** * Abstract class for Zend_Soap_Wsdl_Strategy. * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ abstract class AbstractComplexTypeStrategy implements ComplexTypeStrategyInterface { diff --git a/src/Wsdl/ComplexTypeStrategy/AnyType.php b/src/Wsdl/ComplexTypeStrategy/AnyType.php index f887e04d..ccac34eb 100755 --- a/src/Wsdl/ComplexTypeStrategy/AnyType.php +++ b/src/Wsdl/ComplexTypeStrategy/AnyType.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; @@ -13,9 +12,6 @@ /** * Zend_Soap_Wsdl_Strategy_AnyType * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ class AnyType implements ComplexTypeStrategyInterface { diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php index fb171dbe..c9710278 100755 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; @@ -16,9 +15,6 @@ /** * ArrayOfTypeComplex strategy * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ class ArrayOfTypeComplex extends DefaultComplexType { diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php index ea81eb2c..5e033b0c 100755 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; @@ -15,9 +14,6 @@ /** * Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ class ArrayOfTypeSequence extends DefaultComplexType { diff --git a/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php b/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php old mode 100644 new mode 100755 index 686140e9..9bc22502 --- a/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php +++ b/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; @@ -15,9 +14,6 @@ /** * Interface strategies that generate an XSD-Schema for complex data types in WSDL files. * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ interface ComplexTypeStrategyInterface { diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php index 8dda7c8b..a9268440 100755 --- a/src/Wsdl/ComplexTypeStrategy/Composite.php +++ b/src/Wsdl/ComplexTypeStrategy/Composite.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; @@ -17,9 +16,6 @@ /** * Zend_Soap_Wsdl_Strategy_Composite * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ class Composite implements ComplexTypeStrategy { diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php index 51cdbb68..7b41b857 100755 --- a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php +++ b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Soap */ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; @@ -16,9 +15,6 @@ /** * Zend_Soap_Wsdl_Strategy_DefaultComplexType * - * @category Zend - * @package Zend_Soap - * @subpackage WSDL */ class DefaultComplexType extends AbstractComplexTypeStrategy { diff --git a/test/AutoDiscoverTest.php b/test/AutoDiscoverTest.php index 631ed1f4..415c3a36 100755 --- a/test/AutoDiscoverTest.php +++ b/test/AutoDiscoverTest.php @@ -13,7 +13,6 @@ /** Include Common TestTypes */ require_once 'TestAsset/commontypes.php'; -use Zend\Di\Exception\RuntimeException; use Zend\Soap\AutoDiscover; use Zend\Soap\Wsdl; use Zend\Uri\Uri; @@ -63,11 +62,18 @@ public function setUp() $this->server->setServiceName($this->defaultServiceName); } + /** + * + * + * @param \Zend\Soap\Wsdl $wsdl + * @param null $documentNamespace + */ public function bindWsdl(Wsdl $wsdl, $documentNamespace = null) { - $this->dom = new \DOMDocument(); - $this->dom->formatOutput = true; + $this->dom = new \DOMDocument(); + $this->dom->formatOutput = true; $this->dom->preserveWhiteSpace = false; + $this->dom->loadXML($wsdl->toXML()); if (empty($documentNamespace)) { @@ -76,13 +82,14 @@ public function bindWsdl(Wsdl $wsdl, $documentNamespace = null) $this->xpath = new \DOMXPath($this->dom); - $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); + $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); - $this->xpath->registerNamespace('tns', $documentNamespace); - $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); - $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); - $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); - $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + $this->xpath->registerNamespace('tns', $documentNamespace); + $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); + $this->xpath->registerNamespace('soap12', Wsdl::NS_SOAP12); + $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); + $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); + $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); } /** @@ -94,7 +101,7 @@ protected function assertValidWSDL(\DOMDocument $dom) { // this code is necessary to support some libxml stupidities. // @todo memory streams ? - $file = __DIR__.'/TestAsset/validate.wsdl'; + $file = __DIR__ . '/TestAsset/validate.wsdl'; if (file_exists($file)) { unlink($file); } @@ -103,7 +110,10 @@ protected function assertValidWSDL(\DOMDocument $dom) $dom = new \DOMDocument(); $dom->load($file); - $this->assertTrue($dom->schemaValidate(__DIR__ .'/schemas/wsdl.xsd'), "WSDL Did not validate"); + $this->assertTrue( + $dom->schemaValidate(__DIR__ . '/schemas/wsdl.xsd'), + "WSDL Did not validate" + ); unlink($file); } @@ -123,7 +133,11 @@ public function testDocumentNodes($element = null) /** @var $node \DOMElement */ foreach ($element->childNodes as $node) { if (in_array($node->nodeType, array(XML_ELEMENT_NODE))) { - $this->assertNotEmpty($node->namespaceURI, 'Document element: ' . $node->nodeName . ' has no valid namespace. Line: ' . $node->getLineNo()); + $this->assertNotEmpty( + $node->namespaceURI, 'Document element: ' + . $node->nodeName . ' has no valid namespace. Line: ' + . $node->getLineNo() + ); $this->testDocumentNodes($node); } } @@ -132,18 +146,18 @@ public function testDocumentNodes($element = null) /** * @dataProvider dataProviderValidUris */ - public function testAutoDiscoverConstructorUri($uri) { + public function testAutoDiscoverConstructorUri($uri, $expectedUri) + { $server = new AutoDiscover(null, $uri); - //@todo Uri::toString returns encoded uri - $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); - $this->assertEquals($uri, $server->getUri()->toString()); + $this->assertEquals($expectedUri, $server->getUri()->toString()); } /** * @dataProvider dataProviderForAutoDiscoverConstructorStrategy */ - public function testAutoDiscoverConstructorStrategy($strategy) { + public function testAutoDiscoverConstructorStrategy($strategy) + { $server = new AutoDiscover($strategy); $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); @@ -151,13 +165,16 @@ public function testAutoDiscoverConstructorStrategy($strategy) { $server->setUri('http://example.com'); $wsdl = $server->generate(); - $this->assertEquals(get_class($strategy), get_class($wsdl->getComplexTypeStrategy())); + $this->assertEquals( + get_class($strategy), get_class($wsdl->getComplexTypeStrategy()) + ); } /** * @return array */ - public function dataProviderForAutoDiscoverConstructorStrategy() { + public function dataProviderForAutoDiscoverConstructorStrategy() + { return array( array(new Wsdl\ComplexTypeStrategy\AnyType()), array(new Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex()), @@ -169,17 +186,20 @@ public function dataProviderForAutoDiscoverConstructorStrategy() { /** */ - public function testGetDiscoveryStrategy() { + public function testGetDiscoveryStrategy() + { $server = new AutoDiscover(); - $this->assertEquals('Zend\Soap\AutoDiscover\DiscoveryStrategy\ReflectionDiscovery', + $this->assertEquals( + 'Zend\Soap\AutoDiscover\DiscoveryStrategy\ReflectionDiscovery', get_class($server->getDiscoveryStrategy()) ); } /** */ - public function testAutoDiscoverConstructorWsdlClass() { + public function testAutoDiscoverConstructorWsdlClass() + { $server = new AutoDiscover(null, null, '\Zend\Soap\Wsdl'); $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); @@ -188,13 +208,16 @@ public function testAutoDiscoverConstructorWsdlClass() { $wsdl = $server->generate(); $this->assertEquals('Zend\Soap\Wsdl', trim(get_class($wsdl), '\\')); - $this->assertEquals('Zend\Soap\Wsdl', trim($server->getWsdlClass(), '\\')); + $this->assertEquals( + 'Zend\Soap\Wsdl', trim($server->getWsdlClass(), '\\') + ); } /** * @expectedException \Zend\Soap\Exception\InvalidArgumentException */ - public function testAutoDiscoverConstructorWsdlClassException() { + public function testAutoDiscoverConstructorWsdlClassException() + { $server = new AutoDiscover(); $server->setWsdlClass(new \stdClass()); } @@ -202,7 +225,8 @@ public function testAutoDiscoverConstructorWsdlClassException() { /** * @dataProvider dataProviderForSetServiceName */ - public function testSetServiceName($newName, $shouldBeValid) { + public function testSetServiceName($newName, $shouldBeValid) + { if ($shouldBeValid == false) { $this->setExpectedException('InvalidArgumentException'); @@ -210,13 +234,16 @@ public function testSetServiceName($newName, $shouldBeValid) { $this->server->setServiceName($newName); $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '/wsdl:definitions[@name="'.$newName.'"]'); + $this->assertSpecificNodeNumberInXPath( + 1, '/wsdl:definitions[@name="' . $newName . '"]' + ); } /** * @return array */ - public function dataProviderForSetServiceName() { + public function dataProviderForSetServiceName() + { return array( array('MyServiceName123', true), array('1MyServiceName123', false), @@ -228,7 +255,8 @@ public function dataProviderForSetServiceName() { ); } - public function testGetServiceName() { + public function testGetServiceName() + { $server = new AutoDiscover(); $server->setClass('\ZendTest\Soap\TestAsset\Test'); @@ -239,7 +267,8 @@ public function testGetServiceName() { /** * @expectedException \Zend\Soap\Exception\RuntimeException */ - public function testGetServiceNameException() { + public function testGetServiceNameException() + { $server = new AutoDiscover(); $server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); @@ -250,7 +279,8 @@ public function testGetServiceNameException() { /** * @expectedException \Zend\Soap\Exception\InvalidArgumentException */ - public function testSetUriException() { + public function testSetUriException() + { $server = new AutoDiscover(); $server->setUri(' '); @@ -259,12 +289,14 @@ public function testSetUriException() { /** * @expectedException \Zend\Soap\Exception\RuntimeException */ - public function testGetUriException() { + public function testGetUriException() + { $server = new AutoDiscover(); $server->getUri(); } - public function testClassMap() { + public function testClassMap() + { $classMap = array( 'TestClass' => 'test_class' @@ -281,61 +313,165 @@ public function testSetClass() $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]', 'Invalid schema definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:types/xsd:schema[@targetNamespace="' + . $this->defaultServiceUri . '"]', 'Invalid schema definition' + ); - for($i = 1; $i <= 4; $i++) { - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]', 'Invalid func'.$i.' operation definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:documentation', 'Invalid func'.$i.' port definition - documentation node'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:input[@message="tns:testFunc'.$i.'In"]', 'Invalid func'.$i.' port definition - input node'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:output[@message="tns:testFunc'.$i.'Out"]', 'Invalid func'.$i.' port definition - output node'); + for ($i = 1; $i <= 4; $i++) { + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc' + . $i . '"]', + 'Invalid func' . $i . ' operation definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc' + . $i . '"]/wsdl:documentation', + 'Invalid func' . $i . ' port definition - documentation node' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc' + . $i . '"]/wsdl:input[@message="tns:testFunc' . $i . 'In"]', + 'Invalid func' . $i . ' port definition - input node' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc' + . $i . '"]/wsdl:output[@message="tns:testFunc' . $i . 'Out"]', + 'Invalid func' . $i . ' port definition - output node' + ); } - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]', 'Invalid service binding definition'); - $this->assertEquals('tns:MyServicePort', $nodes->item(0)->getAttribute('type'), 'Invalid type attribute value in service binding definition'); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding"]', + 'Invalid service binding definition' + ); + $this->assertEquals( + 'tns:MyServicePort', $nodes->item(0)->getAttribute('type'), + 'Invalid type attribute value in service binding definition' + ); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/soap:binding', 'Invalid service binding definition'); - $this->assertEquals('rpc', $nodes->item(0)->getAttribute('style'), 'Invalid style attribute value in service binding definition'); - $this->assertEquals('http://schemas.xmlsoap.org/soap/http', $nodes->item(0)->getAttribute('transport'), 'Invalid transport attribute value in service binding definition'); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding"]/soap:binding', + 'Invalid service binding definition' + ); + $this->assertEquals( + 'rpc', $nodes->item(0)->getAttribute('style'), + 'Invalid style attribute value in service binding definition' + ); + $this->assertEquals( + 'http://schemas.xmlsoap.org/soap/http', + $nodes->item(0)->getAttribute('transport'), + 'Invalid transport attribute value in service binding definition' + ); - for($i = 1; $i <= 4; $i++) { - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]', 'Invalid func'.$i.' operation binding definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#testFunc'.$i.'"]', 'Invalid func'.$i.' operation action binding definition'); + for ($i = 1; $i <= 4; $i++) { + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'. $i . '"]', + 'Invalid func' . $i . ' operation binding definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc' + . $i . '"]/soap:operation[@soapAction="' . $this->defaultServiceUri . + '#testFunc' . $i . '"]', + 'Invalid func' . $i . ' operation action binding definition' + ); } - $xpath = '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[wsdl:input or wsdl:output]/*/soap:body'; + $xpath + = '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[wsdl:input or wsdl:output]/*/soap:body'; $this->assertSpecificNodeNumberInXPath(8, $xpath); $nodes = $this->xpath->query($xpath); - $this->assertAttributesOfNodes(array( - "use" => "encoded", - "encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/", - "namespace" => "http://localhost/MyService.php" - ), $nodes); + $this->assertAttributesOfNodes( + array( + "use" => "encoded", + "encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/", + "namespace" => "http://localhost/MyService.php" + ), $nodes + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]', 'Invalid service definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]', 'Invalid service port definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Invalid service address definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:service[@name="MyServiceService"]', + 'Invalid service definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:service[@name="MyServiceService"]/' + . 'wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]', + 'Invalid service port definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:service[@name="MyServiceService"]/' + . 'wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="' + . $this->defaultServiceUri . '"]', + 'Invalid service address definition' + ); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc1In"]', 'Invalid message definition'); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFunc1In"]', + 'Invalid message definition' + ); $this->assertFalse($nodes->item(0)->hasChildNodes()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc2In"]', 'Invalid message definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc2In"]/wsdl:part[@name="who" and @type="xsd:string"]', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFunc2In"]', + 'Invalid message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="testFunc2In"]/wsdl:part[@name="who" and @type="xsd:string"]', + 'Invalid message definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc2Out"]', 'Invalid message definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc2Out"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFunc2Out"]', + 'Invalid message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="testFunc2Out"]/wsdl:part[@name="return" and @type="xsd:string"]', + 'Invalid message definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc3In"]', 'Invalid message definition'); - $this->assertSpecificNodeNumberInXPath(2, '//wsdl:message[@name="testFunc3In"][(wsdl:part[@name="who" and @type="xsd:string"]) or (wsdl:part[@name="when" and @type="xsd:int"])]/wsdl:part', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFunc3In"]', + 'Invalid message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 2, + '//wsdl:message[@name="testFunc3In"][(wsdl:part[@name="who" and @type="xsd:string"]) or (wsdl:part[@name="when" and @type="xsd:int"])]/wsdl:part', + 'Invalid message definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc3Out"]', 'Invalid message definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc3Out"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFunc3Out"]', + 'Invalid message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="testFunc3Out"]/wsdl:part[@name="return" and @type="xsd:string"]', + 'Invalid message definition' + ); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc4In"]', 'Invalid message definition'); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFunc4In"]', + 'Invalid message definition' + ); $this->assertFalse($nodes->item(0)->hasChildNodes()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc4Out"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Invalid message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="testFunc4Out"]/wsdl:part[@name="return" and @type="xsd:string"]', + 'Invalid message definition' + ); $this->assertValidWSDL($this->dom); @@ -344,84 +480,234 @@ public function testSetClass() public function testSetClassWithDifferentStyles() { - $this->server->setBindingStyle(array('style' => 'document', 'transport' => $this->defaultServiceUri)); - $this->server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => $this->defaultServiceUri)); + $this->server->setBindingStyle( + array('style' => 'document', + 'transport' => $this->defaultServiceUri) + ); + $this->server->setOperationBodyStyle( + array('use' => 'literal', 'namespace' => $this->defaultServiceUri) + ); $this->server->setClass('\ZendTest\Soap\TestAsset\Test'); $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]', 'Missing test func1 definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]/xsd:complexType', 'Missing test func1 type definition'); - $this->assertSpecificNodeNumberInXPath(0, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]/xsd:complexType/*', 'Test func1 does not have children'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]', + 'Missing test func1 definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]/xsd:complexType', + 'Missing test func1 type definition' + ); + $this->assertSpecificNodeNumberInXPath( + 0, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1"]/xsd:complexType/*', + 'Test func1 does not have children' + ); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1Response"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func1 return element is invalid'); - $this->assertAttributesOfNodes(array( - 'name' => "testFunc1Result", - 'type' => "xsd:string", - ), $nodes); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc1Response"]/' + .'xsd:complexType/xsd:sequence/xsd:element', + 'Test func1 return element is invalid' + ); + $this->assertAttributesOfNodes( + array( + 'name' => "testFunc1Result", + 'type' => "xsd:string", + ), $nodes + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]', 'Missing test func2 definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]/xsd:complexType', 'Missing test func2 type definition'); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func2 does not have children'); - $this->assertAttributesOfNodes(array( - 'name' => "who", - 'type' => "xsd:string", - ), $nodes); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]', + 'Missing test func2 definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]/xsd:complexType', + 'Missing test func2 type definition' + ); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2"]/xsd:complexType/' + .'xsd:sequence/xsd:element', + 'Test func2 does not have children' + ); + $this->assertAttributesOfNodes( + array( + 'name' => "who", + 'type' => "xsd:string", + ), $nodes + ); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2Response"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func2 return element is invalid'); - $this->assertAttributesOfNodes(array( - 'name' => "testFunc2Result", - 'type' => "xsd:string", - ), $nodes); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc2Response"]/' + .'xsd:complexType/xsd:sequence/xsd:element', + 'Test func2 return element is invalid' + ); + $this->assertAttributesOfNodes( + array( + 'name' => "testFunc2Result", + 'type' => "xsd:string", + ), $nodes + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]', 'Missing test func3 definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType', 'Missing test func3 type definition'); - $this->assertSpecificNodeNumberInXPath(2, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func3 does not have children'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/xsd:sequence/xsd:element[@name="who" and @type="xsd:string"]', 'Test func3 does not have children'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/xsd:sequence/xsd:element[@name="when" and @type="xsd:int"]', 'Test func3 does not have children'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]', + 'Missing test func3 definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType', + 'Missing test func3 type definition' + ); + $this->assertSpecificNodeNumberInXPath( + 2, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/' + .'xsd:sequence/xsd:element', + 'Test func3 does not have children' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/' + .'xsd:sequence/xsd:element[@name="who" and @type="xsd:string"]', + 'Test func3 does not have children' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3"]/xsd:complexType/' + .'xsd:sequence/xsd:element[@name="when" and @type="xsd:int"]', + 'Test func3 does not have children' + ); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3Response"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func3 return element is invalid'); - $this->assertAttributesOfNodes(array( - 'name' => "testFunc3Result", - 'type' => "xsd:string", - ), $nodes); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc3Response"]/' + .'xsd:complexType/xsd:sequence/xsd:element', + 'Test func3 return element is invalid' + ); + $this->assertAttributesOfNodes( + array( + 'name' => "testFunc3Result", + 'type' => "xsd:string", + ), $nodes + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]', 'Missing test func1 definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]/xsd:complexType', 'Missing test func1 type definition'); - $this->assertSpecificNodeNumberInXPath(0, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]/xsd:complexType/*', 'Test func1 does not have children'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]', + 'Missing test func1 definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]/xsd:complexType', + 'Missing test func1 type definition' + ); + $this->assertSpecificNodeNumberInXPath( + 0, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4"]/xsd:complexType/*', + 'Test func1 does not have children' + ); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4Response"]/xsd:complexType/xsd:sequence/xsd:element', 'Test func1 return element is invalid'); - $this->assertAttributesOfNodes(array( - 'name' => "testFunc4Result", - 'type' => "xsd:string", - ), $nodes); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:element[@name="testFunc4Response"]/' + .'xsd:complexType/xsd:sequence/xsd:element', + 'Test func1 return element is invalid' + ); + $this->assertAttributesOfNodes( + array( + 'name' => "testFunc4Result", + 'type' => "xsd:string", + ), $nodes + ); for ($i = 1; $i <= 4; $i++) { - $this->assertSpecificNodeNumberInXPath(3, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/*', 'Missing test func'.$i.' port definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:documentation', 'Missing test func'.$i.' port documentation'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:input[@message="tns:testFunc'.$i.'In"]', 'Missing test func'.$i.' port input message'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:output[@message="tns:testFunc'.$i.'Out"]', 'Missing test func'.$i.' port output message'); + $this->assertSpecificNodeNumberInXPath( + 3, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc' + . $i . '"]/*', + 'Missing test func' . $i . ' port definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc' + . $i . '"]/wsdl:documentation', + 'Missing test func' . $i . ' port documentation' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc' + . $i . '"]/wsdl:input[@message="tns:testFunc' . $i . 'In"]', + 'Missing test func' . $i . ' port input message' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="testFunc' + . $i . '"]/wsdl:output[@message="tns:testFunc' . $i + . 'Out"]', + 'Missing test func' . $i . ' port output message' + ); } for ($i = 1; $i <= 4; $i++) { - $this->assertSpecificNodeNumberInXPath(3, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/*', 'Missing test func'.$i.' binding definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#testFunc'.$i.'"]', 'Missing test func'.$i.' binding operation definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:input/soap:body[@use="literal" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing test func'.$i.' binding input message'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc'.$i.'"]/wsdl:output/soap:body[@use="literal" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing test func'.$i.' binding input message'); + $this->assertSpecificNodeNumberInXPath( + 3, + '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc' + . $i . '"]/*', + 'Missing test func' . $i . ' binding definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc' + . $i . '"]/soap:operation[@soapAction="' + . $this->defaultServiceUri . '#testFunc' . $i . '"]', + 'Missing test func' . $i . ' binding operation definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc' + . $i + . '"]/wsdl:input/soap:body[@use="literal" and @namespace="' + . $this->defaultServiceUri . '"]', + 'Missing test func' . $i . ' binding input message' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding"]/wsdl:operation[@name="testFunc' + . $i + . '"]/wsdl:output/soap:body[@use="literal" and @namespace="' + . $this->defaultServiceUri . '"]', + 'Missing test func' . $i . ' binding input message' + ); } - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort"' + . ' and @binding="tns:MyServiceBinding"]/soap:address[@location="' + . $this->defaultServiceUri . '"]' + ); for ($i = 1; $i <= 4; $i++) { - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc'.$i.'In"]/wsdl:part[@name="parameters" and @element="tns:testFunc'.$i.'"]', 'Missing test testFunc'.$i.' input message definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc'.$i.'Out"]/wsdl:part[@name="parameters" and @element="tns:testFunc'.$i.'Response"]', 'Missing test testFunc'.$i.' output message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFunc' . $i + . 'In"]/wsdl:part[@name="parameters" and @element="tns:testFunc' . $i . '"]', + 'Missing test testFunc' . $i . ' input message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFunc' . $i + . 'Out"]/wsdl:part[@name="parameters" and @element="tns:testFunc' . $i . 'Response"]', + 'Missing test testFunc' . $i . ' output message definition' + ); } @@ -439,7 +725,10 @@ public function testSetClassWithResponseReturnPartCompabilityMode() for ($i = 1; $i <= 4; $i++) { - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFunc'.$i.'Out"]/wsdl:part[@name="return"]'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="testFunc' . $i . 'Out"]/wsdl:part[@name="return"]' + ); } @@ -450,18 +739,20 @@ public function testSetClassWithResponseReturnPartCompabilityMode() * @expectedException \Zend\Soap\Exception\InvalidArgumentException * @dataProvider dataProviderForAddFunctionException */ - public function testAddFunctionException($function){ + public function testAddFunctionException($function) + { $this->server->addFunction($function); } /** * @return array */ - public function dataProviderForAddFunctionException(){ + public function dataProviderForAddFunctionException() + { return array( array('InvalidFunction'), array(1), - array(array(1,2)), + array(array(1, 2)), ); } @@ -471,24 +762,84 @@ public function testAddFunctionSimple() $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service port definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:documentation', 'Missing service port definition documentation'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input', 'Missing service port definition input message'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output', 'Missing service port definition input message'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', + 'Missing service port definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:documentation', + 'Missing service port definition documentation' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input', + 'Missing service port definition input message' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output', + 'Missing service port definition input message' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service binding definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', 'Missing service binding transport definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#TestFunc"]', 'Missing service operation action definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input body definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input body definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]', + 'Missing service binding definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . ' soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', + 'Missing service binding transport definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . ' wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="' + . $this->defaultServiceUri . '#TestFunc"]', + 'Missing service operation action definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="encoded" ' + . 'and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="' + . $this->defaultServiceUri . '"]', + 'Missing operation input body definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="encoded"' + . 'and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="' + . $this->defaultServiceUri . '"]', + 'Missing operation input body definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort"' + . ' and @binding="tns:MyServiceBinding"]/soap:address[@location="' + . $this->defaultServiceUri . '"]', + 'Missing service port definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="who" and @type="xsd:string"]', 'Missing test testFunc input message definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Missing test testFunc input message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="who" and @type="xsd:string"]', + 'Missing test testFunc input message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="return" and @type="xsd:string"]', + 'Missing test testFunc input message definition' + ); $this->assertValidWSDL($this->dom); @@ -497,36 +848,115 @@ public function testAddFunctionSimple() public function testAddFunctionSimpleWithDifferentStyle() { - $this->server->setBindingStyle(array('style' => 'document', 'transport' => $this->defaultServiceUri)); - $this->server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => $this->defaultServiceUri)); + $this->server->setBindingStyle( + array('style' => 'document', + 'transport' => $this->defaultServiceUri) + ); + $this->server->setOperationBodyStyle( + array('use' => 'literal', 'namespace' => $this->defaultServiceUri) + ); $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema[@targetNamespace="' + . $this->defaultServiceUri . '"]', 'Missing service port definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]/xsd:element[@name="TestFunc"]/xsd:complexType/xsd:sequence/xsd:element[@name="who" and @type="xsd:string"]', 'Missing complex type definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]/xsd:element[@name="TestFuncResponse"]/xsd:complexType/xsd:sequence/xsd:element[@name="TestFuncResult" and @type="xsd:string"]', 'Missing complex type definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema[@targetNamespace="' . $this->defaultServiceUri + . '"]/xsd:element[@name="TestFunc"]/xsd:complexType/xsd:sequence/' + . 'xsd:element[@name="who" and @type="xsd:string"]', + 'Missing complex type definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema[@targetNamespace="' . $this->defaultServiceUri + . '"]/xsd:element[@name="TestFuncResponse"]/xsd:complexType/xsd:sequence' + . '/xsd:element[@name="TestFuncResult" and @type="xsd:string"]', + 'Missing complex type definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service port definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:documentation', 'Missing service port definition documentation'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input', 'Missing service port definition input message'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output', 'Missing service port definition input message'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', + 'Missing service port definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:documentation', + 'Missing service port definition documentation' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input', + 'Missing service port definition input message' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output', + 'Missing service port definition input message' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service binding definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/soap:binding[@style="document" and @transport="'.$this->defaultServiceUri.'"]', 'Missing service binding transport definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#TestFunc"]', 'Missing service operation action definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="literal" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input body definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="literal" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input body definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]', + 'Missing service binding definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'soap:binding[@style="document" and @transport="' . $this->defaultServiceUri . '"]', + 'Missing service binding transport definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="' + . $this->defaultServiceUri . '#TestFunc"]', + 'Missing service operation action definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="literal" and @namespace="' + . $this->defaultServiceUri . '"]', + 'Missing operation input body definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="literal" and @namespace="' + . $this->defaultServiceUri . '"]', + 'Missing operation input body definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort"' + . ' and @binding="tns:MyServiceBinding"]/soap:address[@location="' + . $this->defaultServiceUri . '"]', + 'Missing service port definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="parameters" and @element="tns:TestFunc"]', 'Missing test testFunc input message definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="parameters" and @element="tns:TestFuncResponse"]', 'Missing test testFunc input message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="parameters" and @element="tns:TestFunc"]', + 'Missing test testFunc input message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="parameters" and @element="tns:TestFuncResponse"]', + 'Missing test testFunc input message definition' + ); $this->assertValidWSDL($this->dom); @@ -541,27 +971,93 @@ public function testAddFunctionSimpleInReturnNameCompabilityMode() $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:types/xsd:schema[@targetNamespace="' + . $this->defaultServiceUri . '"]', 'Missing service port definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service port definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:documentation', 'Missing service port definition documentation'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input', 'Missing service port definition input message'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output', 'Missing service port definition input message'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]', + 'Missing service port definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/' + . 'wsdl:documentation', + 'Missing service port definition documentation' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/' + . 'wsdl:input', + 'Missing service port definition input message' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc"]/' + . 'wsdl:output', + 'Missing service port definition input message' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]', 'Missing service binding definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', 'Missing service binding transport definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#TestFunc"]', 'Missing service operation action definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="http://localhost/MyService.php"]', 'Missing operation input body definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="http://localhost/MyService.php"]', 'Missing operation input body definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]', + 'Missing service binding definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', + 'Missing service binding transport definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]/soap:operation[@soapAction="' + . $this->defaultServiceUri . '#TestFunc"]', + 'Missing service operation action definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]/wsdl:input/soap:body[@use="encoded"' + . ' and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ' + . 'and @namespace="http://localhost/MyService.php"]', + 'Missing operation input body definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc"]/wsdl:output/soap:body[@use="encoded"' + . 'and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and' + . '@namespace="http://localhost/MyService.php"]', + 'Missing operation input body definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort"' + . 'and @binding="tns:MyServiceBinding"]/soap:address[@location="' + . $this->defaultServiceUri . '"]', + 'Missing service port definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="who" and @type="xsd:string"]', 'Missing test testFunc input message definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="return" and @type="xsd:string"]', 'Missing test testFunc input message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="TestFuncIn"]/wsdl:part[@name="who" and @type="xsd:string"]', + 'Missing test testFunc input message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:message[@name="TestFuncOut"]/wsdl:part[@name="return" and @type="xsd:string"]', + 'Missing test testFunc input message definition' + ); $this->assertValidWSDL($this->dom); @@ -582,33 +1078,98 @@ public function testAddFunctionMultiple() $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema[@targetNamespace="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); - - - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:types/xsd:schema[@targetNamespace="' + . $this->defaultServiceUri . '"]', 'Missing service port definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort" and @binding="tns:MyServiceBinding"]/soap:address[@location="'.$this->defaultServiceUri.'"]', 'Missing service port definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'soap:binding[@style="rpc" and @transport="http://schemas.xmlsoap.org/soap/http"]', + 'Missing service port definition' + ); - foreach(array('', 2,3, 4, 5, 6, 7, 9) as $i) { - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]', 'Missing service port definition for TestFunc'.$i.''); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:documentation', 'Missing service port definition documentation for TestFunc'.$i.''); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:input[@message="tns:TestFunc'.$i.'In"]', 'Missing service port definition input message for TestFunc'.$i.''); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:service[@name="MyServiceService"]/wsdl:port[@name="MyServicePort"' + . ' and @binding="tns:MyServiceBinding"]/soap:address[@location="' + . $this->defaultServiceUri . '"]', + 'Missing service port definition' + ); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/soap:operation[@soapAction="'.$this->defaultServiceUri.'#TestFunc'.$i.'"]', 'Missing service operation action definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:input/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input for TestFunc'.$i.' body definition'); + foreach (array('', 2, 3, 4, 5, 6, 7, 9) as $i) { + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc' + . $i . '"]', + 'Missing service port definition for TestFunc' . $i . '' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc' + . $i . '"]/wsdl:documentation', + 'Missing service port definition documentation for TestFunc' + . $i . '' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc' + . $i . '"]/wsdl:input[@message="tns:TestFunc' . $i . 'In"]', + 'Missing service port definition input message for TestFunc' + . $i . '' + ); + + + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc' . $i . '"]/soap:operation[@soapAction="' + . $this->defaultServiceUri . '#TestFunc' . $i . '"]', + 'Missing service operation action definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/' + . 'wsdl:operation[@name="TestFunc' . $i . '"]/wsdl:input/soap:body' + . '[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' + . ' and @namespace="' . $this->defaultServiceUri . '"]', + 'Missing operation input for TestFunc' . $i . ' body definition' + ); if ($i != 2) { - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:output[@message="tns:TestFunc'.$i.'Out"]', 'Missing service port definition input message for TestFunc'.$i.''); - - - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]/wsdl:operation[@name="TestFunc'.$i.'"]/wsdl:output/soap:body[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" and @namespace="'.$this->defaultServiceUri.'"]', 'Missing operation input for TestFunc'.$i.' body definition'); - - - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFunc'.$i.'In"]', 'Missing test testFunc'.$i.' input message definition'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="TestFunc'.$i.'Out"]', 'Missing test testFunc'.$i.' input message definition'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:portType[@name="MyServicePort"]/wsdl:operation[@name="TestFunc' + . $i . '"]/wsdl:output[@message="tns:TestFunc' . $i + . 'Out"]', + 'Missing service port definition input message for TestFunc' + . $i . '' + ); + + + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:binding[@name="MyServiceBinding" and @type="tns:MyServicePort"]' + . '/wsdl:operation[@name="TestFunc'. $i . '"]/wsdl:output/soap:body' + . '[@use="encoded" and @encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' + . ' and @namespace="' . $this->defaultServiceUri . '"]', + 'Missing operation input for TestFunc' . $i + . ' body definition' + ); + + + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="TestFunc' . $i . 'In"]', + 'Missing test testFunc' . $i . ' input message definition' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="TestFunc' . $i . 'Out"]', + 'Missing test testFunc' . $i . ' input message definition' + ); } } @@ -622,16 +1183,20 @@ public function testAddFunctionMultiple() * * @dataProvider dataProviderValidUris */ - public function testChangeWsdlUriInConstructor($uri) + public function testChangeWsdlUriInConstructor($uri, $expectedUri) { $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); $this->server->setUri($uri); $this->bindWsdl($this->server->generate()); - $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); - $this->assertEquals($uri, $this->dom->documentElement->getAttribute('targetNamespace')); - $this->assertNotContains($this->defaultServiceUri, $this->dom->saveXML()); + $this->assertEquals( + $expectedUri, + $this->dom->documentElement->getAttribute('targetNamespace') + ); + $this->assertNotContains( + $this->defaultServiceUri, $this->dom->saveXML() + ); $this->assertValidWSDL($this->dom); @@ -643,9 +1208,10 @@ public function testSetNonStringNonZendUriUriThrowsException() $server = new AutoDiscover(); - $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', + $this->setExpectedException( + 'Zend\Soap\Exception\InvalidArgumentException', 'Argument to \Zend\Soap\AutoDiscover::setUri should be string ' - .'or \Zend\Uri\Uri instance.' + . 'or \Zend\Uri\Uri instance.' ); $server->setUri(array("bogus")); } @@ -654,17 +1220,18 @@ public function testSetNonStringNonZendUriUriThrowsException() * @group ZF-4117 * @dataProvider dataProviderValidUris */ - public function testChangingWsdlUriAfterGenerationIsPossible($uri) - { + public function testChangingWsdlUriAfterGenerationIsPossible( + $uri, $expectedUri + ) { $this->server->addFunction('\ZendTest\Soap\TestAsset\TestFunc'); $wsdl = $this->server->generate(); $wsdl->setUri($uri); - //@todo string retrieved this way contains decoded entities -// $this->assertEquals($uri, $wsdl->toDomDocument()->documentElement->getAttribute('targetNamespace')); - $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); - $this->assertContains($uri, $wsdl->toXML()); - $this->assertNotContains($this->defaultServiceUri, $wsdl->toXML()); + $this->assertEquals( + $expectedUri, $wsdl->toDomDocument()->documentElement->getAttribute( + 'targetNamespace' + ) + ); $this->assertValidWSDL($wsdl->toDomDocument()); $this->testDocumentNodes(); @@ -673,14 +1240,24 @@ public function testChangingWsdlUriAfterGenerationIsPossible($uri) /** * @return array */ - public function dataProviderValidUris() { + public function dataProviderValidUris() + { return array( - array('http://example.com/service.php'), - array('http://example.com/?a=b&b=c'), - array('http://example.com/?a=b&b=c'), - array('urn:uuid:550e8400-e29b-41d4-a716-446655440000'), - array('urn:acme:servicenamespace'), - array(new Uri('http://example.com/service.php')) + array('http://example.com/service.php', + 'http://example.com/service.php'), + array('http://example.com/?a=b&b=c', + 'http://example.com/?a=b&b=c'), + array('http://example.com/?a=b&b=c', + 'http://example.com/?a=b&b=c'), + array('urn:uuid:550e8400-e29b-41d4-a716-446655440000', + 'urn:uuid:550e8400-e29b-41d4-a716-446655440000'), + array('urn:acme:servicenamespace', 'urn:acme:servicenamespace'), + array(new Uri('http://example.com/service.php'), + 'http://example.com/service.php'), + array(new Uri('http://example.com/?a=b&b=c'), + 'http://example.com/?a=b&b=c'), + array(new Uri('http://example.com/?a=b&b=c'), + 'http://example.com/?a=b&b=c'), ); } @@ -689,14 +1266,21 @@ public function dataProviderValidUris() { * @group ZF-4125 * */ - public function testUsingClassWithMethodsWithMultipleDefaultParameterValues() + public function testUsingClassWithMethodsWithMultipleDefaultParameterValues( + ) { - $this->server->setClass('\ZendTest\Soap\TestAsset\TestFixingMultiplePrototypes'); + $this->server->setClass( + '\ZendTest\Soap\TestAsset\TestFixingMultiplePrototypes' + ); $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFuncIn"]'); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:message[@name="testFuncOut"]'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFuncIn"]' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:message[@name="testFuncOut"]' + ); $this->assertValidWSDL($this->dom); @@ -708,16 +1292,37 @@ public function testUsingClassWithMethodsWithMultipleDefaultParameterValues() */ public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce() { - $this->server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); - $this->server->setClass('\ZendTest\Soap\TestAsset\AutoDiscoverTestClass2'); + $this->server->setComplexTypeStrategy( + new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex + ); + $this->server->setClass( + '\ZendTest\Soap\TestAsset\AutoDiscoverTestClass2' + ); $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//xsd:attribute[@wsdl:arrayType="tns:AutoDiscoverTestClass1[]"]', 'Definition of TestClass1 has to occour once.'); - $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="AutoDiscoverTestClass1"]', 'AutoDiscoverTestClass1 has to be defined once.'); - $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfAutoDiscoverTestClass1"]', 'AutoDiscoverTestClass1 should be defined once.'); - $nodes = $this->assertSpecificNodeNumberInXPath(1, '//wsdl:part[@name="test" and @type="tns:AutoDiscoverTestClass1"]', 'AutoDiscoverTestClass1 appears once or more than once in the message parts section.'); - $this->assertTrue($nodes->length >= 1, 'AutoDiscoverTestClass1 appears once or more than once in the message parts section.'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//xsd:attribute[@wsdl:arrayType="tns:AutoDiscoverTestClass1[]"]', + 'Definition of TestClass1 has to occour once.' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//xsd:complexType[@name="AutoDiscoverTestClass1"]', + 'AutoDiscoverTestClass1 has to be defined once.' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//xsd:complexType[@name="ArrayOfAutoDiscoverTestClass1"]', + 'AutoDiscoverTestClass1 should be defined once.' + ); + $nodes = $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:part[@name="test" and @type="tns:AutoDiscoverTestClass1"]', + 'AutoDiscoverTestClass1 appears once or more than once in the message parts section.' + ); + $this->assertTrue( + $nodes->length >= 1, + 'AutoDiscoverTestClass1 appears once or more than once in the message parts section.' + ); $this->assertValidWSDL($this->dom); @@ -727,15 +1332,22 @@ public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce() /** * @group ZF-5604 */ - public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayComplex() + public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayComplex( + ) { - $this->server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); + $this->server->setComplexTypeStrategy( + new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex + ); $this->server->setClass('\ZendTest\Soap\TestAsset\MyService'); $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfMyResponse"]'); - $this->assertSpecificNodeNumberInXPath(0, '//wsdl:part[@type="tns:My_Response[]"]'); + $this->assertSpecificNodeNumberInXPath( + 1, '//xsd:complexType[@name="ArrayOfMyResponse"]' + ); + $this->assertSpecificNodeNumberInXPath( + 0, '//wsdl:part[@type="tns:My_Response[]"]' + ); $this->assertValidWSDL($this->dom); @@ -745,16 +1357,25 @@ public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayC /** * @group ZF-5430 */ - public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArraySequence() + public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArraySequence( + ) { - $this->server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); + $this->server->setComplexTypeStrategy( + new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence + ); $this->server->setClass('\ZendTest\Soap\TestAsset\MyServiceSequence'); $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfString"]'); - $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfArrayOfString"]'); - $this->assertSpecificNodeNumberInXPath(1, '//xsd:complexType[@name="ArrayOfArrayOfArrayOfString"]'); + $this->assertSpecificNodeNumberInXPath( + 1, '//xsd:complexType[@name="ArrayOfString"]' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//xsd:complexType[@name="ArrayOfArrayOfString"]' + ); + $this->assertSpecificNodeNumberInXPath( + 1, '//xsd:complexType[@name="ArrayOfArrayOfArrayOfString"]' + ); $this->assertNotContains('tns:string[]', $this->dom->saveXML()); @@ -773,8 +1394,12 @@ public function testNoReturnIsOneWayCallInSetClass() $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType/wsdl:operation[@name="pushOneWay"]/wsdl:input'); - $this->assertSpecificNodeNumberInXPath(0, '//wsdl:portType/wsdl:operation[@name="pushOneWay"]/wsdl:output'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:portType/wsdl:operation[@name="pushOneWay"]/wsdl:input' + ); + $this->assertSpecificNodeNumberInXPath( + 0, '//wsdl:portType/wsdl:operation[@name="pushOneWay"]/wsdl:output' + ); $this->assertValidWSDL($this->dom); @@ -790,8 +1415,12 @@ public function testNoReturnIsOneWayCallInAddFunction() $this->bindWsdl($this->server->generate()); - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:portType/wsdl:operation[@name="OneWay"]/wsdl:input'); - $this->assertSpecificNodeNumberInXPath(0, '//wsdl:portType/wsdl:operation[@name="OneWay"]/wsdl:output'); + $this->assertSpecificNodeNumberInXPath( + 1, '//wsdl:portType/wsdl:operation[@name="OneWay"]/wsdl:input' + ); + $this->assertSpecificNodeNumberInXPath( + 0, '//wsdl:portType/wsdl:operation[@name="OneWay"]/wsdl:output' + ); $this->assertValidWSDL($this->dom); @@ -804,7 +1433,9 @@ public function testNoReturnIsOneWayCallInAddFunction() */ public function testRecursiveWsdlDependencies() { - $this->server->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); + $this->server->setComplexTypeStrategy( + new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence + ); $this->server->setClass('\ZendTest\Soap\TestAsset\Recursion'); $this->bindWsdl($this->server->generate()); @@ -815,7 +1446,11 @@ public function testRecursiveWsdlDependencies() // // // - $this->assertSpecificNodeNumberInXPath(1, '//wsdl:types/xsd:schema/xsd:complexType[@name="Recursion"]/xsd:all/xsd:element[@name="recursion" and @type="tns:Recursion"]'); + $this->assertSpecificNodeNumberInXPath( + 1, + '//wsdl:types/xsd:schema/xsd:complexType[@name="Recursion"]/xsd:all/' + . 'xsd:element[@name="recursion" and @type="tns:Recursion"]' + ); $this->assertValidWSDL($this->dom); @@ -823,9 +1458,10 @@ public function testRecursiveWsdlDependencies() } /** - * @param int $n + * @param int $n * @param string $xpath * @param string $msg + * * @return \DOMNodeList */ public function assertSpecificNodeNumberInXPath($n, $xpath, $msg = null) @@ -835,7 +1471,7 @@ public function assertSpecificNodeNumberInXPath($n, $xpath, $msg = null) if (!($nodes instanceof \DOMNodeList)) { $this->fail('Nodes not found. Invalid XPath expression ?'); } - $this->assertEquals($n, $nodes->length, $msg); + $this->assertEquals($n, $nodes->length, $msg . "\nXPath: " . $xpath); return $nodes; } @@ -847,9 +1483,12 @@ public function assertAttributesOfNodes($attributes, $nodeList) $keys = array_keys($attributes); - foreach($nodeList as $node) { - for($i = 0; $i < $c; $i++) { - $this->assertEquals($attributes[$keys[$i]], $node->getAttribute($keys[$i]), 'Invalid attribute value.'); + foreach ($nodeList as $node) { + for ($i = 0; $i < $c; $i++) { + $this->assertEquals( + $attributes[$keys[$i]], $node->getAttribute($keys[$i]), + 'Invalid attribute value.' + ); } } } diff --git a/test/ClientTest.php b/test/ClientTest.php index f068a69c..c4305336 100755 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -589,7 +589,8 @@ public function testSetSoapClient() * @expectedException \Zend\Soap\Exception\UnexpectedValueException * @dataProvider dataProviderForInitSoapClientObjectException */ - public function testInitSoapClientObjectException($wsdl, $options){ + public function testInitSoapClientObjectException($wsdl, $options) + { $client = new Client($wsdl, $options); $client->getSoapClient(); } @@ -597,7 +598,8 @@ public function testInitSoapClientObjectException($wsdl, $options){ /** * @return array */ - public function dataProviderForInitSoapClientObjectException() { + public function dataProviderForInitSoapClientObjectException() + { return array( array(null, array()), array(null, array('location'=>'http://example.com')), diff --git a/test/ServerTest.php b/test/ServerTest.php index 77329f19..d8b87d9b 100755 --- a/test/ServerTest.php +++ b/test/ServerTest.php @@ -692,7 +692,8 @@ public function testDeregisterFaultException($exception) * * @param string|array $exception */ - public function testIsRegisteredAsFaultException($exception) { + public function testIsRegisteredAsFaultException($exception) + { $server = new Server(); $server->registerFaultException($exception); @@ -808,6 +809,7 @@ public function testHandlePhpErrors() $client = new \Zend\Soap\Client\Local($server, $wsdlFilename); $client->triggerError(); + unlink($wsdlFilename); } public function testLoadFunctionsIsNotImplemented() diff --git a/test/TestAsset/commontypes.php b/test/TestAsset/commontypes.php index 23237ec6..f18adc90 100755 --- a/test/TestAsset/commontypes.php +++ b/test/TestAsset/commontypes.php @@ -688,7 +688,8 @@ class PublicPrivateProtected class errorClass { - public function triggerError() { - trigger_error('TestError', E_USER_ERROR); + public function triggerError() + { + trigger_error('TestError', E_USER_ERROR); } } diff --git a/test/TestAsset/testHandlePhpErrors.wsdl b/test/TestAsset/testHandlePhpErrors.wsdl new file mode 100644 index 00000000..b44c6037 --- /dev/null +++ b/test/TestAsset/testHandlePhpErrors.wsdl @@ -0,0 +1,33 @@ + + + + + + + + + + + + triggerError + + + + + + + + + + + + + + + + + + + + + diff --git a/test/Wsdl/ArrayOfTypeComplexStrategyTest.php b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php index 793b20e5..d104eec0 100755 --- a/test/Wsdl/ArrayOfTypeComplexStrategyTest.php +++ b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php @@ -35,13 +35,17 @@ public function setUp() public function testNestingObjectsDeepMakesNoSenseThrowingException() { - $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than one level'); + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', + 'ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than one level' + ); $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexTest[][]'); } public function testAddComplexTypeOfNonExistingClassThrowsException() { - $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Cannot add a complex type \ZendTest\Soap\TestAsset\UnknownClass that is not an object or where class'); + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', + 'Cannot add a complex type \ZendTest\Soap\TestAsset\UnknownClass that is not an object or where class' + ); $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\UnknownClass[]'); } @@ -62,14 +66,22 @@ public function testArrayOfSimpleObject() $this->assertEquals('xsd:int', $nodes->item(0)->getAttribute('type'), 'Invalid type name'); // array of elements - $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexTest"]/xsd:complexContent/xsd:restriction'); + $nodes = $this->xpath->query( + '//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexTest"]/xsd:complexContent/xsd:restriction' + ); $this->assertEquals(1, $nodes->length, 'Unable to find complex type array definition in wsdl.'); - $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), 'Invalid base encoding in complex type.'); + $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), + 'Invalid base encoding in complex type.' + ); $nodes = $this->xpath->query('xsd:attribute', $nodes->item(0)); - $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.'); - $this->assertEquals('tns:ComplexTest[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), 'Invalid array type reference.'); + $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), + 'Invalid attribute reference value in complex type.' + ); + $this->assertEquals('tns:ComplexTest[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), + 'Invalid array type reference.' + ); $this->testDocumentNodes(); } @@ -88,7 +100,9 @@ public function testArrayOfComplexObjects() $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectStructure[]'); $this->assertEquals("tns:ArrayOfComplexObjectStructure", $return); - $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="ComplexObjectStructure"]/xsd:all'); + $nodes = $this->xpath->query( + '//wsdl:types/xsd:schema/xsd:complexType[@name="ComplexObjectStructure"]/xsd:all' + ); $this->assertEquals(4, $nodes->item(0)->childNodes->length, 'Invalid complex object definition.'); foreach (array( @@ -98,19 +112,32 @@ public function testArrayOfComplexObjects() 'array' => 'soap-enc:Array' ) as $name => $type) { $node = $this->xpath->query('xsd:element[@name="'.$name.'"]', $nodes->item(0)); - $this->assertEquals($name, $node->item(0)->getAttribute('name'), 'Invalid name attribute value in complex object definition'); - $this->assertEquals($type, $node->item(0)->getAttribute('type'), 'Invalid type name in complex object definition'); + $this->assertEquals($name, $node->item(0)->getAttribute('name'), + 'Invalid name attribute value in complex object definition' + ); + $this->assertEquals($type, $node->item(0)->getAttribute('type'), + 'Invalid type name in complex object definition' + ); } // array of elements - $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexObjectStructure"]/xsd:complexContent/xsd:restriction'); + $nodes = $this->xpath->query( + '//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexObjectStructure"]/xsd:complexContent/xsd:restriction' + ); $this->assertEquals(1, $nodes->length, 'Unable to find complex type array definition in wsdl.'); - $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), 'Invalid base encoding in complex type.'); + $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), + 'Invalid base encoding in complex type.' + ); $nodes = $this->xpath->query('xsd:attribute', $nodes->item(0)); - $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.'); - $this->assertEquals('tns:ComplexObjectStructure[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), 'Invalid array type reference.'); + $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), + 'Invalid attribute reference value in complex type.' + ); + $this->assertEquals('tns:ComplexObjectStructure[]', + $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), + 'Invalid array type reference.' + ); $this->testDocumentNodes(); @@ -129,22 +156,40 @@ public function testArrayOfObjectWithObject() $this->assertEquals('xsd:int', $nodes->item(0)->getAttribute('type'), 'Invalid type name'); // single object element - $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ComplexObjectWithObjectStructure"]/xsd:all/xsd:element'); + $nodes = $this->xpath->query( + '//wsdl:types/*/xsd:complexType[@name="ComplexObjectWithObjectStructure"]/xsd:all/xsd:element' + ); $this->assertEquals(1, $nodes->length, 'Unable to find complex object in wsdl.'); - $this->assertEquals('object', $nodes->item(0)->getAttribute('name'), 'Invalid attribute name'); - $this->assertEquals('tns:ComplexTest', $nodes->item(0)->getAttribute('type'), 'Invalid type name'); - $this->assertEquals('true', $nodes->item(0)->getAttribute('nillable'), 'Invalid nillable attribute value'); + $this->assertEquals('object', $nodes->item(0)->getAttribute('name'), + 'Invalid attribute name' + ); + $this->assertEquals('tns:ComplexTest', $nodes->item(0)->getAttribute('type'), + 'Invalid type name' + ); + $this->assertEquals('true', $nodes->item(0)->getAttribute('nillable'), + 'Invalid nillable attribute value' + ); // array of elements - $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]/xsd:complexContent/xsd:restriction'); + $nodes = $this->xpath->query( + '//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]/' + .'xsd:complexContent/xsd:restriction' + ); $this->assertEquals(1, $nodes->length, 'Unable to find complex type array definition in wsdl.'); - $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), 'Invalid base encoding in complex type.'); + $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), + 'Invalid base encoding in complex type.' + ); $nodes = $this->xpath->query('xsd:attribute', $nodes->item(0)); - $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.'); - $this->assertEquals('tns:ComplexObjectWithObjectStructure[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), 'Invalid array type reference.'); + $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), + 'Invalid attribute reference value in complex type.' + ); + $this->assertEquals('tns:ComplexObjectWithObjectStructure[]', + $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), + 'Invalid array type reference.' + ); $this->testDocumentNodes(); } @@ -154,14 +199,20 @@ public function testArrayOfObjectWithObject() */ public function testAddingTypesMultipleTimesIsSavedOnlyOnce() { - $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); - $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); // this xpath is proper version of simpler: //*[wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"] - namespaces in attributes and xpath - $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::NS_WSDL.'" and local-name()="arrayType"]="tns:ComplexObjectWithObjectStructure[]"]'); - $this->assertEquals(1, $nodes->length, 'Invalid array of complex type array type reference detected'); - - $nodes = $this->xpath->query('//xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]'); + $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::NS_WSDL + .'" and local-name()="arrayType"]="tns:ComplexObjectWithObjectStructure[]"]' + ); + $this->assertEquals(1, $nodes->length, + 'Invalid array of complex type array type reference detected' + ); + + $nodes = $this->xpath->query( + '//xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]' + ); $this->assertEquals(1, $nodes->length, 'Invalid array complex type detected'); $nodes = $this->xpath->query('//xsd:complexType[@name="ComplexTest"]'); @@ -175,14 +226,20 @@ public function testAddingTypesMultipleTimesIsSavedOnlyOnce() */ public function testAddingSingularThenArrayTypeIsRecognizedCorretly() { - $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure'); - $return = $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure'); + $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); // this xpath is proper version of simpler: //*[wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"] - namespaces in attributes and xpath - $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::NS_WSDL.'" and local-name()="arrayType"]="tns:ComplexObjectWithObjectStructure[]"]'); - $this->assertEquals(1, $nodes->length, 'Invalid array of complex type array type reference detected'); - - $nodes = $this->xpath->query('//xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]'); + $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::NS_WSDL. + '" and local-name()="arrayType"]="tns:ComplexObjectWithObjectStructure[]"]' + ); + $this->assertEquals(1, $nodes->length, + 'Invalid array of complex type array type reference detected' + ); + + $nodes = $this->xpath->query( + '//xsd:complexType[@name="ArrayOfComplexObjectWithObjectStructure"]' + ); $this->assertEquals(1, $nodes->length, 'Invalid array complex type detected'); $nodes = $this->xpath->query('//xsd:complexType[@name="ComplexTest"]'); @@ -208,27 +265,51 @@ public function testArrayOfComplexNestedObjectsIsCoveredByStrategyAndAddsAllType 'foo' => 'xsd:string', ) as $name => $type) { $node = $this->xpath->query('xsd:element[@name="'.$name.'"]', $nodes->item(0)); - $this->assertEquals($name, $node->item(0)->getAttribute('name'), 'Invalid name attribute value in complex object definition'); - $this->assertEquals($type, $node->item(0)->getAttribute('type'), 'Invalid type name in complex object definition'); - $this->assertEquals('true', $node->item(0)->getAttribute('nillable'), 'Invalid nillable attribute value'); + $this->assertEquals($name, $node->item(0)->getAttribute('name'), + 'Invalid name attribute value in complex object definition' + ); + $this->assertEquals($type, $node->item(0)->getAttribute('type'), + 'Invalid type name in complex object definition' + ); + $this->assertEquals('true', $node->item(0)->getAttribute('nillable'), + 'Invalid nillable attribute value' + ); } // single object element - $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ComplexTypeA"]/xsd:all/xsd:element'); + $nodes = $this->xpath->query( + '//wsdl:types/*/xsd:complexType[@name="ComplexTypeA"]/xsd:all/xsd:element' + ); $this->assertEquals(1, $nodes->length, 'Unable to find complex object in wsdl.'); - $this->assertEquals('baz', $nodes->item(0)->getAttribute('name'), 'Invalid attribute name'); - $this->assertEquals('tns:ArrayOfComplexTypeB', $nodes->item(0)->getAttribute('type'), 'Invalid type name'); + $this->assertEquals('baz', + $nodes->item(0)->getAttribute('name'), 'Invalid attribute name' + ); + $this->assertEquals('tns:ArrayOfComplexTypeB', + $nodes->item(0)->getAttribute('type'), 'Invalid type name' + ); // array of elements - $nodes = $this->xpath->query('//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexTypeB"]/xsd:complexContent/xsd:restriction'); - $this->assertEquals(1, $nodes->length, 'Unable to find complex type array definition in wsdl.'); - $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), 'Invalid base encoding in complex type.'); + $nodes = $this->xpath->query( + '//wsdl:types/*/xsd:complexType[@name="ArrayOfComplexTypeB"]/xsd:complexContent/xsd:restriction' + ); + $this->assertEquals(1, $nodes->length, + 'Unable to find complex type array definition in wsdl.' + ); + $this->assertEquals('soap-enc:Array', $nodes->item(0)->getAttribute('base'), + 'Invalid base encoding in complex type.' + ); $nodes = $this->xpath->query('xsd:attribute', $nodes->item(0)); - $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.'); - $this->assertEquals('tns:ComplexTypeB[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), 'Invalid array type reference.'); + $this->assertEquals('soap-enc:arrayType', + $nodes->item(0)->getAttribute('ref'), + 'Invalid attribute reference value in complex type.' + ); + $this->assertEquals('tns:ComplexTypeB[]', + $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), + 'Invalid array type reference.' + ); $this->testDocumentNodes(); } diff --git a/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php index 8079691b..c5f052d2 100755 --- a/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php +++ b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php @@ -48,10 +48,18 @@ public function testFunctionReturningSimpleArrayOfBasicTypes($type, $arrayTypeNa $nodes = $this->xpath->query('xsd:sequence/xsd:element', $nodes->item(0)); $this->assertEquals(1, $nodes->length, 'Missing complex type element declaration'); - $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), 'Wrong complex type element name attribute'); - $this->assertEquals('xsd:'.$type, $nodes->item(0)->getAttribute('type'), 'Wrong complex type type attribute value'); - $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), 'Wrong complex type minOccurs attribute value'); - $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), 'Wrong complex type maxOccurs attribute value'); + $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), + 'Wrong complex type element name attribute' + ); + $this->assertEquals('xsd:'.$type, $nodes->item(0)->getAttribute('type'), + 'Wrong complex type type attribute value' + ); + $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), + 'Wrong complex type minOccurs attribute value' + ); + $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), + 'Wrong complex type maxOccurs attribute value' + ); $this->testDocumentNodes(); } @@ -85,10 +93,18 @@ public function testNestedTypesDefinitions($stringDefinition, $definedTypeName, $nodes = $this->xpath->query('xsd:sequence/xsd:element', $nodes->item(0)); $this->assertEquals(1, $nodes->length, 'Invalid element in first level of nested element definition'); - $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), 'Wrong complex type element name attribute'); - $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), 'Wrong complex type minOccurs attribute value'); - $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), 'Wrong complex type maxOccurs attribute value'); - $this->assertEquals($typeName, $nodes->item(0)->getAttribute('type'), 'Wrong complex type type attribute value'); + $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), + 'Wrong complex type element name attribute' + ); + $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), + 'Wrong complex type minOccurs attribute value' + ); + $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), + 'Wrong complex type maxOccurs attribute value' + ); + $this->assertEquals($typeName, $nodes->item(0)->getAttribute('type'), + 'Wrong complex type type attribute value' + ); } $this->testDocumentNodes(); @@ -172,8 +188,12 @@ public function testAddComplexTypeArrayOfObject() $this->assertEquals(1, $nodes->length, 'Missing complex type element declaration'); - $this->assertEquals('baz', $nodes->item(0)->getAttribute('name'), 'Wrong complex type element name attribute'); - $this->assertEquals('tns:ArrayOfComplexTypeB', $nodes->item(0)->getAttribute('type'), 'Wrong complex type type attribute value'); + $this->assertEquals('baz', $nodes->item(0)->getAttribute('name'), + 'Wrong complex type element name attribute' + ); + $this->assertEquals('tns:ArrayOfComplexTypeB', $nodes->item(0)->getAttribute('type'), + 'Wrong complex type type attribute value' + ); // class b @@ -186,9 +206,15 @@ public function testAddComplexTypeArrayOfObject() ) as $name => $type) { $node = $this->xpath->query('xsd:all/xsd:element[@name="'.$name.'"]', $nodes->item(0)); - $this->assertEquals($name, $node->item(0)->getAttribute('name'), 'Invalid name attribute value in complex object definition'); - $this->assertEquals($type, $node->item(0)->getAttribute('type'), 'Invalid type name in complex object definition'); - $this->assertEquals('true', $node->item(0)->getAttribute('nillable'), 'Invalid nillable attribute value'); + $this->assertEquals($name, $node->item(0)->getAttribute('name'), + 'Invalid name attribute value in complex object definition' + ); + $this->assertEquals($type, $node->item(0)->getAttribute('type'), + 'Invalid type name in complex object definition' + ); + $this->assertEquals('true', $node->item(0)->getAttribute('nillable'), + 'Invalid nillable attribute value' + ); } @@ -198,16 +224,26 @@ public function testAddComplexTypeArrayOfObject() 'ArrayOfComplexTypeA' => 'ComplexTypeA' ) as $arrayTypeName => $typeName) { - $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="'.$arrayTypeName.'"]'); + $nodes = $this->xpath->query( + '//wsdl:types/xsd:schema/xsd:complexType[@name="'.$arrayTypeName.'"]' + ); $this->assertEquals(1, $nodes->length, 'Missing complex type definition.'); $nodes = $this->xpath->query('xsd:sequence/xsd:element', $nodes->item(0)); $this->assertEquals(1, $nodes->length, 'Missing complex type element declaration'); - $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), 'Wrong complex type element name attribute'); - $this->assertEquals('tns:'.$typeName, $nodes->item(0)->getAttribute('type'), 'Wrong complex type type attribute value'); - $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), 'Wrong complex type minOccurs attribute value'); - $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), 'Wrong complex type maxOccurs attribute value'); + $this->assertEquals('item', $nodes->item(0)->getAttribute('name'), + 'Wrong complex type element name attribute' + ); + $this->assertEquals('tns:'.$typeName, $nodes->item(0)->getAttribute('type'), + 'Wrong complex type type attribute value' + ); + $this->assertEquals('0', $nodes->item(0)->getAttribute('minOccurs'), + 'Wrong complex type minOccurs attribute value' + ); + $this->assertEquals('unbounded', $nodes->item(0)->getAttribute('maxOccurs'), + 'Wrong complex type maxOccurs attribute value' + ); } $this->testDocumentNodes(); diff --git a/test/Wsdl/CompositeStrategyTest.php b/test/Wsdl/CompositeStrategyTest.php index 94224fe7..4092703d 100755 --- a/test/Wsdl/CompositeStrategyTest.php +++ b/test/Wsdl/CompositeStrategyTest.php @@ -56,7 +56,9 @@ public function testConstructorTypeMapSyntax() { $typeMap = array('Book' => '\Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex'); - $strategy = new ComplexTypeStrategy\Composite($typeMap, new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence); + $strategy = new ComplexTypeStrategy\Composite($typeMap, + new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence + ); $bookStrategy = $strategy->getStrategyOfType('Book'); $cookieStrategy = $strategy->getStrategyOfType('Cookie'); @@ -69,7 +71,9 @@ public function testCompositeThrowsExceptionOnInvalidType() { $strategy = new ComplexTypeStrategy\Composite(); - $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Invalid type given to Composite Type Map'); + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', + 'Invalid type given to Composite Type Map' + ); $strategy->connectTypeToStrategy(array(), 'strategy'); } @@ -78,8 +82,10 @@ public function testCompositeThrowsExceptionOnInvalidStrategy() $strategy = new ComplexTypeStrategy\Composite(array(), 'invalid'); $strategy->connectTypeToStrategy('Book', 'strategy'); - $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Strategy for Complex Type \'Book\' is not a valid strategy'); - $book = $strategy->getStrategyOfType('Book'); + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', + 'Strategy for Complex Type \'Book\' is not a valid strategy' + ); + $strategy->getStrategyOfType('Book'); } public function testCompositeThrowsExceptionOnInvalidStrategyPart2() @@ -87,15 +93,21 @@ public function testCompositeThrowsExceptionOnInvalidStrategyPart2() $strategy = new ComplexTypeStrategy\Composite(array(), 'invalid'); $strategy->connectTypeToStrategy('Book', 'strategy'); - $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Default Strategy for Complex Types is not a valid strategy object'); - $book = $strategy->getStrategyOfType('Anything'); + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', + 'Default Strategy for Complex Types is not a valid strategy object' + ); + $strategy->getStrategyOfType('Anything'); } public function testCompositeDelegatesAddingComplexTypesToSubStrategies() { $this->strategy = new ComplexTypeStrategy\Composite(array(), new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); - $this->strategy->connectTypeToStrategy('\ZendTest\Soap\TestAsset\Book', new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex); - $this->strategy->connectTypeToStrategy('\ZendTest\Soap\TestAsset\Cookie', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); + $this->strategy->connectTypeToStrategy('\ZendTest\Soap\TestAsset\Book', + new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex + ); + $this->strategy->connectTypeToStrategy('\ZendTest\Soap\TestAsset\Cookie', + new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType + ); parent::setUp(); diff --git a/test/WsdlTest.php b/test/WsdlTest.php index a6e4f4a5..255d23a2 100755 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -30,6 +30,7 @@ function testConstructor() { $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri(null)); $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); + $this->assertEquals(Wsdl::NS_SOAP12, $this->dom->lookupNamespaceUri('soap12')); $this->assertEquals($this->defaultServiceUri, $this->dom->lookupNamespaceUri('tns')); $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); $this->assertEquals(Wsdl::NS_SCHEMA, $this->dom->lookupNamespaceUri('xsd')); @@ -49,7 +50,7 @@ function testConstructor() * * @param string $uri */ - public function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes($uri) + public function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes($uri, $expectedUri) { if ($uri instanceof Uri) { $uri = $uri->toString(); @@ -57,14 +58,10 @@ public function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAt $this->wsdl->setUri($uri); - $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); - $this->assertEquals($uri, $this->dom->lookupNamespaceUri('tns')); - - //@todo string retrieved this way contains decoded entities -// $this->assertEquals($uri, $this->dom->documentElement->getAttribute('targetNamespace')); - $this->assertContains($uri, $this->wsdl->toXML()); - $this->testDocumentNodes(); + + $this->assertEquals($expectedUri, $this->dom->lookupNamespaceUri('tns')); + $this->assertEquals($expectedUri, $this->dom->documentElement->getAttribute('targetNamespace')); } /** @@ -72,18 +69,14 @@ public function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAt * * @param string $uri */ - public function testSetUriWithZendUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes($uri) + public function testSetUriWithZendUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes($uri, $expectedUri) { $this->wsdl->setUri(new Uri($uri)); + $this->testDocumentNodes(); - $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); - $this->assertEquals($uri, $this->dom->lookupNamespaceUri('tns')); - - //@todo string retrieved this way contains decoded entities -// $this->assertEquals($uri, $this->dom->documentElement->getAttribute('targetNamespace')); - $this->assertContains($uri, $this->wsdl->toXML()); + $this->assertEquals($expectedUri, $this->dom->lookupNamespaceUri('tns')); + $this->assertEquals($expectedUri, $this->dom->documentElement->getAttribute('targetNamespace')); - $this->testDocumentNodes(); } /** @@ -91,17 +84,16 @@ public function testSetUriWithZendUriChangesDomDocumentWsdlStructureTnsAndTarget * * @param string $uri */ - public function testObjectConstructionWithDifferentURI($uri) + public function testObjectConstructionWithDifferentURI($uri, $expectedUri) { $wsdl = new Wsdl($this->defaultServiceName, $uri); $dom = $this->registerNamespaces($wsdl->toDomDocument(), $uri); + $this->testDocumentNodes(); - $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); - $this->assertEquals($uri, $dom->lookupNamespaceUri('tns')); - $this->assertEquals($uri, $dom->documentElement->getAttribute('targetNamespace')); + $this->assertEquals($expectedUri, $dom->lookupNamespaceUri('tns')); + $this->assertEquals($expectedUri, $dom->documentElement->getAttribute('targetNamespace')); - $this->testDocumentNodes(); } /** @@ -112,18 +104,18 @@ public function testObjectConstructionWithDifferentURI($uri) public function dataProviderForURITesting() { return array( - array('http://localhost/MyService.php'), - array('http://localhost/MyNewService.php'), - array(new Uri('http://localhost/MyService.php')), + array('http://localhost/MyService.php', 'http://localhost/MyService.php'), + array('http://localhost/MyNewService.php', 'http://localhost/MyNewService.php'), + array(new Uri('http://localhost/MyService.php'), 'http://localhost/MyService.php'), /** * @bug ZF-5736 */ - array('http://localhost/MyService.php?a=b&b=c'), + array('http://localhost/MyService.php?a=b&b=c', 'http://localhost/MyService.php?a=b&b=c'), /** * @bug ZF-5736 */ - array('http://localhost/MyService.php?a=b&b=c'), + array('http://localhost/MyService.php?a=b&b=c', 'http://localhost/MyService.php?a=b&b=c'), ); } @@ -142,6 +134,7 @@ function testAddMessage($parameters) $messageName = 'myMessage'; $this->wsdl->addMessage($messageName, $messageParts); + $this->testDocumentNodes(); $messageNodes = $this->xpath->query('//wsdl:definitions/wsdl:message'); @@ -154,7 +147,6 @@ function testAddMessage($parameters) $this->assertEquals($parameterType, $part->item(0)->getAttribute('type')); } - $this->testDocumentNodes(); } /** @@ -175,6 +167,7 @@ public function testAddComplexMessage($parameters) $messageName = 'myMessage'; $this->wsdl->addMessage($messageName, $messageParts); + $this->testDocumentNodes(); $messageNodes = $this->xpath->query('//wsdl:definitions/wsdl:message'); @@ -186,7 +179,6 @@ public function testAddComplexMessage($parameters) $this->assertEquals($parameterDefinition['name'], $part->item(0)->getAttribute('name')); } - $this->testDocumentNodes(); } /** @@ -208,14 +200,14 @@ function testAddPortType() $portName = 'myPortType'; $this->wsdl->addPortType($portName); + $this->testDocumentNodes(); + $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType'); $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); $this->assertTrue($portTypeNodes->item(0)->hasAttribute('name')); $this->assertEquals($portName, $portTypeNodes->item(0)->getAttribute('name')); - - $this->testDocumentNodes(); } /** @@ -230,10 +222,11 @@ function testAddPortOperation($operationName, $inputRequest = null, $outputRespo $this->wsdl->addPortOperation($portType, $operationName, $inputRequest, $outputResponse, $fail); + $this->testDocumentNodes(); + $portTypeNodes = $this->xpath->query('//wsdl:definitions/wsdl:portType[@name="'.$portName.'"]'); $this->assertGreaterThan(0, $portTypeNodes->length, 'Missing portType node in definitions node.'); - $operationNodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $portTypeNodes->item(0)); $this->assertGreaterThan(0, $operationNodes->length); @@ -257,8 +250,6 @@ function testAddPortOperation($operationName, $inputRequest = null, $outputRespo $faultNodes = $operationNodes->item(0)->getElementsByTagName('fault'); $this->assertEquals($fail, $faultNodes->item(0)->getAttribute('message')); } - - $this->testDocumentNodes(); } /** @@ -280,7 +271,8 @@ function dataProviderForAddPortOperation() function testAddBinding() { $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $this->wsdl->toDomDocument()->formatOutput = true; + + $this->testDocumentNodes(); $bindingNodes = $this->xpath->query('//wsdl:definitions/wsdl:binding'); @@ -291,7 +283,6 @@ function testAddBinding() $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttribute('name')); $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttribute('type')); - $this->testDocumentNodes(); } /** @@ -335,6 +326,8 @@ function testAddBindingOperation($operationName, $faultArray ); + $this->testDocumentNodes(); + $bindingNodes = $this->xpath->query('//wsdl:binding'); $this->assertGreaterThan(0, $bindingNodes->length, 'Missing binding node in definition.'); @@ -366,8 +359,6 @@ function testAddBindingOperation($operationName, } } } - - $this->testDocumentNodes(); } /** @@ -400,13 +391,12 @@ function testAddSoapBinding($style) $this->wsdl->addSoapBinding($binding, $style); + $this->testDocumentNodes(); - $nodes = $this->xpath->query('//soap:binding'); + $nodes = $this->xpath->query('//soap:binding'); $this->assertGreaterThan(0, $nodes->length); $this->assertEquals($style, $nodes->item(0)->getAttribute('style')); - - $this->testDocumentNodes(); } public function dataProviderForSoapBindingStyle() @@ -427,11 +417,11 @@ function testAddSoapOperation($operationUrl) $this->wsdl->addSoapOperation($binding, $operationUrl); + $this->testDocumentNodes(); + $node = $this->xpath->query('//soap:operation'); $this->assertGreaterThan(0, $node->length); $this->assertEquals($operationUrl, $node->item(0)->getAttribute('soapAction')); - - $this->testDocumentNodes(); } public function dataProviderForAddSoapOperation() @@ -452,14 +442,17 @@ function testAddService($serviceUrl) $this->wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', $serviceUrl); + $this->testDocumentNodes(); + $nodes = $this->xpath->query('//wsdl:service[@name="Service1"]/wsdl:port/soap:address'); $this->assertGreaterThan(0, $nodes->length); $this->assertEquals($serviceUrl, $nodes->item(0)->getAttribute('location')); - - $this->testDocumentNodes(); } + /** + * @return array + */ public function dataProviderForAddService() { return array( @@ -468,16 +461,96 @@ public function dataProviderForAddService() ); } + /** + * @dataProvider ampersandInUrlDataProvider + */ + public function testAddBindingOperationWithAmpersandInUrl($actualUrl, $expectedUrl) + { + + $this->wsdl->addPortType('myPortType'); + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + + $this->wsdl->addBindingOperation( + $binding, + 'operation1', + array('use' => 'encoded', 'encodingStyle' => $actualUrl), + array('use' => 'encoded', 'encodingStyle' => $actualUrl), + array('name' => 'MyFault','use' => 'encoded', 'encodingStyle' => $actualUrl) + ); + + $nodes = $this->xpath->query('//wsdl:binding[@type="myPortType" and @name="MyServiceBinding"]/wsdl:operation[@name="operation1"]/wsdl:input/soap:body'); + + $this->assertGreaterThanOrEqual(1, $nodes->length); + $this->assertEquals($expectedUrl, $nodes->item(0)->getAttribute('encodingStyle')); + } + + /** + * @dataProvider ampersandInUrlDataProvider() + */ + public function testAddSoapOperationWithAmpersandInUrl($actualUrl, $expectedUrl) + { + $this->wsdl->addPortType('myPortType'); + $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + + $this->wsdl->addSoapOperation($binding, $actualUrl); + + $this->testDocumentNodes(); + + $nodes = $this->xpath->query('//wsdl:binding/soap:operation'); + $this->assertGreaterThanOrEqual(1, $nodes->length); + $this->assertEquals($expectedUrl, $nodes->item(0)->getAttribute('soapAction')); + } + + /** + * @dataProvider ampersandInUrlDataProvider() + */ + public function testAddServiceWithAmpersandInUrl($actualUrl, $expectedUrl) + { + $this->wsdl->addPortType('myPortType'); + $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); + + $this->wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', $actualUrl); + + $this->testDocumentNodes(); + + $nodes = $this->xpath->query('//wsdl:port/soap:address'); + $this->assertGreaterThanOrEqual(1, $nodes->length); + $this->assertEquals($expectedUrl, $nodes->item(0)->getAttribute('location')); + } + + public function ampersandInUrlDataProvider() + { + return array( + 'Decoded ampersand' => array( + 'http://localhost/MyService.php?foo=bar&baz=qux', + 'http://localhost/MyService.php?foo=bar&baz=qux', + ), + 'Encoded ampersand' => array( + 'http://localhost/MyService.php?foo=bar&baz=qux', + 'http://localhost/MyService.php?foo=bar&baz=qux', + ), + 'Encoded and decoded ampersand' => array( + 'http://localhost/MyService.php?foo=bar&&baz=qux', + 'http://localhost/MyService.php?foo=bar&&baz=qux', + ), + ); + } + + + /** + * + */ function testAddDocumentation() { $doc = 'This is a description for Port Type node.'; $this->wsdl->addDocumentation($this->wsdl, $doc); + $this->testDocumentNodes(); + $nodes = $this->wsdl->toDomDocument()->childNodes; $this->assertEquals(1, $nodes->length); $this->assertEquals($doc, $nodes->item(0)->nodeValue); - $this->testDocumentNodes(); } function testAddDocumentationToSomeElmenet() @@ -487,11 +560,11 @@ function testAddDocumentationToSomeElmenet() $doc = 'This is a description for Port Type node.'; $this->wsdl->addDocumentation($portType, $doc); + $this->testDocumentNodes(); + $nodes = $this->xpath->query('//wsdl:portType[@name="myPortType"]/wsdl:documentation'); $this->assertEquals(1, $nodes->length); $this->assertEquals($doc, $nodes->item(0)->nodeValue); - - $this->testDocumentNodes(); } public function testAddDocumentationToSetInsertsBefore() @@ -504,10 +577,11 @@ public function testAddDocumentationToSetInsertsBefore() $message = $this->wsdl->addMessage('myMessage', $messageParts); $this->wsdl->addDocumentation($message, "foo"); + $this->testDocumentNodes(); + $nodes = $this->xpath->query('//wsdl:message[@name="myMessage"]/*[1]'); $this->assertEquals('documentation', $nodes->item(0)->nodeName); - $this->testDocumentNodes(); } public function testDumpToFile() @@ -526,7 +600,6 @@ public function testDumpToFile() public function testDumpToOutput() { - ob_start(); $dumpStatus = $this->wsdl->dump(); $screenContent = ob_get_clean(); @@ -541,6 +614,9 @@ public function checkXMLContent($content) libxml_use_internal_errors(true); libxml_disable_entity_loader(false); $xml = new \DOMDocument(); + $xml->preserveWhiteSpace = false; + $xml->encoding = 'UTF-8'; + $xml->formatOutput = false; $xml->loadXML($content); $errors = libxml_get_errors(); @@ -573,8 +649,6 @@ function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() { $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); - - $this->testDocumentNodes(); } function testGetComplexTypeBasedOnStrategiesStringNames() @@ -586,8 +660,6 @@ function testGetComplexTypeBasedOnStrategiesStringNames() $wsdl2 = new Wsdl($this->defaultServiceName, $this->defaultServiceUri, new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); $this->assertEquals('xsd:anyType', $wsdl2->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof ComplexTypeStrategy\AnyType); - - $this->testDocumentNodes(); } function testAddingSameComplexTypeMoreThanOnceIsIgnored() @@ -638,38 +710,11 @@ function testAddComplexType() { $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); + $this->testDocumentNodes(); + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType/xsd:all/*'); $this->assertGreaterThan(0, $nodes->length, 'Unable to find object properties in wsdl'); - - $this->testDocumentNodes(); -// print $nodes->length; -// print_r($nodes->item(0)->firstChild); -// print_r($this->wsdl->toXML()); -// -//exit; -// $this->markTestIncomplete(); - - /*$this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($this->wsdl->toXml()), - '' . - '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' );*/ } public function testAddTypesFromDocument() @@ -710,10 +755,14 @@ public function testTranslateTypeFromClassMap() /** * @dataProvider dataProviderForTranslateType */ - public function testTranslateType($type, $expected) { + public function testTranslateType($type, $expected) + { $this->assertEquals($expected, $this->wsdl->translateType($type)); } + /** + * @return array + */ public function dataProviderForTranslateType() { return array( array('\\SomeType','SomeType'), @@ -726,23 +775,18 @@ public function dataProviderForTranslateType() { /** * @group ZF-3910 + * @group ZF-11937 */ function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() { - $this->assertEquals("xsd:string", $this->wsdl->getType("StrIng")); - $this->assertEquals("xsd:string", $this->wsdl->getType("sTr")); - $this->assertEquals("xsd:int", $this->wsdl->getType("iNt")); - $this->assertEquals("xsd:int", $this->wsdl->getType("INTEGER")); - $this->assertEquals("xsd:float", $this->wsdl->getType("FLOAT")); - $this->assertEquals("xsd:double", $this->wsdl->getType("douBLE")); - } + $this->assertEquals("xsd:string", $this->wsdl->getType("StrIng")); + $this->assertEquals("xsd:string", $this->wsdl->getType("sTr")); + $this->assertEquals("xsd:int", $this->wsdl->getType("iNt")); + $this->assertEquals("xsd:int", $this->wsdl->getType("INTEGER")); + $this->assertEquals("xsd:float", $this->wsdl->getType("FLOAT")); + $this->assertEquals("xsd:double", $this->wsdl->getType("douBLE")); - /** - * @group ZF-11937 - */ - public function testWsdlGetTypeWillAllowLongType() - { - $this->assertEquals("xsd:long", $this->wsdl->getType("long")); + $this->assertEquals("xsd:long", $this->wsdl->getType("long")); } /** @@ -755,12 +799,16 @@ public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceByS $this->wsdl->addComplexType("string[]"); $this->wsdl->addComplexType("int[]"); $this->wsdl->addComplexType("string[]"); - - $xml = $this->wsdl->toXml(); - $this->assertEquals(1, substr_count($xml, "ArrayOfString"), "ArrayOfString should appear only once."); - $this->assertEquals(1, substr_count($xml, "ArrayOfInt"), "ArrayOfInt should appear only once."); + $this->wsdl->addComplexType("int[]"); $this->testDocumentNodes(); + + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="ArrayOfString"]'); + $this->assertEquals(1, $nodes->length, "ArrayOfString should appear only once."); + + $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:complexType[@name="ArrayOfInt"]'); + $this->assertEquals(1, $nodes->length, "ArrayOfInt should appear only once."); + } public function testClassMap() @@ -790,6 +838,8 @@ public function testAddElement() $newElementName = $this->wsdl->addElement($element); + $this->testDocumentNodes(); + $this->assertEquals('tns:'.$element['name'], $newElementName); $nodes = $this->xpath->query('//wsdl:types/xsd:schema/xsd:element[@name="'.$element['name'].'"]/xsd:complexType'); @@ -806,8 +856,6 @@ public function testAddElement() } $this->assertEquals(count($element['sequence']), $n); - - $this->testDocumentNodes(); } diff --git a/test/WsdlTestHelper.php b/test/WsdlTestHelper.php index 50f5685d..2aae3ef6 100755 --- a/test/WsdlTestHelper.php +++ b/test/WsdlTestHelper.php @@ -87,11 +87,12 @@ public function registerNamespaces($obj, $documentNamespace = null) $this->xpath = new \DOMXPath($obj); $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); - $this->xpath->registerNamespace('tns', $documentNamespace); - $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); - $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); + $this->xpath->registerNamespace('tns', $documentNamespace); + $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); + $this->xpath->registerNamespace('soap12', Wsdl::NS_SOAP12); + $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); - $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); return $obj; } From 63b924cf2454de7e447d1dd3cdff273a7d596a0f Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 28 Feb 2013 02:00:15 +0100 Subject: [PATCH 08/22] Missing tests for DotNet client. --- test/Client/DotNetTest.php | 204 ++++++++++++++++++++++++++++ test/TestAsset/MockCallUserFunc.php | 31 +++++ test/TestAsset/call_user_func.php | 40 ++++++ 3 files changed, 275 insertions(+) create mode 100755 test/Client/DotNetTest.php create mode 100755 test/TestAsset/MockCallUserFunc.php create mode 100755 test/TestAsset/call_user_func.php diff --git a/test/Client/DotNetTest.php b/test/Client/DotNetTest.php new file mode 100755 index 00000000..68930024 --- /dev/null +++ b/test/Client/DotNetTest.php @@ -0,0 +1,204 @@ +client = new DotNetClient(null, array('location' => 'http://unithost/test', + 'uri' => 'http://unithost/test')); + } + + /** + * Tests that a default cURL client is used if none is injected. + * + * @return void + * @covers Zend\Soap\Client\DotNet::getCurlClient + */ + public function testADefaultCurlClientIsUsedIfNoneIsInjected() + { + $this->assertInstanceOf('Zend\Http\Client\Adapter\Curl', $this->client->getCurlClient()); + } + + /** + * Tests that the cURL client can be injected. + * + * @return void + * @covers Zend\Soap\Client\DotNet::getCurlClient + * @covers Zend\Soap\Client\DotNet::setCurlClient + */ + public function testCurlClientCanBeInjected() + { + $this->mockCurlClient(); + $this->assertSame($this->curlClient, $this->client->getCurlClient()); + } + + /** + * Tests that a cURL client request is done when using NTLM + * authentication. + * + * @return void + * @covers Zend\Soap\Client\DotNet::_doRequest + */ + public function testCurlClientRequestIsDoneWhenUsingNtlmAuthentication() + { + $this->mockNtlmRequest(); + $this->assertInstanceOf('stdClass', $this->client->TestMethod()); + } + + /** + * Tests that the default SOAP client request is done when not using NTLM authentication. + * + * @return void + * @covers Zend\Soap\Client\DotNet::_doRequest + */ + public function testDefaultSoapClientRequestIsDoneWhenNotUsingNtlmAuthentication() + { + $soapClient = $this->getMock('Zend\Soap\Client\Common', + array('_doRequest'), + array(array($this->client, '_doRequest'), + null, + array('location' => 'http://unit/test', + 'uri' => 'http://unit/test'))); + + MockCallUserFunc::$mock = true; + $this->client->setSoapClient($soapClient); + $this->client->TestMethod(); + + $this->assertSame('http://unit/test#TestMethod', MockCallUserFunc::$params[3]); + + MockCallUserFunc::$mock = false; + } + + /** + * Tests that the last request headers can be fetched correctly. + * + * @return void + * @covers Zend\Soap\Client\DotNet::getLastRequestHeaders + */ + public function testLastRequestHeadersCanBeFetchedCorrectly() + { + $expectedHeaders = "Content-Type: text/xml; charset=utf-8\r\n" + . "Method: POST\r\n" + . "SOAPAction: \"http://unithost/test#TestMethod\"\r\n" + . "User-Agent: PHP-SOAP-CURL\r\n"; + + $this->mockNtlmRequest(); + $this->client->TestMethod(); + + $this->assertSame($expectedHeaders, $this->client->getLastRequestHeaders()); + } + + /** + * Tests that the last response headers can be fetched correctly. + * + * @return void + * @covers Zend\Soap\Client\DotNet::getLastResponseHeaders + */ + public function testLastResponseHeadersCanBeFetchedCorrectly() + { + $expectedHeaders = "Cache-Control: private\r\n" + . "Content-Type: text/xml; charset=utf-8\r\n"; + + $this->mockNtlmRequest(); + $this->client->TestMethod(); + + $this->assertSame($expectedHeaders, $this->client->getLastResponseHeaders()); + } + + /** + * Mocks the cURL client. + * + * @return void + */ + private function mockCurlClient() + { + $this->curlClient = $this->getMock('Zend\Http\Client\Adapter\Curl', + array('close', 'connect', 'read', 'write')); + $this->client->setCurlClient($this->curlClient); + } + + /** + * Mocks an NTLM SOAP request. + * + * @return void + */ + private function mockNtlmRequest() + { + $headers = array('Content-Type' => 'text/xml; charset=utf-8', + 'Method' => 'POST', + 'SOAPAction' => '"http://unithost/test#TestMethod"', + 'User-Agent' => 'PHP-SOAP-CURL'); + $response = "HTTP/1.1 200 OK\n" + . "Cache-Control: private\n" + . "Content-Type: text/xml; charset=utf-8\n" + . "\n\n" + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . ''; + + $this->mockCurlClient(); + + $this->curlClient->expects($this->once()) + ->method('connect') + ->with('unithost', 80); + $this->curlClient->expects($this->once()) + ->method('read') + ->will($this->returnValue($response)); + $this->curlClient->expects($this->any()) + ->method('write') + ->with('POST', $this->isInstanceOf('Zend\Uri\Http'), 1.1, $headers, $this->stringContains('client->setOptions(array('authentication' => 'ntlm', + 'login' => 'username', + 'password' => 'testpass')); + } +} diff --git a/test/TestAsset/MockCallUserFunc.php b/test/TestAsset/MockCallUserFunc.php new file mode 100755 index 00000000..6e7275df --- /dev/null +++ b/test/TestAsset/MockCallUserFunc.php @@ -0,0 +1,31 @@ +' + . ''; + + $result .= '' + . '' + . '' + . '' + . ''; + + $result .= '' + . ''; + + return $result; +} From c1d99b5e97a28d58a7ec049a8e78fdc46b100e81 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 28 Feb 2013 10:59:05 +0100 Subject: [PATCH 09/22] Another permission fix. --- src/AutoDiscover.php | 0 src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php | 0 src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php | 0 src/Client.php | 0 src/Client/Common.php | 0 src/Client/DotNet.php | 0 src/Client/Local.php | 0 src/Exception/BadMethodCallException.php | 0 src/Exception/ExceptionInterface.php | 0 src/Exception/ExtensionNotLoadedException.php | 0 src/Exception/InvalidArgumentException.php | 0 src/Exception/RuntimeException.php | 0 src/Exception/UnexpectedValueException.php | 0 src/Server.php | 0 src/Server/DocumentLiteralWrapper.php | 0 src/Wsdl.php | 0 src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php | 0 src/Wsdl/ComplexTypeStrategy/AnyType.php | 0 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php | 0 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php | 0 src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php | 0 src/Wsdl/ComplexTypeStrategy/Composite.php | 0 src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php | 0 test/AutoDiscoverTest.php | 0 test/Client/DotNetTest.php | 0 test/ClientTest.php | 0 test/ServerTest.php | 0 test/TestAsset/MockCallUserFunc.php | 0 test/TestAsset/call_user_func.php | 0 test/TestAsset/commontypes.php | 0 test/TestAsset/wsdl_example.wsdl | 0 test/Wsdl/ArrayOfTypeComplexStrategyTest.php | 0 test/Wsdl/ArrayOfTypeSequenceStrategyTest.php | 0 test/Wsdl/CompositeStrategyTest.php | 0 test/Wsdl/DefaultComplexTypeTest.php | 0 test/WsdlTest.php | 0 test/WsdlTestHelper.php | 0 test/_files/wsdl_example.wsdl | 0 38 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/AutoDiscover.php mode change 100755 => 100644 src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php mode change 100755 => 100644 src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php mode change 100755 => 100644 src/Client.php mode change 100755 => 100644 src/Client/Common.php mode change 100755 => 100644 src/Client/DotNet.php mode change 100755 => 100644 src/Client/Local.php mode change 100755 => 100644 src/Exception/BadMethodCallException.php mode change 100755 => 100644 src/Exception/ExceptionInterface.php mode change 100755 => 100644 src/Exception/ExtensionNotLoadedException.php mode change 100755 => 100644 src/Exception/InvalidArgumentException.php mode change 100755 => 100644 src/Exception/RuntimeException.php mode change 100755 => 100644 src/Exception/UnexpectedValueException.php mode change 100755 => 100644 src/Server.php mode change 100755 => 100644 src/Server/DocumentLiteralWrapper.php mode change 100755 => 100644 src/Wsdl.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/AnyType.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/Composite.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php mode change 100755 => 100644 test/AutoDiscoverTest.php mode change 100755 => 100644 test/Client/DotNetTest.php mode change 100755 => 100644 test/ClientTest.php mode change 100755 => 100644 test/ServerTest.php mode change 100755 => 100644 test/TestAsset/MockCallUserFunc.php mode change 100755 => 100644 test/TestAsset/call_user_func.php mode change 100755 => 100644 test/TestAsset/commontypes.php mode change 100755 => 100644 test/TestAsset/wsdl_example.wsdl mode change 100755 => 100644 test/Wsdl/ArrayOfTypeComplexStrategyTest.php mode change 100755 => 100644 test/Wsdl/ArrayOfTypeSequenceStrategyTest.php mode change 100755 => 100644 test/Wsdl/CompositeStrategyTest.php mode change 100755 => 100644 test/Wsdl/DefaultComplexTypeTest.php mode change 100755 => 100644 test/WsdlTest.php mode change 100755 => 100644 test/WsdlTestHelper.php mode change 100755 => 100644 test/_files/wsdl_example.wsdl diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php old mode 100755 new mode 100644 diff --git a/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php b/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php old mode 100755 new mode 100644 diff --git a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php old mode 100755 new mode 100644 diff --git a/src/Client.php b/src/Client.php old mode 100755 new mode 100644 diff --git a/src/Client/Common.php b/src/Client/Common.php old mode 100755 new mode 100644 diff --git a/src/Client/DotNet.php b/src/Client/DotNet.php old mode 100755 new mode 100644 diff --git a/src/Client/Local.php b/src/Client/Local.php old mode 100755 new mode 100644 diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php old mode 100755 new mode 100644 diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php old mode 100755 new mode 100644 diff --git a/src/Exception/ExtensionNotLoadedException.php b/src/Exception/ExtensionNotLoadedException.php old mode 100755 new mode 100644 diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php old mode 100755 new mode 100644 diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php old mode 100755 new mode 100644 diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php old mode 100755 new mode 100644 diff --git a/src/Server.php b/src/Server.php old mode 100755 new mode 100644 diff --git a/src/Server/DocumentLiteralWrapper.php b/src/Server/DocumentLiteralWrapper.php old mode 100755 new mode 100644 diff --git a/src/Wsdl.php b/src/Wsdl.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/AnyType.php b/src/Wsdl/ComplexTypeStrategy/AnyType.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php b/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php old mode 100755 new mode 100644 diff --git a/test/AutoDiscoverTest.php b/test/AutoDiscoverTest.php old mode 100755 new mode 100644 diff --git a/test/Client/DotNetTest.php b/test/Client/DotNetTest.php old mode 100755 new mode 100644 diff --git a/test/ClientTest.php b/test/ClientTest.php old mode 100755 new mode 100644 diff --git a/test/ServerTest.php b/test/ServerTest.php old mode 100755 new mode 100644 diff --git a/test/TestAsset/MockCallUserFunc.php b/test/TestAsset/MockCallUserFunc.php old mode 100755 new mode 100644 diff --git a/test/TestAsset/call_user_func.php b/test/TestAsset/call_user_func.php old mode 100755 new mode 100644 diff --git a/test/TestAsset/commontypes.php b/test/TestAsset/commontypes.php old mode 100755 new mode 100644 diff --git a/test/TestAsset/wsdl_example.wsdl b/test/TestAsset/wsdl_example.wsdl old mode 100755 new mode 100644 diff --git a/test/Wsdl/ArrayOfTypeComplexStrategyTest.php b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php old mode 100755 new mode 100644 diff --git a/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php old mode 100755 new mode 100644 diff --git a/test/Wsdl/CompositeStrategyTest.php b/test/Wsdl/CompositeStrategyTest.php old mode 100755 new mode 100644 diff --git a/test/Wsdl/DefaultComplexTypeTest.php b/test/Wsdl/DefaultComplexTypeTest.php old mode 100755 new mode 100644 diff --git a/test/WsdlTest.php b/test/WsdlTest.php old mode 100755 new mode 100644 diff --git a/test/WsdlTestHelper.php b/test/WsdlTestHelper.php old mode 100755 new mode 100644 diff --git a/test/_files/wsdl_example.wsdl b/test/_files/wsdl_example.wsdl old mode 100755 new mode 100644 From 1149e5a273365069d1832b020740f4f578c5795f Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 28 Feb 2013 11:34:25 +0100 Subject: [PATCH 10/22] First part of changes acording to code rewiev. Mostly style and formating changes. --- src/Client.php | 2 +- src/Wsdl.php | 18 ++++++++++++------ test/WsdlTest.php | 13 ++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) mode change 100644 => 100755 src/Client.php mode change 100644 => 100755 src/Wsdl.php mode change 100644 => 100755 test/WsdlTest.php diff --git a/src/Client.php b/src/Client.php old mode 100644 new mode 100755 index ee8b4d45..cabc70a5 --- a/src/Client.php +++ b/src/Client.php @@ -360,7 +360,7 @@ public function setClassmap(array $classmap) { foreach ($classmap as $class) { if (!class_exists($class)) { - throw new Exception\InvalidArgumentException('Invalid class in class map: '.$class); + throw new Exception\InvalidArgumentException('Invalid class in class map: ' . $class); } } diff --git a/src/Wsdl.php b/src/Wsdl.php old mode 100644 new mode 100755 index 7e980ba1..0ee42a59 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -354,9 +354,15 @@ public function addBinding($name, $portType) * * @param object $binding A binding XML_Tree_Node returned by {@link function addBinding} * @param string $name - * @param array|bool $input An array of attributes for the input element, allowed keys are: 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param array|bool $output An array of attributes for the output element, allowed keys are: 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param array|bool $fault An array with attributes for the fault element, allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * @param array|bool $input An array of attributes for the input element, + * allowed keys are: 'use', 'namespace', 'encodingStyle'. + * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * @param array|bool $output An array of attributes for the output element, + * allowed keys are: 'use', 'namespace', 'encodingStyle'. + * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * @param array|bool $fault An array with attributes for the fault element, + * allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. + * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} * * @return object The new Operation's XML_Tree_Node for use with {@link function addSoapOperation} and {@link function addDocumentation} */ @@ -369,7 +375,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $operation->appendChild($attr); $attr->value = $name; - if (is_array($input) AND !empty($input)) { + if (is_array($input) && !empty($input)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'input'); $operation->appendChild($node); @@ -379,7 +385,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $this->arrayToAttributes($soapNode, $input); } - if (is_array($output) AND !empty($output)) { + if (is_array($output) && !empty($output)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'output'); $operation->appendChild($node); @@ -389,7 +395,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $this->arrayToAttributes($soapNode, $output); } - if (is_array($fault) AND !empty($fault)) { + if (is_array($fault) && !empty($fault)) { $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'fault'); $operation->appendChild($node); diff --git a/test/WsdlTest.php b/test/WsdlTest.php old mode 100644 new mode 100755 index 255d23a2..8a96dc2b --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -9,8 +9,7 @@ */ namespace ZendTest\Soap; -use Zend\Soap\Wsdl, - Zend\Soap\Wsdl\ComplexTypeStrategy; +use Zend\Soap\Wsdl; use Zend\Uri\Uri; @@ -648,18 +647,18 @@ public function testGetType() function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() { $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); + $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof Wsdl\ComplexTypeStrategy\DefaultComplexType); } function testGetComplexTypeBasedOnStrategiesStringNames() { - $this->wsdl = new Wsdl($this->defaultServiceName, 'http://localhost/MyService.php', new \Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType); + $this->wsdl = new Wsdl($this->defaultServiceName, 'http://localhost/MyService.php', new Wsdl\ComplexTypeStrategy\DefaultComplexType); $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof ComplexTypeStrategy\DefaultComplexType); + $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof Wsdl\ComplexTypeStrategy\DefaultComplexType); - $wsdl2 = new Wsdl($this->defaultServiceName, $this->defaultServiceUri, new \Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType); + $wsdl2 = new Wsdl($this->defaultServiceName, $this->defaultServiceUri, new Wsdl\ComplexTypeStrategy\AnyType); $this->assertEquals('xsd:anyType', $wsdl2->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); - $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof ComplexTypeStrategy\AnyType); + $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof Wsdl\ComplexTypeStrategy\AnyType); } function testAddingSameComplexTypeMoreThanOnceIsIgnored() From 8a9fb423ca9b02aa7a7e4f0dd5f274b0018e1982 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 28 Feb 2013 13:51:09 +0100 Subject: [PATCH 11/22] Final code reformat acording to code review. --- src/AutoDiscover.php | 34 ++++----- src/Client.php | 69 +++++++++---------- src/Client/Common.php | 21 ++++-- src/Client/DotNet.php | 4 +- src/Server.php | 25 +++---- src/Server/DocumentLiteralWrapper.php | 7 +- src/Wsdl.php | 2 +- .../ArrayOfTypeComplex.php | 10 +-- src/Wsdl/ComplexTypeStrategy/Composite.php | 9 +-- .../DefaultComplexType.php | 3 +- 10 files changed, 91 insertions(+), 93 deletions(-) mode change 100644 => 100755 src/AutoDiscover.php mode change 100644 => 100755 src/Client/Common.php mode change 100644 => 100755 src/Client/DotNet.php mode change 100644 => 100755 src/Server.php mode change 100644 => 100755 src/Server/DocumentLiteralWrapper.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/Composite.php mode change 100644 => 100755 src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php old mode 100644 new mode 100755 index a2fdaf62..8e2196e9 --- a/src/AutoDiscover.php +++ b/src/AutoDiscover.php @@ -179,9 +179,7 @@ public function setServiceName($serviceName) $matches = array(); $i = preg_match('/^[a-z\_]/ims', $serviceName, $matches); if ($i != 1) { - throw new InvalidArgumentException( - 'XML NCName and Service Name must start with letter or _' - ); + throw new InvalidArgumentException('XML NCName and Service Name must start with letter or _'); } $this->serviceName = $serviceName; @@ -198,12 +196,9 @@ public function getServiceName() { if (!$this->serviceName) { if ($this->class) { - return $this->reflection->reflectClass($this->class) - ->getShortName(); + return $this->reflection->reflectClass($this->class)->getShortName(); } else { - throw new Exception\RuntimeException( - "No service name given. Call Autodiscover::setServiceName()." - ); + throw new Exception\RuntimeException('No service name given. Call Autodiscover::setServiceName().'); } } @@ -222,8 +217,7 @@ public function setUri($uri) { if (!is_string($uri) && !($uri instanceof Uri\Uri)) { throw new Exception\InvalidArgumentException( - 'Argument to \Zend\Soap\AutoDiscover::setUri should be string ' - .'or \Zend\Uri\Uri instance.' + 'Argument to \Zend\Soap\AutoDiscover::setUri should be string or \Zend\Uri\Uri instance.' ); } @@ -248,8 +242,8 @@ public function setUri($uri) public function getUri() { if ($this->uri === null) { - throw new Exception\RuntimeException("Missing uri. You have to ' - .'explicitly configure the Endpoint Uri by calling AutoDiscover::setUri()." + throw new Exception\RuntimeException( + 'Missing uri. You have to explicitly configure the Endpoint Uri by calling AutoDiscover::setUri().' ); } if (is_string($this->uri)) { @@ -302,9 +296,7 @@ public function getWsdlClass() public function setOperationBodyStyle(array $operationStyle=array()) { if (!isset($operationStyle['use'])) { - throw new Exception\InvalidArgumentException( - "Key 'use' is required in Operation soap:body style." - ); + throw new Exception\InvalidArgumentException('Key "use" is required in Operation soap:body style.'); } $this->operationBodyStyle = $operationStyle; return $this; @@ -372,14 +364,14 @@ public function addFunction($function) if (function_exists($function)) { $this->functions[] = $function; } else { - throw new Exception\InvalidArgumentException('Argument to ' - . '\Zend\Soap\AutoDiscover::addFunction should be a valid function name.' + throw new Exception\InvalidArgumentException( + 'Argument to Zend\Soap\AutoDiscover::addFunction should be a valid function name.' ); } } else { - throw new Exception\InvalidArgumentException('Argument to ' - . '\Zend\Soap\AutoDiscover::addFunction should be string or array of strings.' + throw new Exception\InvalidArgumentException( + 'Argument to Zend\Soap\AutoDiscover::addFunction should be string or array of strings.' ); } @@ -592,9 +584,7 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) public function generate() { if ($this->class && $this->functions) { - throw new Exception\RuntimeException( - "Can either dump functions or a class as a service, not both." - ); + throw new Exception\RuntimeException('Can either dump functions or a class as a service, not both.'); } if ($this->class) { diff --git a/src/Client.php b/src/Client.php index cabc70a5..46bca55f 100755 --- a/src/Client.php +++ b/src/Client.php @@ -327,8 +327,8 @@ public function getOptions() public function setSoapVersion($version) { if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) { - throw new Exception\InvalidArgumentException('Invalid soap version' - .' specified. Use SOAP_1_1 or SOAP_1_2 constants.' + throw new Exception\InvalidArgumentException( + 'Invalid soap version specified. Use SOAP_1_1 or SOAP_1_2 constants.' ); } $this->soapVersion = $version; @@ -391,12 +391,12 @@ public function setTypemap(array $typeMap) foreach ($typeMap as $type) { if (!is_callable($type['from_xml'])) { throw new Exception\InvalidArgumentException( - 'Invalid from_xml callback for type: '.$type['type_name'] + 'Invalid from_xml callback for type: ' . $type['type_name'] ); } if (!is_callable($type['to_xml'])) { throw new Exception\InvalidArgumentException( - 'Invalid to_xml callback for type: '.$type['type_name'] + 'Invalid to_xml callback for type: ' . $type['type_name'] ); } } @@ -537,8 +537,8 @@ public function getLocation() public function setStyle($style) { if (!in_array($style, array(SOAP_RPC, SOAP_DOCUMENT))) { - throw new Exception\InvalidArgumentException('Invalid request style' - . ' specified. Use SOAP_RPC or SOAP_DOCUMENT constants.' + throw new Exception\InvalidArgumentException( + 'Invalid request style specified. Use SOAP_RPC or SOAP_DOCUMENT constants.' ); } @@ -570,8 +570,8 @@ public function getStyle() public function setEncodingMethod($use) { if (!in_array($use, array(SOAP_ENCODED, SOAP_LITERAL))) { - throw new Exception\InvalidArgumentException('Invalid message' - .' encoding method. Use SOAP_ENCODED or SOAP_LITERAL constants.' + throw new Exception\InvalidArgumentException( + 'Invalid message encoding method. Use SOAP_ENCODED or SOAP_LITERAL constants.' ); } @@ -1017,12 +1017,21 @@ public function _doRequest(Client\Common $client, $request, $location, ) { // Perform request as is if ($oneWay === null) { - return call_user_func(array($client,'SoapClient::__doRequest'), - $request, $location, $action, $version + return call_user_func( + array($client, 'SoapClient::__doRequest'), + $request, + $location, + $action, + $version ); } - return call_user_func(array($client, 'SoapClient::__doRequest'), $request, - $location, $action, $version, $oneWay + return call_user_func( + array($client, 'SoapClient::__doRequest'), + $request, + $location, + $action, + $version, + $oneWay ); } @@ -1038,25 +1047,17 @@ protected function _initSoapClientObject() if ($wsdl == null) { if (!isset($options['location'])) { - throw new Exception\UnexpectedValueException( - '\'location\' parameter is required in non-WSDL mode.' - ); + throw new Exception\UnexpectedValueException('"location" parameter is required in non-WSDL mode.'); } if (!isset($options['uri'])) { - throw new Exception\UnexpectedValueException( - '\'uri\' parameter is required in non-WSDL mode.' - ); + throw new Exception\UnexpectedValueException('"uri" parameter is required in non-WSDL mode.'); } } else { if (isset($options['use'])) { - throw new Exception\UnexpectedValueException( - '\'use\' parameter only works in non-WSDL mode.' - ); + throw new Exception\UnexpectedValueException('"use" parameter only works in non-WSDL mode.'); } if (isset($options['style'])) { - throw new Exception\UnexpectedValueException( - '\'style\' parameter only works in non-WSDL mode.' - ); + throw new Exception\UnexpectedValueException('"style" parameter only works in non-WSDL mode.'); } } unset($options['wsdl']); @@ -1151,11 +1152,13 @@ public function __call($name, $arguments) $this->lastMethod = $name; $soapHeaders = array_merge($this->permanentSoapInputHeaders, $this->soapInputHeaders); - $result = $soapClient->__soapCall($name, - $this->_preProcessArguments($arguments), - null, /* Options are already set to the SOAP client object */ - (count($soapHeaders) > 0)? $soapHeaders : null, - $this->soapOutputHeaders); + $result = $soapClient->__soapCall( + $name, + $this->_preProcessArguments($arguments), + null, /* Options are already set to the SOAP client object */ + (count($soapHeaders) > 0)? $soapHeaders : null, + $this->soapOutputHeaders + ); // Reset non-permanent input headers $this->soapInputHeaders = array(); @@ -1184,9 +1187,7 @@ public function call($method, $params = array()) public function getFunctions() { if ($this->getWSDL() == null) { - throw new Exception\UnexpectedValueException( - __METHOD__ . ' is available only in WSDL mode.' - ); + throw new Exception\UnexpectedValueException(__METHOD__ . ' is available only in WSDL mode.'); } $soapClient = $this->getSoapClient(); @@ -1209,9 +1210,7 @@ public function getFunctions() public function getTypes() { if ($this->getWSDL() == null) { - throw new Exception\UnexpectedValueException( - __METHOD__ . ' method is available only in WSDL mode.' - ); + throw new Exception\UnexpectedValueException(__METHOD__ . ' method is available only in WSDL mode.'); } $soapClient = $this->getSoapClient(); diff --git a/src/Client/Common.php b/src/Client/Common.php old mode 100644 new mode 100755 index d9c820c2..f9333780 --- a/src/Client/Common.php +++ b/src/Client/Common.php @@ -51,12 +51,25 @@ public function __construct($doRequestCallback, $wsdl, $options) public function __doRequest($request, $location, $action, $version, $oneWay = null) { if ($oneWay === null) { - return call_user_func($this->doRequestCallback, $this, $request, - $location, $action, $version); + return call_user_func( + $this->doRequestCallback, + $this, + $request, + $location, + $action, + $version + ); } - return call_user_func($this->doRequestCallback, $this, $request, - $location, $action, $version, $oneWay); + return call_user_func( + $this->doRequestCallback, + $this, + $request, + $location, + $action, + $version, + $oneWay + ); } } diff --git a/src/Client/DotNet.php b/src/Client/DotNet.php old mode 100644 new mode 100755 index b46ac3c6..3525dc99 --- a/src/Client/DotNet.php +++ b/src/Client/DotNet.php @@ -199,8 +199,8 @@ protected function _preProcessArguments($arguments) if (count($arguments) > 1 || (count($arguments) == 1 && !is_array(reset($arguments))) ) { - throw new Exception\RuntimeException('.Net webservice arguments have' - ." to be grouped into array: array('a' => \$a, 'b' => \$b, ...)." + throw new Exception\RuntimeException( + '.Net webservice arguments have to be grouped into array: array("a" => $a, "b" => $b, ...).' ); } diff --git a/src/Server.php b/src/Server.php old mode 100644 new mode 100755 index 8e48d132..fa92e853 --- a/src/Server.php +++ b/src/Server.php @@ -212,8 +212,8 @@ public function setOptions($options) // @todo is missing break really necessary ? case 'featues': - trigger_error(__METHOD__ . ': the option "featues" is deprecated'. - ' as of 1.10.x and will be removed with 2.0.0; use "features" instead', + trigger_error( + __METHOD__ . ': the option "featues" is deprecated as of 1.10.x and will be removed with 2.0.0; use "features" instead', E_USER_NOTICE ); @@ -601,15 +601,11 @@ public function setClass($class, $namespace = '', $argv = null) } if (!is_string($class)) { - throw new Exception\InvalidArgumentException( - 'Invalid class argument (' . gettype($class) . ')' - ); + throw new Exception\InvalidArgumentException('Invalid class argument (' . gettype($class) . ')'); } if (!class_exists($class)) { - throw new Exception\InvalidArgumentException( - 'Class "' . $class . '" does not exist' - ); + throw new Exception\InvalidArgumentException('Class "' . $class . '" does not exist'); } $this->class = $class; @@ -634,9 +630,7 @@ public function setClass($class, $namespace = '', $argv = null) public function setObject($object) { if (!is_object($object)) { - throw new Exception\InvalidArgumentException( - 'Invalid object argument ('.gettype($object).')' - ); + throw new Exception\InvalidArgumentException('Invalid object argument ('.gettype($object).')'); } if (isset($this->object)) { @@ -760,9 +754,7 @@ protected function _setRequest($request) foreach ($dom->childNodes as $child) { if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { - throw new Exception\InvalidArgumentException( - 'Invalid XML: Detected use of illegal DOCTYPE' - ); + throw new Exception\InvalidArgumentException('Invalid XML: Detected use of illegal DOCTYPE'); } } libxml_disable_entity_loader(false); @@ -969,9 +961,8 @@ public function registerFaultException($class) $this->faultExceptions[] = $ref->getName(); $this->faultExceptions = array_unique($this->faultExceptions); } else { - throw new Exception\InvalidArgumentException('Argument for' - .' \Zend\Soap\Server::registerFaultException should be string or ' - . 'array of strings with valid exception names' + throw new Exception\InvalidArgumentException( + 'Argument for Zend\Soap\Server::registerFaultException should be string or array of strings with valid exception names' ); } diff --git a/src/Server/DocumentLiteralWrapper.php b/src/Server/DocumentLiteralWrapper.php old mode 100644 new mode 100755 index c034d529..c343da66 --- a/src/Server/DocumentLiteralWrapper.php +++ b/src/Server/DocumentLiteralWrapper.php @@ -129,7 +129,9 @@ protected function _parseArguments($method, $document) if (!isset($params[$argName])) { throw new UnexpectedValueException(sprintf( "Received unknown argument %s which is not an argument to %s::%s", - $argName, get_class($this->object), $method + $argName, + get_class($this->object), + $method )); } $delegateArgs[$params[$argName]->getPosition()] = $argValue; @@ -147,7 +149,8 @@ protected function _assertServiceDelegateHasMethod($method) if (!$this->reflection->hasMethod($method)) { throw new BadMethodCallException(sprintf( "Method %s does not exist on delegate object %s", - $method, get_class($this->object) + $method, + get_class($this->object) )); } } diff --git a/src/Wsdl.php b/src/Wsdl.php index 0ee42a59..79a799c5 100755 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -721,7 +721,7 @@ public function addComplexType($type) private function _parseElement($element) { if (!is_array($element)) { - throw new Exception\RuntimeException("The 'element' parameter needs to be an associative array."); + throw new Exception\RuntimeException('The "element" parameter needs to be an associative array.'); } $elementXML = $this->dom->createElementNS(Wsdl::NS_SCHEMA, 'element'); diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php old mode 100644 new mode 100755 index c9710278..414a8669 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php @@ -42,8 +42,7 @@ public function addComplexType($type) return $this->_addArrayOfComplexType($singularType, $type); } else { throw new Exception\InvalidArgumentException( - 'ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than ' - . 'one level. Use array object properties to return deep nested data.' + 'ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than one level. Use array object properties to return deep nested data.' ); } } @@ -91,8 +90,11 @@ protected function _addArrayOfComplexType($singularType, $type) $xsdRestriction->appendChild($xsdAttribute); $xsdAttribute->setAttribute('ref', 'soap-enc:arrayType'); - $xsdAttribute->setAttributeNS(Wsdl::NS_WSDL, 'arrayType', - 'tns:' . $this->getContext()->translateType($singularType) . '[]'); + $xsdAttribute->setAttributeNS( + Wsdl::NS_WSDL, + 'arrayType', + 'tns:' . $this->getContext()->translateType($singularType) . '[]' + ); return $xsdComplexType; } diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php old mode 100644 new mode 100755 index a9268440..9952d8a8 --- a/src/Wsdl/ComplexTypeStrategy/Composite.php +++ b/src/Wsdl/ComplexTypeStrategy/Composite.php @@ -46,8 +46,9 @@ class Composite implements ComplexTypeStrategy * @param array $typeMap * @param string|ComplexTypeStrategy $defaultStrategy */ - public function __construct(array $typeMap=array(), - $defaultStrategy='\Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType' + public function __construct( + array $typeMap=array(), + $defaultStrategy = '\Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType' ) { foreach ($typeMap AS $type => $strategy) { $this->connectTypeToStrategy($type, $strategy); @@ -111,7 +112,7 @@ public function getStrategyOfType($type) if ( !($strategy instanceof ComplexTypeStrategy) ) { throw new Exception\InvalidArgumentException( - "Strategy for Complex Type '$type' is not a valid strategy object." + 'Strategy for Complex Type ' . $type . ' is not a valid strategy object.' ); } $this->typeMap[$type] = $strategy; @@ -144,7 +145,7 @@ public function addComplexType($type) { if (!($this->context instanceof Wsdl) ) { throw new Exception\InvalidArgumentException( - "Cannot add complex type '$type', no context is set for this composite strategy." + 'Cannot add complex type ' . $type . ', no context is set for this composite strategy.' ); } diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php old mode 100644 new mode 100755 index 7b41b857..85f4aa5c --- a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php +++ b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php @@ -29,8 +29,7 @@ public function addComplexType($type) { if (!class_exists($type)) { throw new Exception\InvalidArgumentException(sprintf( - 'Cannot add a complex type %s that is not an object or where ' - . 'class could not be found in \'DefaultComplexType\' strategy.', + 'Cannot add a complex type %s that is not an object or where class could not be found in "DefaultComplexType" strategy.', $type )); } From db65f671419501fdecf4f18af9e71ba2edccf1e4 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 28 Feb 2013 14:04:38 +0100 Subject: [PATCH 12/22] Damm you file permissions :/. Another fix. --- src/AutoDiscover.php | 0 src/Client.php | 0 src/Client/Common.php | 0 src/Client/DotNet.php | 0 src/Server.php | 0 src/Server/DocumentLiteralWrapper.php | 0 src/Wsdl.php | 0 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php | 0 src/Wsdl/ComplexTypeStrategy/Composite.php | 0 src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php | 0 10 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/AutoDiscover.php mode change 100755 => 100644 src/Client.php mode change 100755 => 100644 src/Client/Common.php mode change 100755 => 100644 src/Client/DotNet.php mode change 100755 => 100644 src/Server.php mode change 100755 => 100644 src/Server/DocumentLiteralWrapper.php mode change 100755 => 100644 src/Wsdl.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/Composite.php mode change 100755 => 100644 src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php old mode 100755 new mode 100644 diff --git a/src/Client.php b/src/Client.php old mode 100755 new mode 100644 diff --git a/src/Client/Common.php b/src/Client/Common.php old mode 100755 new mode 100644 diff --git a/src/Client/DotNet.php b/src/Client/DotNet.php old mode 100755 new mode 100644 diff --git a/src/Server.php b/src/Server.php old mode 100755 new mode 100644 diff --git a/src/Server/DocumentLiteralWrapper.php b/src/Server/DocumentLiteralWrapper.php old mode 100755 new mode 100644 diff --git a/src/Wsdl.php b/src/Wsdl.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php old mode 100755 new mode 100644 diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php old mode 100755 new mode 100644 From 2016696365b6f383269723dfc74a54274e7f1413 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 28 Feb 2013 15:26:50 +0100 Subject: [PATCH 13/22] Fixed failing tests. --- src/AutoDiscover.php | 2 +- src/Wsdl/ComplexTypeStrategy/Composite.php | 4 ++-- test/AutoDiscoverTest.php | 5 ++--- test/Wsdl/CompositeStrategyTest.php | 4 ++-- test/WsdlTest.php | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) mode change 100755 => 100644 test/WsdlTest.php diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php index 8e2196e9..fc51b966 100644 --- a/src/AutoDiscover.php +++ b/src/AutoDiscover.php @@ -217,7 +217,7 @@ public function setUri($uri) { if (!is_string($uri) && !($uri instanceof Uri\Uri)) { throw new Exception\InvalidArgumentException( - 'Argument to \Zend\Soap\AutoDiscover::setUri should be string or \Zend\Uri\Uri instance.' + 'Argument to \Zend\Soap\AutoDiscover::setUri should be string or \Zend\Uri\Uri instance.' ); } diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php index 9952d8a8..f585187d 100644 --- a/src/Wsdl/ComplexTypeStrategy/Composite.php +++ b/src/Wsdl/ComplexTypeStrategy/Composite.php @@ -112,7 +112,7 @@ public function getStrategyOfType($type) if ( !($strategy instanceof ComplexTypeStrategy) ) { throw new Exception\InvalidArgumentException( - 'Strategy for Complex Type ' . $type . ' is not a valid strategy object.' + 'Strategy for Complex Type "' . $type . '" is not a valid strategy object.' ); } $this->typeMap[$type] = $strategy; @@ -145,7 +145,7 @@ public function addComplexType($type) { if (!($this->context instanceof Wsdl) ) { throw new Exception\InvalidArgumentException( - 'Cannot add complex type ' . $type . ', no context is set for this composite strategy.' + 'Cannot add complex type "' . $type . '", no context is set for this composite strategy.' ); } diff --git a/test/AutoDiscoverTest.php b/test/AutoDiscoverTest.php index 415c3a36..edac2a98 100644 --- a/test/AutoDiscoverTest.php +++ b/test/AutoDiscoverTest.php @@ -1209,9 +1209,8 @@ public function testSetNonStringNonZendUriUriThrowsException() $server = new AutoDiscover(); $this->setExpectedException( - 'Zend\Soap\Exception\InvalidArgumentException', - 'Argument to \Zend\Soap\AutoDiscover::setUri should be string ' - . 'or \Zend\Uri\Uri instance.' + '\Zend\Soap\Exception\InvalidArgumentException', + 'Argument to \Zend\Soap\AutoDiscover::setUri should be string or \Zend\Uri\Uri instance.' ); $server->setUri(array("bogus")); } diff --git a/test/Wsdl/CompositeStrategyTest.php b/test/Wsdl/CompositeStrategyTest.php index 4092703d..d70260e1 100644 --- a/test/Wsdl/CompositeStrategyTest.php +++ b/test/Wsdl/CompositeStrategyTest.php @@ -83,7 +83,7 @@ public function testCompositeThrowsExceptionOnInvalidStrategy() $strategy->connectTypeToStrategy('Book', 'strategy'); $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', - 'Strategy for Complex Type \'Book\' is not a valid strategy' + 'Strategy for Complex Type "Book" is not a valid strategy' ); $strategy->getStrategyOfType('Book'); } @@ -122,7 +122,7 @@ public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrows { $strategy = new ComplexTypeStrategy\Composite(); - $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Cannot add complex type \'Test\''); + $this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Cannot add complex type "Test"'); $strategy->addComplexType('Test'); } diff --git a/test/WsdlTest.php b/test/WsdlTest.php old mode 100755 new mode 100644 index 8a96dc2b..b9ba7f7b --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -793,7 +793,7 @@ function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() */ public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceBySequenceStrategy() { - $this->wsdl->setComplexTypeStrategy(new ComplexTypeStrategy\ArrayOfTypeSequence()); + $this->wsdl->setComplexTypeStrategy(new Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence()); $this->wsdl->addComplexType("string[]"); $this->wsdl->addComplexType("int[]"); From c148a6e559794d8b07c72560393621d998db08bc Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Thu, 28 Feb 2013 20:05:47 +0100 Subject: [PATCH 14/22] Proper namespace constants. Change in namespace prefixes to use constants. Format and code style fixes acording to code review. Restpre AutoDiscovery::handle with tests. --- src/AutoDiscover.php | 27 +++- src/Client.php | 2 +- src/Server.php | 17 +-- src/Wsdl.php | 142 ++++++++++-------- src/Wsdl/ComplexTypeStrategy/AnyType.php | 4 +- .../ArrayOfTypeComplex.php | 18 +-- .../ArrayOfTypeSequence.php | 8 +- .../DefaultComplexType.php | 8 +- test/AutoDiscoverTest.php | 28 +++- test/Wsdl/ArrayOfTypeComplexStrategyTest.php | 12 +- test/WsdlTest.php | 20 +-- test/WsdlTestHelper.php | 12 +- 12 files changed, 170 insertions(+), 128 deletions(-) diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php index fc51b966..99a251d4 100644 --- a/src/AutoDiscover.php +++ b/src/AutoDiscover.php @@ -422,13 +422,13 @@ protected function _generateWsdl(array $reflectionMethods) $wsdl->addSchemaTypeSection(); $port = $wsdl->addPortType($serviceName . 'Port'); - $binding = $wsdl->addBinding($serviceName . 'Binding', 'tns:' . $serviceName . 'Port'); + $binding = $wsdl->addBinding($serviceName . 'Binding', Wsdl::TYPES_NS . ':' . $serviceName . 'Port'); $wsdl->addSoapBinding($binding, $this->bindingStyle['style'], $this->bindingStyle['transport'] ); $wsdl->addService($serviceName . 'Service', $serviceName . 'Port', - 'tns:' . $serviceName . 'Binding', $uri + Wsdl::TYPES_NS . ':' . $serviceName . 'Binding', $uri ); foreach ($reflectionMethods as $method) { @@ -543,12 +543,16 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) // Add the portType operation if ($isOneWayMessage == false) { - $portOperation = $wsdl->addPortOperation($port, $functionName, - 'tns:' . $functionName . 'In', 'tns:' . $functionName . 'Out' + $portOperation = $wsdl->addPortOperation( + $port, + $functionName, + Wsdl::TYPES_NS . ':' . $functionName . 'In', Wsdl::TYPES_NS . ':' . $functionName . 'Out' ); } else { - $portOperation = $wsdl->addPortOperation($port, $functionName, - 'tns:' . $functionName . 'In', false + $portOperation = $wsdl->addPortOperation( + $port, + $functionName, + Wsdl::TYPES_NS . ':' . $functionName . 'In', false ); } $desc = $this->discoveryStrategy->getFunctionDocumentation($function); @@ -618,4 +622,15 @@ public function toXml() { return $this->generate()->toXml(); } + + /** + * Handle WSDL document. + * + * @return void + */ + public function handle() + { + header('Content-Type: text/xml'); + echo $this->toXml(); + } } diff --git a/src/Client.php b/src/Client.php index 46bca55f..0b7ffed7 100644 --- a/src/Client.php +++ b/src/Client.php @@ -405,7 +405,7 @@ public function setTypemap(array $typeMap) $this->soapClient = null; return $this; -} + } /** * Retrieve typemap diff --git a/src/Server.php b/src/Server.php index fa92e853..03b4bfd3 100644 --- a/src/Server.php +++ b/src/Server.php @@ -210,13 +210,6 @@ public function setOptions($options) $this->setWSDLCache($value); break; - // @todo is missing break really necessary ? - case 'featues': - trigger_error( - __METHOD__ . ': the option "featues" is deprecated as of 1.10.x and will be removed with 2.0.0; use "features" instead', - E_USER_NOTICE - ); - case 'features': $this->setSoapFeatures($value); break; @@ -333,7 +326,7 @@ public function getSoapVersion() * @param string $urn * @throws Exception\InvalidArgumentException on invalid URN * - * @return bool + * @return true */ public function validateUrn($urn) { @@ -447,10 +440,10 @@ public function setTypemap($typeMap) foreach ($typeMap as $type) { if (!is_callable($type['from_xml'])) { - throw new Exception\InvalidArgumentException('Invalid from_xml callback for type: '.$type['type_name']); + throw new Exception\InvalidArgumentException('Invalid from_xml callback for type: ' . $type['type_name']); } if (!is_callable($type['to_xml'])) { - throw new Exception\InvalidArgumentException('Invalid to_xml callback for type: '.$type['type_name']); + throw new Exception\InvalidArgumentException('Invalid to_xml callback for type: ' . $type['type_name']); } } @@ -630,7 +623,7 @@ public function setClass($class, $namespace = '', $argv = null) public function setObject($object) { if (!is_object($object)) { - throw new Exception\InvalidArgumentException('Invalid object argument ('.gettype($object).')'); + throw new Exception\InvalidArgumentException('Invalid object argument (' . gettype($object) . ')'); } if (isset($this->object)) { @@ -700,7 +693,7 @@ public function setPersistence($mode) /** * Get server persistence * - * @return Server + * @return int */ public function getPersistence() { diff --git a/src/Wsdl.php b/src/Wsdl.php index 79a799c5..70de56d5 100644 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -60,12 +60,29 @@ class Wsdl */ protected $classMap = array(); - const NS_WSDL = 'http://schemas.xmlsoap.org/wsdl/'; - const NS_XMLNS = 'http://www.w3.org/2000/xmlns/'; - const NS_SOAP = 'http://schemas.xmlsoap.org/wsdl/soap/'; - const NS_SOAP12 = 'http://schemas.xmlsoap.org/wsdl/soap12/'; - const NS_SCHEMA = 'http://www.w3.org/2001/XMLSchema'; - const NS_S_ENC = 'http://schemas.xmlsoap.org/soap/encoding/'; +// const WSDL_NS_URI = 'http://schemas.xmlsoap.org/wsdl/'; +// const XML_NS_URI = 'http://www.w3.org/2000/xmlns/'; +// const SOAP_11_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap/'; +// const SOAP_12_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap12/'; +// const XSD_NS_URI = 'http://www.w3.org/2001/XMLSchema'; +// const SOAP_ENC_URI = 'http://schemas.xmlsoap.org/soap/encoding/'; + + /**#@+ + * XML Namespaces. + */ + const XML_NS = 'xmlns'; + const XML_NS_URI = 'http://www.w3.org/2000/xmlns/'; + const WSDL_NS = 'wsdl'; + const WSDL_NS_URI = 'http://schemas.xmlsoap.org/wsdl/'; + const SOAP_11_NS = 'soap'; + const SOAP_11_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap/'; + const SOAP_12_NS = 'soap12'; + const SOAP_12_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap12/'; + const SOAP_ENC_NS = 'soap-enc'; + const SOAP_ENC_URI = 'http://schemas.xmlsoap.org/soap/encoding/'; + const XSD_NS = 'xsd'; + const XSD_NS_URI = 'http://www.w3.org/2001/XMLSchema'; + const TYPES_NS = 'tns'; /** * Constructor @@ -108,19 +125,19 @@ protected function getDOMDocument($name, $uri = null) $dom->encoding = 'UTF-8'; $dom->substituteEntities = false; - $definitions = $dom->createElementNS(Wsdl::NS_WSDL, 'definitions'); + $definitions = $dom->createElementNS(Wsdl::WSDL_NS_URI, 'definitions'); $dom->appendChild($definitions); $uri = $this->sanitizeUri($uri); $this->setAttributeWithSanitization($definitions, 'name', $name); $this->setAttributeWithSanitization($definitions, 'targetNamespace', $uri); - $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:wsdl', Wsdl::NS_WSDL); - $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:tns', $uri); - $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:soap', Wsdl::NS_SOAP); - $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:xsd', Wsdl::NS_SCHEMA); - $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:soap-enc', Wsdl::NS_S_ENC); - $definitions->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:soap12', Wsdl::NS_SOAP12); + $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::WSDL_NS, Wsdl::WSDL_NS_URI); + $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::TYPES_NS, $uri); + $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::SOAP_11_NS, Wsdl::SOAP_11_NS_URI); + $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::XSD_NS, Wsdl::XSD_NS_URI); + $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::SOAP_ENC_NS, Wsdl::SOAP_ENC_URI); + $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::SOAP_12_NS, Wsdl::SOAP_12_NS_URI); return $dom; } @@ -158,22 +175,21 @@ public function setUri($uri) if ($this->dom instanceof \DOMDocument ) { // namespace declarations are NOT true attributes - $this->dom->documentElement->setAttributeNS(Wsdl::NS_XMLNS, 'xmlns:tns', $uri); - + $this->dom->documentElement->setAttributeNS(Wsdl::XML_NS_URI, Wsdl::XML_NS . ':' . Wsdl::TYPES_NS, $uri); $xpath = new \DOMXPath($this->dom); - $xpath->registerNamespace('unittest', Wsdl::NS_WSDL); + $xpath->registerNamespace('default', Wsdl::WSDL_NS_URI); - $xpath->registerNamespace('tns', $uri); - $xpath->registerNamespace('soap', Wsdl::NS_SOAP); - $xpath->registerNamespace('soap12', Wsdl::NS_SOAP12); - $xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); - $xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); - $xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + $xpath->registerNamespace(Wsdl::TYPES_NS, $uri); + $xpath->registerNamespace(Wsdl::SOAP_11_NS, Wsdl::SOAP_11_NS_URI); + $xpath->registerNamespace(Wsdl::SOAP_12_NS, Wsdl::SOAP_12_NS_URI); + $xpath->registerNamespace(Wsdl::XSD_NS, Wsdl::XSD_NS_URI); + $xpath->registerNamespace(Wsdl::SOAP_ENC_NS, Wsdl::SOAP_ENC_URI); + $xpath->registerNamespace(Wsdl::WSDL_NS, Wsdl::WSDL_NS_URI); // select only attribute nodes. Data nodes does not contain uri except for documentation node but // this is for the user to decide - $attributeNodes = $xpath->query('//attribute::*[contains(., "'.$oldUri.'")]'); + $attributeNodes = $xpath->query('//attribute::*[contains(., "' . $oldUri . '")]'); /** @var $node \DOMAttr */ foreach ($attributeNodes as $node) { @@ -188,7 +204,8 @@ public function setUri($uri) /** * @return string */ - public function getUri() { + public function getUri() + { return $this->uri; } @@ -200,7 +217,8 @@ public function getUri() { * @throws Exception\InvalidArgumentException * @return string */ - public function sanitizeUri($uri) { + public function sanitizeUri($uri) + { if ($uri instanceof Uri) { $uri = $uri->toString(); @@ -252,13 +270,13 @@ public function getComplexTypeStrategy() */ public function addMessage($messageName, $parts) { - $message = $this->dom->createElementNS(Wsdl::NS_WSDL, 'message'); + $message = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'message'); $message->setAttribute('name', $messageName); if (count($parts) > 0) { foreach ($parts as $name => $type) { - $part = $this->dom->createElementNS(Wsdl::NS_WSDL, 'part'); + $part = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'part'); $part->setAttribute('name', $name); if (is_array($type)) { $this->arrayToAttributes($part, $type); @@ -282,7 +300,7 @@ public function addMessage($messageName, $parts) */ public function addPortType($name) { - $portType = $this->dom->createElementNS(Wsdl::NS_WSDL, 'portType'); + $portType = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'portType'); $portType->setAttribute('name', $name); $this->wsdl->appendChild($portType); @@ -301,21 +319,21 @@ public function addPortType($name) */ public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false) { - $operation = $this->dom->createElementNS(Wsdl::NS_WSDL, 'operation'); + $operation = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'operation'); $operation->setAttribute('name', $name); if (is_string($input) && (strlen(trim($input)) >= 1)) { - $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'input'); + $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'input'); $operation->appendChild($node); $node->setAttribute('message', $input); } if (is_string($output) && (strlen(trim($output)) >= 1)) { - $node= $this->dom->createElementNS(Wsdl::NS_WSDL, 'output'); + $node= $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'output'); $operation->appendChild($node); $node->setAttribute('message', $output); } if (is_string($fault) && (strlen(trim($fault)) >= 1)) { - $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'fault'); + $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'fault'); $operation->appendChild($node); $node->setAttribute('message', $fault); } @@ -335,7 +353,7 @@ public function addPortOperation($portType, $name, $input = false, $output = fal */ public function addBinding($name, $portType) { - $binding = $this->dom->createElementNS(Wsdl::NS_WSDL, 'binding'); + $binding = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'binding'); $this->wsdl->appendChild($binding); $attr = $this->dom->createAttribute('name'); @@ -368,7 +386,7 @@ public function addBinding($name, $portType) */ public function addBindingOperation($binding, $name, $input = false, $output = false, $fault = false) { - $operation = $this->dom->createElementNS(Wsdl::NS_WSDL, 'operation'); + $operation = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'operation'); $binding->appendChild($operation); $attr = $this->dom->createAttribute('name'); @@ -376,27 +394,27 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $attr->value = $name; if (is_array($input) && !empty($input)) { - $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'input'); + $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'input'); $operation->appendChild($node); - $soapNode = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); + $soapNode = $this->dom->createElementNS(Wsdl::SOAP_11_NS_URI, 'body'); $node->appendChild($soapNode); $this->arrayToAttributes($soapNode, $input); } if (is_array($output) && !empty($output)) { - $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'output'); + $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'output'); $operation->appendChild($node); - $soapNode = $this->dom->createElementNS(Wsdl::NS_SOAP, 'body'); + $soapNode = $this->dom->createElementNS(Wsdl::SOAP_11_NS_URI, 'body'); $node->appendChild($soapNode); $this->arrayToAttributes($soapNode, $output); } if (is_array($fault) && !empty($fault)) { - $node = $this->dom->createElementNS(Wsdl::NS_WSDL, 'fault'); + $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'fault'); $operation->appendChild($node); $this->arrayToAttributes($node, $fault); @@ -416,7 +434,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f public function addSoapBinding($binding, $style = 'document', $transport = 'http://schemas.xmlsoap.org/soap/http') { - $soapBinding = $this->dom->createElementNS(WSDL::NS_SOAP, 'binding'); + $soapBinding = $this->dom->createElementNS(WSDL::SOAP_11_NS_URI, 'binding'); $soapBinding->setAttribute('style', $style); $soapBinding->setAttribute('transport', $transport); @@ -437,7 +455,7 @@ public function addSoapOperation($binding, $soapAction) if ($soapAction instanceof Uri) { $soapAction = $soapAction->toString(); } - $soapOperation = $this->dom->createElementNS(WSDL::NS_SOAP, 'operation'); + $soapOperation = $this->dom->createElementNS(WSDL::SOAP_11_NS_URI, 'operation'); $this->setAttributeWithSanitization($soapOperation, 'soapAction', $soapAction); $binding->insertBefore($soapOperation, $binding->firstChild); @@ -459,18 +477,18 @@ public function addService($name, $portName, $binding, $location) if ($location instanceof Uri) { $location = $location->toString(); } - $service = $this->dom->createElementNS(WSDL::NS_WSDL, 'service'); + $service = $this->dom->createElementNS(WSDL::WSDL_NS_URI, 'service'); $service->setAttribute('name', $name); $this->wsdl->appendChild($service); - $port = $this->dom->createElementNS(WSDL::NS_WSDL, 'port'); + $port = $this->dom->createElementNS(WSDL::WSDL_NS_URI, 'port'); $port->setAttribute('name', $portName); $port->setAttribute('binding', $binding); $service->appendChild($port); - $soapAddress = $this->dom->createElementNS(WSDL::NS_SOAP, 'address'); + $soapAddress = $this->dom->createElementNS(WSDL::SOAP_11_NS_URI, 'address'); $this->setAttributeWithSanitization($soapAddress, 'location', $location); $port->appendChild($soapAddress); @@ -497,7 +515,7 @@ public function addDocumentation($inputNode, $documentation) $node = $inputNode; } - $doc = $this->dom->createElementNS(WSDL::NS_WSDL, 'documentation'); + $doc = $this->dom->createElementNS(WSDL::WSDL_NS_URI, 'documentation'); if ($node->hasChildNodes()) { $node->insertBefore($doc, $node->firstChild); } else { @@ -605,9 +623,7 @@ public function dump($filename = false) return true; } - $i = file_put_contents($filename, $this->toXML()); - - return $i > 0; + return (bool) file_put_contents($filename, $this->toXML()); } /** @@ -621,25 +637,25 @@ public function getType($type) switch (strtolower($type)) { case 'string': case 'str': - return 'xsd:string'; + return Wsdl::XSD_NS . ':string'; case 'long': - return 'xsd:long'; + return Wsdl::XSD_NS . ':long'; case 'int': case 'integer': - return 'xsd:int'; + return Wsdl::XSD_NS . ':int'; case 'float': - return 'xsd:float'; + return Wsdl::XSD_NS . ':float'; case 'double': - return 'xsd:double'; + return Wsdl::XSD_NS . ':double'; case 'boolean': case 'bool': - return 'xsd:boolean'; + return Wsdl::XSD_NS . ':boolean'; case 'array': - return 'soap-enc:Array'; + return Wsdl::SOAP_ENC_NS . ':Array'; case 'object': - return 'xsd:struct'; + return Wsdl::XSD_NS . ':struct'; case 'mixed': - return 'xsd:anyType'; + return Wsdl::XSD_NS . ':anyType'; case 'void': return ''; default: @@ -657,10 +673,10 @@ public function addSchemaTypeSection() { if ($this->schema === null) { - $types = $this->dom->createElementNS(Wsdl::NS_WSDL, 'types'); + $types = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'types'); $this->wsdl->appendChild($types); - $this->schema = $this->dom->createElementNS(WSDL::NS_SCHEMA, 'schema'); + $this->schema = $this->dom->createElementNS(WSDL::XSD_NS_URI, 'schema'); $types->appendChild($this->schema); $this->schema->setAttribute('targetNamespace', $this->getUri()); @@ -724,13 +740,13 @@ private function _parseElement($element) throw new Exception\RuntimeException('The "element" parameter needs to be an associative array.'); } - $elementXML = $this->dom->createElementNS(Wsdl::NS_SCHEMA, 'element'); + $elementXML = $this->dom->createElementNS(Wsdl::XSD_NS_URI, 'element'); foreach ($element as $key => $value) { if (in_array($key, array('sequence', 'all', 'choice'))) { if (is_array($value)) { - $complexType = $this->dom->createElementNS(Wsdl::NS_SCHEMA, 'complexType'); + $complexType = $this->dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType'); if (count($value) > 0) { - $container = $this->dom->createElementNS(Wsdl::NS_SCHEMA, $key); + $container = $this->dom->createElementNS(Wsdl::XSD_NS_URI, $key); foreach ($value as $subElement) { $subElementXML = $this->_parseElement($subElement); $container->appendChild($subElementXML); @@ -832,6 +848,6 @@ public function addElement($element) $schema = $this->getSchema(); $elementXml = $this->_parseElement($element); $schema->appendChild($elementXml); - return 'tns:' . $element['name']; + return Wsdl::TYPES_NS . ':' . $element['name']; } } diff --git a/src/Wsdl/ComplexTypeStrategy/AnyType.php b/src/Wsdl/ComplexTypeStrategy/AnyType.php index ccac34eb..b5637a69 100644 --- a/src/Wsdl/ComplexTypeStrategy/AnyType.php +++ b/src/Wsdl/ComplexTypeStrategy/AnyType.php @@ -13,6 +13,8 @@ * Zend_Soap_Wsdl_Strategy_AnyType * */ +use Zend\Soap\Wsdl; + class AnyType implements ComplexTypeStrategyInterface { /** @@ -31,6 +33,6 @@ public function setContext(\Zend\Soap\Wsdl $context) */ public function addComplexType($type) { - return 'xsd:anyType'; + return Wsdl::XSD_NS . ':anyType'; } } diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php index 414a8669..c5e91fe0 100644 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php @@ -62,7 +62,7 @@ protected function _addArrayOfComplexType($singularType, $type) } $xsdComplexTypeName = 'ArrayOf' . $this->getContext()->translateType($singularType); - $xsdComplexType = 'tns:' . $xsdComplexTypeName; + $xsdComplexType = Wsdl::TYPES_NS . ':' . $xsdComplexTypeName; // Register type here to avoid recursion $this->getContext()->addType($type, $xsdComplexType); @@ -74,26 +74,26 @@ protected function _addArrayOfComplexType($singularType, $type) // Add array type structure to WSDL document $dom = $this->getContext()->toDomDocument(); - $complexType = $dom->createElementNS(Wsdl::NS_SCHEMA, 'complexType'); + $complexType = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType'); $this->getContext()->getSchema()->appendChild($complexType); $complexType->setAttribute('name', $xsdComplexTypeName); - $complexContent = $dom->createElementNS(Wsdl::NS_SCHEMA, 'complexContent'); + $complexContent = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexContent'); $complexType->appendChild($complexContent); - $xsdRestriction = $dom->createElementNS(Wsdl::NS_SCHEMA, 'restriction'); - $xsdRestriction->setAttribute('base', 'soap-enc:Array'); + $xsdRestriction = $dom->createElementNS(Wsdl::XSD_NS_URI, 'restriction'); + $xsdRestriction->setAttribute('base', Wsdl::SOAP_ENC_NS . ':Array'); $complexContent->appendChild($xsdRestriction); - $xsdAttribute = $dom->createElementNS(Wsdl::NS_SCHEMA, 'attribute'); + $xsdAttribute = $dom->createElementNS(Wsdl::XSD_NS_URI, 'attribute'); $xsdRestriction->appendChild($xsdAttribute); - $xsdAttribute->setAttribute('ref', 'soap-enc:arrayType'); + $xsdAttribute->setAttribute('ref', Wsdl::SOAP_ENC_NS . ':arrayType'); $xsdAttribute->setAttributeNS( - Wsdl::NS_WSDL, + Wsdl::WSDL_NS_URI, 'arrayType', - 'tns:' . $this->getContext()->translateType($singularType) . '[]' + Wsdl::TYPES_NS . ':' . $this->getContext()->translateType($singularType) . '[]' ); return $xsdComplexType; diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php index 5e033b0c..df14d595 100644 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php @@ -65,7 +65,7 @@ protected function _getTypeBasedOnNestingLevel($singularType, $level) return $this->getContext()->getType($singularType); } - return 'tns:' . str_repeat('ArrayOf', $level) . ucfirst($this->getContext()->translateType($singularType)); + return Wsdl::TYPES_NS . ':' . str_repeat('ArrayOf', $level) . ucfirst($this->getContext()->translateType($singularType)); } /** @@ -112,13 +112,13 @@ protected function _addSequenceType($arrayType, $childType, $phpArrayType) $arrayTypeName = substr($arrayType, strpos($arrayType, ':') + 1); - $complexType = $dom->createElementNS(Wsdl::NS_SCHEMA, 'complexType'); + $complexType = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType'); $complexType->setAttribute('name', $arrayTypeName); - $sequence = $dom->createElementNS(Wsdl::NS_SCHEMA, 'sequence'); + $sequence = $dom->createElementNS(Wsdl::XSD_NS_URI, 'sequence'); $complexType->appendChild($sequence); - $element = $dom->createElementNS(Wsdl::NS_SCHEMA, 'element'); + $element = $dom->createElementNS(Wsdl::XSD_NS_URI, 'element'); $sequence->appendChild($element); $element->setAttribute('name', 'item'); diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php index 85f4aa5c..a5080f13 100644 --- a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php +++ b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php @@ -42,7 +42,7 @@ public function addComplexType($type) $class = new \ReflectionClass($type); $soapTypeName = $this->getContext()->translateType($type); - $soapType = 'tns:' . $soapTypeName; + $soapType = Wsdl::TYPES_NS . ':' . $soapTypeName; // Register type here to avoid recursion $this->getContext()->addType($type, $soapType); @@ -50,10 +50,10 @@ public function addComplexType($type) $defaultProperties = $class->getDefaultProperties(); - $complexType = $dom->createElementNS(Wsdl::NS_SCHEMA, 'complexType'); + $complexType = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType'); $complexType->setAttribute('name', $soapTypeName); - $all = $dom->createElementNS(Wsdl::NS_SCHEMA, 'all'); + $all = $dom->createElementNS(Wsdl::XSD_NS_URI, 'all'); foreach ($class->getProperties() as $property) { if ($property->isPublic() @@ -65,7 +65,7 @@ public function addComplexType($type) * compatible with using 'complexType' node for describing other * classes used as attribute types for current class */ - $element = $dom->createElementNS(Wsdl::NS_SCHEMA, 'element'); + $element = $dom->createElementNS(Wsdl::XSD_NS_URI, 'element'); $element->setAttribute('name', $propertyName = $property->getName()); $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0]))); diff --git a/test/AutoDiscoverTest.php b/test/AutoDiscoverTest.php index edac2a98..d02f1ab1 100644 --- a/test/AutoDiscoverTest.php +++ b/test/AutoDiscoverTest.php @@ -82,14 +82,14 @@ public function bindWsdl(Wsdl $wsdl, $documentNamespace = null) $this->xpath = new \DOMXPath($this->dom); - $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); + $this->xpath->registerNamespace('unittest', Wsdl::WSDL_NS_URI); $this->xpath->registerNamespace('tns', $documentNamespace); - $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); - $this->xpath->registerNamespace('soap12', Wsdl::NS_SOAP12); - $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); - $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); - $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + $this->xpath->registerNamespace('soap', Wsdl::SOAP_11_NS_URI); + $this->xpath->registerNamespace('soap12', Wsdl::SOAP_12_NS_URI); + $this->xpath->registerNamespace('xsd', Wsdl::XSD_NS_URI); + $this->xpath->registerNamespace('soap-enc', Wsdl::SOAP_ENC_URI); + $this->xpath->registerNamespace('wsdl', Wsdl::WSDL_NS_URI); } /** @@ -1456,6 +1456,22 @@ public function testRecursiveWsdlDependencies() $this->testDocumentNodes(); } + /** + * @runInSeparateProcess + */ + public function testHandle() + { + $scriptUri = 'http://localhost/MyService.php'; + + $this->server->setClass('\ZendTest\Soap\TestAsset\Test'); + + ob_start(); + $this->server->handle(); + $actualWsdl = ob_get_clean(); + $this->assertNotEmpty($actualWsdl, "WSDL content was not outputted."); + $this->assertContains($scriptUri, $actualWsdl, "Script URL was not found in WSDL content."); + } + /** * @param int $n * @param string $xpath diff --git a/test/Wsdl/ArrayOfTypeComplexStrategyTest.php b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php index d104eec0..289951f0 100644 --- a/test/Wsdl/ArrayOfTypeComplexStrategyTest.php +++ b/test/Wsdl/ArrayOfTypeComplexStrategyTest.php @@ -79,7 +79,7 @@ public function testArrayOfSimpleObject() $this->assertEquals('soap-enc:arrayType', $nodes->item(0)->getAttribute('ref'), 'Invalid attribute reference value in complex type.' ); - $this->assertEquals('tns:ComplexTest[]', $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), + $this->assertEquals('tns:ComplexTest[]', $nodes->item(0)->getAttributeNS(Wsdl::WSDL_NS_URI, 'arrayType'), 'Invalid array type reference.' ); @@ -135,7 +135,7 @@ public function testArrayOfComplexObjects() 'Invalid attribute reference value in complex type.' ); $this->assertEquals('tns:ComplexObjectStructure[]', - $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), + $nodes->item(0)->getAttributeNS(Wsdl::WSDL_NS_URI, 'arrayType'), 'Invalid array type reference.' ); @@ -187,7 +187,7 @@ public function testArrayOfObjectWithObject() 'Invalid attribute reference value in complex type.' ); $this->assertEquals('tns:ComplexObjectWithObjectStructure[]', - $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), + $nodes->item(0)->getAttributeNS(Wsdl::WSDL_NS_URI, 'arrayType'), 'Invalid array type reference.' ); @@ -203,7 +203,7 @@ public function testAddingTypesMultipleTimesIsSavedOnlyOnce() $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); // this xpath is proper version of simpler: //*[wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"] - namespaces in attributes and xpath - $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::NS_WSDL + $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::WSDL_NS_URI .'" and local-name()="arrayType"]="tns:ComplexObjectWithObjectStructure[]"]' ); $this->assertEquals(1, $nodes->length, @@ -230,7 +230,7 @@ public function testAddingSingularThenArrayTypeIsRecognizedCorretly() $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\ComplexObjectWithObjectStructure[]'); // this xpath is proper version of simpler: //*[wsdl:arrayType="tns:ComplexObjectWithObjectStructure[]"] - namespaces in attributes and xpath - $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::NS_WSDL. + $nodes = $this->xpath->query('//*[@*[namespace-uri()="'.Wsdl::WSDL_NS_URI. '" and local-name()="arrayType"]="tns:ComplexObjectWithObjectStructure[]"]' ); $this->assertEquals(1, $nodes->length, @@ -307,7 +307,7 @@ public function testArrayOfComplexNestedObjectsIsCoveredByStrategyAndAddsAllType 'Invalid attribute reference value in complex type.' ); $this->assertEquals('tns:ComplexTypeB[]', - $nodes->item(0)->getAttributeNS(Wsdl::NS_WSDL, 'arrayType'), + $nodes->item(0)->getAttributeNS(Wsdl::WSDL_NS_URI, 'arrayType'), 'Invalid array type reference.' ); diff --git a/test/WsdlTest.php b/test/WsdlTest.php index b9ba7f7b..2f729622 100644 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -27,16 +27,16 @@ class WsdlTest extends WsdlTestHelper function testConstructor() { - $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri(null)); - $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); - $this->assertEquals(Wsdl::NS_SOAP12, $this->dom->lookupNamespaceUri('soap12')); + $this->assertEquals(Wsdl::WSDL_NS_URI, $this->dom->lookupNamespaceUri(null)); + $this->assertEquals(Wsdl::SOAP_11_NS_URI, $this->dom->lookupNamespaceUri('soap')); + $this->assertEquals(Wsdl::SOAP_12_NS_URI, $this->dom->lookupNamespaceUri('soap12')); $this->assertEquals($this->defaultServiceUri, $this->dom->lookupNamespaceUri('tns')); - $this->assertEquals(Wsdl::NS_SOAP, $this->dom->lookupNamespaceUri('soap')); - $this->assertEquals(Wsdl::NS_SCHEMA, $this->dom->lookupNamespaceUri('xsd')); - $this->assertEquals(Wsdl::NS_S_ENC, $this->dom->lookupNamespaceUri('soap-enc')); - $this->assertEquals(Wsdl::NS_WSDL, $this->dom->lookupNamespaceUri('wsdl')); + $this->assertEquals(Wsdl::SOAP_11_NS_URI, $this->dom->lookupNamespaceUri('soap')); + $this->assertEquals(Wsdl::XSD_NS_URI, $this->dom->lookupNamespaceUri('xsd')); + $this->assertEquals(Wsdl::SOAP_ENC_URI, $this->dom->lookupNamespaceUri('soap-enc')); + $this->assertEquals(Wsdl::WSDL_NS_URI, $this->dom->lookupNamespaceUri('wsdl')); - $this->assertEquals(Wsdl::NS_WSDL, $this->dom->documentElement->namespaceURI); + $this->assertEquals(Wsdl::WSDL_NS_URI, $this->dom->documentElement->namespaceURI); $this->assertEquals($this->defaultServiceName, $this->dom->documentElement->getAttribute('name')); $this->assertEquals($this->defaultServiceUri, $this->dom->documentElement->getAttribute('targetNamespace')); @@ -719,7 +719,7 @@ function testAddComplexType() public function testAddTypesFromDocument() { $dom = new \DOMDocument(); - $types = $dom->createElementNS(WSDL::NS_WSDL, 'types'); + $types = $dom->createElementNS(WSDL::WSDL_NS_URI, 'types'); $dom->appendChild($types); $this->wsdl->addTypes($dom); @@ -732,7 +732,7 @@ public function testAddTypesFromDocument() public function testAddTypesFromNode() { - $dom = $this->dom->createElementNS(WSDL::NS_WSDL, 'types'); + $dom = $this->dom->createElementNS(WSDL::WSDL_NS_URI, 'types'); $this->wsdl->addTypes($dom); diff --git a/test/WsdlTestHelper.php b/test/WsdlTestHelper.php index 2aae3ef6..6c2a8491 100644 --- a/test/WsdlTestHelper.php +++ b/test/WsdlTestHelper.php @@ -85,14 +85,14 @@ public function registerNamespaces($obj, $documentNamespace = null) } $this->xpath = new \DOMXPath($obj); - $this->xpath->registerNamespace('unittest', Wsdl::NS_WSDL); + $this->xpath->registerNamespace('unittest', Wsdl::WSDL_NS_URI); $this->xpath->registerNamespace('tns', $documentNamespace); - $this->xpath->registerNamespace('soap', Wsdl::NS_SOAP); - $this->xpath->registerNamespace('soap12', Wsdl::NS_SOAP12); - $this->xpath->registerNamespace('xsd', Wsdl::NS_SCHEMA); - $this->xpath->registerNamespace('soap-enc', Wsdl::NS_S_ENC); - $this->xpath->registerNamespace('wsdl', Wsdl::NS_WSDL); + $this->xpath->registerNamespace('soap', Wsdl::SOAP_11_NS_URI); + $this->xpath->registerNamespace('soap12', Wsdl::SOAP_12_NS_URI); + $this->xpath->registerNamespace('xsd', Wsdl::XSD_NS_URI); + $this->xpath->registerNamespace('soap-enc', Wsdl::SOAP_ENC_URI); + $this->xpath->registerNamespace('wsdl', Wsdl::WSDL_NS_URI); return $obj; } From ebadea9f0e3a722e2ac4f7a74c9504adbc7417c9 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Fri, 1 Mar 2013 16:02:49 +0100 Subject: [PATCH 15/22] Restored missing function from AutoDiscover Code style and reformat --- src/AutoDiscover.php | 83 ++--- .../DiscoveryStrategy/ReflectionDiscovery.php | 30 ++ src/Client.php | 133 ++++---- src/Client/Common.php | 20 +- src/Client/DotNet.php | 25 +- src/Client/Local.php | 7 +- src/Exception/BadMethodCallException.php | 1 - src/Server.php | 90 +++--- src/Server/DocumentLiteralWrapper.php | 35 ++- src/Wsdl.php | 288 ++++++++++++------ .../AbstractComplexTypeStrategy.php | 13 +- src/Wsdl/ComplexTypeStrategy/AnyType.php | 7 +- .../ArrayOfTypeComplex.php | 8 +- .../ArrayOfTypeSequence.php | 11 +- .../ComplexTypeStrategyInterface.php | 1 + src/Wsdl/ComplexTypeStrategy/Composite.php | 30 +- .../DefaultComplexType.php | 7 +- test/WsdlTest.php | 206 ++++++------- 18 files changed, 602 insertions(+), 393 deletions(-) diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php index 99a251d4..a0e9845f 100644 --- a/src/AutoDiscover.php +++ b/src/AutoDiscover.php @@ -10,10 +10,9 @@ namespace Zend\Soap; use Zend\Server\Reflection; -use Zend\Server\Reflection\AbstractFunction; use Zend\Soap\AutoDiscover\DiscoveryStrategy\DiscoveryStrategyInterface as DiscoveryStrategy; use Zend\Soap\AutoDiscover\DiscoveryStrategy\ReflectionDiscovery; -use Zend\Soap\Exception\InvalidArgumentException; +use Zend\Soap\Exception; use Zend\Soap\Wsdl; use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy; use Zend\Uri; @@ -36,14 +35,12 @@ class AutoDiscover /** * Service function names - * * @var array */ protected $functions = array(); /** * Service class name - * * @var string */ protected $class; @@ -55,14 +52,12 @@ class AutoDiscover /** * Url where the WSDL file will be available at. - * * @var WSDL Uri */ protected $uri; /** * soap:body operation style options - * * @var array */ protected $operationBodyStyle = array( @@ -72,7 +67,6 @@ class AutoDiscover /** * soap:operation style - * * @var array */ protected $bindingStyle = array( @@ -82,21 +76,18 @@ class AutoDiscover /** * Name of the class to handle the WSDL creation. - * * @var string */ protected $wsdlClass = 'Zend\Soap\Wsdl'; /** * Class Map of PHP to WSDL types. - * * @var array */ protected $classMap = array(); /** * Discovery strategy for types and other method details. - * * @var DiscoveryStrategy */ protected $discoveryStrategy; @@ -109,9 +100,8 @@ class AutoDiscover * @param string $wsdlClass * @param array $classMap */ - public function __construct(ComplexTypeStrategy $strategy = null, - $endpointUri=null, $wsdlClass=null, array $classMap = array() - ) { + public function __construct(ComplexTypeStrategy $strategy = null, $endpointUri = null, $wsdlClass = null, array $classMap = array()) + { $this->reflection = new Reflection(); $this->setDiscoveryStrategy(new ReflectionDiscovery()); @@ -132,15 +122,19 @@ public function __construct(ComplexTypeStrategy $strategy = null, * Set the discovery strategy for method type and other information. * * @param DiscoveryStrategy $discoveryStrategy + * * @return AutoDiscover */ public function setDiscoveryStrategy(DiscoveryStrategy $discoveryStrategy) { $this->discoveryStrategy = $discoveryStrategy; + return $this; } /** + * Get the discovery strategy. + * * @return DiscoveryStrategy */ public function getDiscoveryStrategy() @@ -149,7 +143,7 @@ public function getDiscoveryStrategy() } /** - * Get the class map of php to wsdl qname types. + * Get the class map of php to wsdl mappings. * * @return array */ @@ -159,11 +153,14 @@ public function getClassMap() } /** - * Set the class map of php to wsdl qname types. + * Set the class map of php to wsdl mappings. + * + * @return AutoDiscover */ public function setClassMap($classMap) { $this->classMap = $classMap; + return $this; } @@ -172,17 +169,20 @@ public function setClassMap($classMap) * * @param string $serviceName * @throws Exception\InvalidArgumentException + * * @return AutoDiscover */ public function setServiceName($serviceName) { $matches = array(); + // first character must be letter or underscore {@see http://www.w3.org/TR/wsdl#_document-n} $i = preg_match('/^[a-z\_]/ims', $serviceName, $matches); if ($i != 1) { - throw new InvalidArgumentException('XML NCName and Service Name must start with letter or _'); + throw new Exception\InvalidArgumentException('Service Name must start with letter or _'); } $this->serviceName = $serviceName; + return $this; } @@ -190,6 +190,7 @@ public function setServiceName($serviceName) * Get service name * * @throws Exception\RuntimeException + * * @return string */ public function getServiceName() @@ -198,7 +199,7 @@ public function getServiceName() if ($this->class) { return $this->reflection->reflectClass($this->class)->getShortName(); } else { - throw new Exception\RuntimeException('No service name given. Call Autodiscover::setServiceName().'); + throw new Exception\RuntimeException('No service name given. Call AutoDiscover::setServiceName().'); } } @@ -207,10 +208,11 @@ public function getServiceName() /** - * Set the location at which the WSDL file will be availabe. + * Set the location at which the WSDL file will be available. * * @param Uri\Uri|string $uri * @throws Exception\InvalidArgumentException + * * @return AutoDiscover */ public function setUri($uri) @@ -225,7 +227,7 @@ public function setUri($uri) $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); if (empty($uri)) { - throw new InvalidArgumentException('Uri contains invalid characters or is empty'); + throw new Exception\InvalidArgumentException('Uri contains invalid characters or is empty'); } $this->uri = $uri; @@ -237,6 +239,7 @@ public function setUri($uri) * Return the current Uri that the SOAP WSDL Service will be located at. * * @throws Exception\RuntimeException + * * @return Uri\Uri */ public function getUri() @@ -258,6 +261,7 @@ public function getUri() * * @param string $wsdlClass * @throws Exception\InvalidArgumentException + * * @return AutoDiscover */ public function setWsdlClass($wsdlClass) @@ -291,6 +295,7 @@ public function getWsdlClass() * * @param array $operationStyle * @throws Exception\InvalidArgumentException + * * @return AutoDiscover */ public function setOperationBodyStyle(array $operationStyle=array()) @@ -299,6 +304,7 @@ public function setOperationBodyStyle(array $operationStyle=array()) throw new Exception\InvalidArgumentException('Key "use" is required in Operation soap:body style.'); } $this->operationBodyStyle = $operationStyle; + return $this; } @@ -308,6 +314,7 @@ public function setOperationBodyStyle(array $operationStyle=array()) * By default 'style' is 'rpc' and 'transport' is 'http://schemas.xmlsoap.org/soap/http'. * * @param array $bindingStyle + * * @return AutoDiscover */ public function setBindingStyle(array $bindingStyle=array()) @@ -318,6 +325,7 @@ public function setBindingStyle(array $bindingStyle=array()) if (isset($bindingStyle['transport'])) { $this->bindingStyle['transport'] = $bindingStyle['transport']; } + return $this; } @@ -325,6 +333,7 @@ public function setBindingStyle(array $bindingStyle=array()) * Set the strategy that handles functions and classes that are added AFTER this call. * * @param ComplexTypeStrategy $strategy + * * @return AutoDiscover */ public function setComplexTypeStrategy(ComplexTypeStrategy $strategy) @@ -338,6 +347,7 @@ public function setComplexTypeStrategy(ComplexTypeStrategy $strategy) * Set the Class the SOAP server will use * * @param string $class Class Name + * * @return AutoDiscover */ public function setClass($class) @@ -352,6 +362,7 @@ public function setClass($class) * * @param string $function Function Name * @throws Exception\InvalidArgumentException + * * @return AutoDiscover */ public function addFunction($function) @@ -407,6 +418,7 @@ protected function _generateFunctions() * Generate the WSDL for a set of reflection method instances. * * @param array $reflectionMethods + * * @return Wsdl */ protected function _generateWsdl(array $reflectionMethods) @@ -424,12 +436,8 @@ protected function _generateWsdl(array $reflectionMethods) $port = $wsdl->addPortType($serviceName . 'Port'); $binding = $wsdl->addBinding($serviceName . 'Binding', Wsdl::TYPES_NS . ':' . $serviceName . 'Port'); - $wsdl->addSoapBinding($binding, $this->bindingStyle['style'], - $this->bindingStyle['transport'] - ); - $wsdl->addService($serviceName . 'Service', $serviceName . 'Port', - Wsdl::TYPES_NS . ':' . $serviceName . 'Binding', $uri - ); + $wsdl->addSoapBinding($binding, $this->bindingStyle['style'], $this->bindingStyle['transport']); + $wsdl->addService($serviceName . 'Service', $serviceName . 'Port', Wsdl::TYPES_NS . ':' . $serviceName . 'Binding', $uri); foreach ($reflectionMethods as $method) { $this->_addFunctionToWsdl($method, $wsdl, $port, $binding); @@ -442,10 +450,11 @@ protected function _generateWsdl(array $reflectionMethods) * Add a function to the WSDL document. * * @param $function \Zend\Server\Reflection\AbstractFunction function to add - * @param $wsdl \Zend\Soap\Wsdl WSDL document - * @param $port object wsdl:portType - * @param $binding object wsdl:binding + * @param $wsdl \Zend\Soap\Wsdl WSDL document + * @param $port \DOMElement wsdl:portType + * @param $binding \DOMElement wsdl:binding * @throws Exception\InvalidArgumentException + * * @return void */ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) @@ -476,6 +485,7 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) if ($this->bindingStyle['style'] == 'document') { // Document style: wrap all parameters in a sequence element $sequence = array(); + /** @var $param Reflection\ReflectionParameter */ foreach ($prototype->getParameters() as $param) { $sequenceElement = array( 'name' => $param->getName(), @@ -497,7 +507,7 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) } else { // RPC style: add each parameter as a typed part - /** @var $param \Zend\Server\Reflection\ReflectionParameter */ + /** @var $param Reflection\ReflectionParameter */ foreach ($prototype->getParameters() as $param) { $args[$param->getName()] = array( 'type' => $wsdl->getType($this->discoveryStrategy->getFunctionParameterType($param)) @@ -517,9 +527,7 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) if ($prototype->getReturnType() != "void") { $sequence[] = array( 'name' => $functionName . 'Result', - 'type' => $wsdl->getType( - $this->discoveryStrategy->getFunctionReturnType($function, $prototype) - ) + 'type' => $wsdl->getType($this->discoveryStrategy->getFunctionReturnType($function, $prototype)) ); } @@ -570,9 +578,7 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) // Add the binding operation if ($isOneWayMessage == false) { - $operation = $wsdl->addBindingOperation($binding, $functionName, - $operationBodyStyle, $operationBodyStyle - ); + $operation = $wsdl->addBindingOperation($binding, $functionName, $operationBodyStyle, $operationBodyStyle); } else { $operation = $wsdl->addBindingOperation($binding, $functionName, $operationBodyStyle); } @@ -583,6 +589,7 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) * Generate the WSDL file from the configured input. * * @throws Exception\RuntimeException + * * @return Wsdl */ public function generate() @@ -604,8 +611,9 @@ public function generate() * Proxy to WSDL dump function * * @param string $filename - * @return bool * @throws \Zend\Soap\Exception\RuntimeException + * + * @return bool */ public function dump($filename) { @@ -615,8 +623,9 @@ public function dump($filename) /** * Proxy to WSDL toXml() function * - * @return string * @throws \Zend\Soap\Exception\RuntimeException + * + * @return string */ public function toXml() { diff --git a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php index b9f4ff97..981e3fd9 100644 --- a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php +++ b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php @@ -21,21 +21,51 @@ class ReflectionDiscovery implements DiscoveryStrategyInterface { + /** + * Returns description from phpdoc block + * + * @param \Zend\Server\Reflection\AbstractFunction $function + * + * @return string + */ public function getFunctionDocumentation(AbstractFunction $function) { return $function->getDescription(); } + /** + * Return parameter type + * + * @param \Zend\Server\Reflection\ReflectionParameter $param + * + * @return string + */ public function getFunctionParameterType(ReflectionParameter $param) { return $param->getType(); } + /** + * Return function return type + * + * @param \Zend\Server\Reflection\AbstractFunction $function + * @param \Zend\Server\Reflection\Prototype $prototype + * + * @return string + */ public function getFunctionReturnType(AbstractFunction $function, Prototype $prototype) { return $prototype->getReturnType(); } + /** + * Return true if function is one way (return nothing) + * + * @param \Zend\Server\Reflection\AbstractFunction $function + * @param \Zend\Server\Reflection\Prototype $prototype + * + * @return bool + */ public function isFunctionOneWay(AbstractFunction $function, Prototype $prototype) { return $prototype->getReturnType() == 'void'; diff --git a/src/Client.php b/src/Client.php index 0b7ffed7..8e7a891c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -11,7 +11,6 @@ use SoapClient; use SoapHeader; -use Traversable; use Zend\Server\Client as ServerClient; use Zend\Stdlib\ArrayUtils; @@ -45,7 +44,9 @@ class Client implements ServerClient */ protected $soapVersion = SOAP_1_2; - /** Set of other SoapClient options */ + /**#@+ + * @var string + */ protected $uri = null; protected $location = null; protected $style = null; @@ -58,59 +59,57 @@ class Client implements ServerClient protected $proxyPassword = null; protected $localCert = null; protected $passphrase = null; - protected $compression = null; protected $connectionTimeout = null; protected $streamContext = null; - protected $features = null; - protected $cacheWsdl = null; protected $userAgent = null; + /**#@-*/ + + /**#@+ + * @var int + */ + protected $cacheWsdl = null; + protected $features = null; + protected $compression = null; + /**#@-*/ + + /** + * @var array + */ protected $typemap = null; /** * WSDL used to access server * It also defines Client working mode (WSDL vs non-WSDL) - * * @var string */ protected $wsdl = null; /** * SoapClient object - * * @var SoapClient */ protected $soapClient; /** * Last invoked method - * * @var string */ protected $lastMethod = ''; /** - * SOAP request headers. - * * Array of SoapHeader objects - * * @var array */ protected $soapInputHeaders = array(); /** * Permanent SOAP request headers (shared between requests). - * - * Array of SoapHeader objects - * * @var array */ protected $permanentSoapInputHeaders = array(); /** - * Output SOAP headers. - * * Array of SoapHeader objects - * * @var array */ protected $soapOutputHeaders = array(); @@ -140,6 +139,7 @@ public function __construct($wsdl = null, $options = null) * Set wsdl * * @param string $wsdl + * * @return Client */ public function setWSDL($wsdl) @@ -172,7 +172,7 @@ public function getWSDL() */ public function setOptions($options) { - if ($options instanceof Traversable) { + if ($options instanceof \Traversable) { $options = ArrayUtils::iteratorToArray($options); } @@ -182,64 +182,84 @@ public function setOptions($options) case 'class_map': $this->setClassmap($value); break; + case 'encoding': $this->setEncoding($value); break; + case 'soapVersion': case 'soap_version': $this->setSoapVersion($value); break; + case 'wsdl': $this->setWSDL($value); break; + case 'uri': $this->setUri($value); break; + case 'location': $this->setLocation($value); break; + case 'style': $this->setStyle($value); break; + case 'use': $this->setEncodingMethod($value); break; + case 'login': $this->setHttpLogin($value); break; + case 'password': $this->setHttpPassword($value); break; + case 'proxy_host': $this->setProxyHost($value); break; + case 'proxy_port': $this->setProxyPort($value); break; + case 'proxy_login': $this->setProxyLogin($value); break; + case 'proxy_password': $this->setProxyPassword($value); break; + case 'local_cert': $this->setHttpsCertificate($value); break; + case 'passphrase': $this->setHttpsCertPassphrase($value); break; + case 'compression': $this->setCompressionOptions($value); break; + case 'stream_context': $this->setStreamContext($value); break; + case 'features': $this->setSoapFeatures($value); break; + case 'cache_wsdl': $this->setWSDLCache($value); break; + case 'useragent': case 'user_agent': $this->setUserAgent($value); @@ -381,6 +401,8 @@ public function getClassmap() } /** + * Set typemap with xml to php type mappings with appropriate validation. + * * @param array $typeMap * @throws Exception\InvalidArgumentException * @@ -390,14 +412,10 @@ public function setTypemap(array $typeMap) { foreach ($typeMap as $type) { if (!is_callable($type['from_xml'])) { - throw new Exception\InvalidArgumentException( - 'Invalid from_xml callback for type: ' . $type['type_name'] - ); + throw new Exception\InvalidArgumentException('Invalid from_xml callback for type: ' . $type['type_name']); } if (!is_callable($type['to_xml'])) { - throw new Exception\InvalidArgumentException( - 'Invalid to_xml callback for type: ' . $type['type_name'] - ); + throw new Exception\InvalidArgumentException('Invalid to_xml callback for type: ' . $type['type_name']); } } @@ -596,6 +614,7 @@ public function getEncodingMethod() * Set HTTP login * * @param string $login + * * @return Client */ public function setHttpLogin($login) @@ -621,6 +640,7 @@ public function getHttpLogin() * Set HTTP password * * @param string $password + * * @return Client */ public function setHttpPassword($password) @@ -646,6 +666,7 @@ public function getHttpPassword() * Set proxy host * * @param string $proxyHost + * * @return Client */ public function setProxyHost($proxyHost) @@ -671,6 +692,7 @@ public function getProxyHost() * Set proxy port * * @param int $proxyPort + * * @return Client */ public function setProxyPort($proxyPort) @@ -696,6 +718,7 @@ public function getProxyPort() * Set proxy login * * @param string $proxyLogin + * * @return Client */ public function setProxyLogin($proxyLogin) @@ -721,6 +744,7 @@ public function getProxyLogin() * Set proxy password * * @param string $proxyPassword + * * @return Client */ public function setProxyPassword($proxyPassword) @@ -767,6 +791,7 @@ public function getHttpsCertificate() * Set HTTPS client certificate passphrase * * @param string $passphrase + * * @return Client */ public function setHttpsCertPassphrase($passphrase) @@ -842,6 +867,7 @@ public function setStreamContext($context) } $this->streamContext = $context; + return $this; } @@ -859,6 +885,7 @@ public function getStreamContext() * Set the SOAP Feature options. * * @param string|int $feature + * * @return Client */ public function setSoapFeatures($feature) @@ -866,6 +893,7 @@ public function setSoapFeatures($feature) $this->features = $feature; $this->soapClient = null; + return $this; } @@ -883,15 +911,18 @@ public function getSoapFeatures() * Set the SOAP WSDL Caching Options * * @param string|int|bool|null $caching + * * @return Client */ public function setWSDLCache($caching) { + //@todo check WSDL_CACHE_* constants? if ($caching === null) { $this->cacheWsdl = null; } else { $this->cacheWsdl = (int) $caching; } + return $this; } @@ -919,6 +950,7 @@ public function setUserAgent($userAgent) } else { $this->userAgent = (string) $userAgent; } + return $this; } @@ -1010,29 +1042,16 @@ public function getLastMethod() * @param string $action * @param int $version * @param int $oneWay + * * @return mixed */ - public function _doRequest(Client\Common $client, $request, $location, - $action, $version, $oneWay = null - ) { + public function _doRequest(Client\Common $client, $request, $location,$action, $version, $oneWay = null) + { // Perform request as is if ($oneWay === null) { - return call_user_func( - array($client, 'SoapClient::__doRequest'), - $request, - $location, - $action, - $version - ); + return call_user_func(array($client, 'SoapClient::__doRequest'), $request, $location, $action, $version); } - return call_user_func( - array($client, 'SoapClient::__doRequest'), - $request, - $location, - $action, - $version, - $oneWay - ); + return call_user_func(array($client, 'SoapClient::__doRequest'), $request, $location, $action, $version, $oneWay); } /** @@ -1072,6 +1091,7 @@ protected function _initSoapClientObject() * My be overridden in descendant classes * * @param array $arguments + * * @return array */ protected function _preProcessArguments($arguments) @@ -1086,6 +1106,7 @@ protected function _preProcessArguments($arguments) * My be overridden in descendant classes * * @param array $result + * * @return array */ protected function _preProcessResult($result) @@ -1098,7 +1119,8 @@ protected function _preProcessResult($result) * Add SOAP input header * * @param SoapHeader $header - * @param bool $permanent + * @param bool $permanent + * * @return Client */ public function addSoapInputHeader(SoapHeader $header, $permanent = false) @@ -1140,6 +1162,7 @@ public function getLastSoapOutputHeaderObjects() * * @param string $name * @param array $arguments + * * @return mixed */ public function __call($name, $arguments) @@ -1171,6 +1194,7 @@ public function __call($name, $arguments) * * @param string $method Name of the method we want to call. * @param array $params List of parameters for the method. + * * @return mixed Returned results. */ public function call($method, $params = array()) @@ -1181,8 +1205,9 @@ public function call($method, $params = array()) /** * Return a list of available functions * + * @throws Exception\UnexpectedValueException + * * @return array - * @throws Exception\ExceptionInterface */ public function getFunctions() { @@ -1191,21 +1216,16 @@ public function getFunctions() } $soapClient = $this->getSoapClient(); + return $soapClient->__getFunctions(); } - - /** - * Get used types. - * - * @return array - */ - /** * Return a list of SOAP types * + * @throws Exception\UnexpectedValueException + * * @return array - * @throws Exception\ExceptionInterface */ public function getTypes() { @@ -1219,6 +1239,8 @@ public function getTypes() } /** + * Set SoapClient object + * * @param SoapClient $soapClient * * @return Client @@ -1226,10 +1248,13 @@ public function getTypes() public function setSoapClient(SoapClient $soapClient) { $this->soapClient = $soapClient; + return $this; } /** + * Get SoapClient object + * * @return SoapClient */ public function getSoapClient() @@ -1237,10 +1262,13 @@ public function getSoapClient() if ($this->soapClient == null) { $this->_initSoapClientObject(); } + return $this->soapClient; } /** + * Set cookie + * * @param string $cookieName * @param string $cookieValue * @@ -1250,6 +1278,7 @@ public function setCookie($cookieName, $cookieValue=null) { $soapClient = $this->getSoapClient(); $soapClient->__setCookie($cookieName, $cookieValue); + return $this; } } diff --git a/src/Client/Common.php b/src/Client/Common.php index f9333780..bdc06dcf 100644 --- a/src/Client/Common.php +++ b/src/Client/Common.php @@ -46,30 +46,16 @@ public function __construct($doRequestCallback, $wsdl, $options) * @param string $action * @param int $version * @param int $oneWay + * * @return mixed */ public function __doRequest($request, $location, $action, $version, $oneWay = null) { if ($oneWay === null) { - return call_user_func( - $this->doRequestCallback, - $this, - $request, - $location, - $action, - $version - ); + return call_user_func($this->doRequestCallback, $this, $request, $location, $action, $version); } - return call_user_func( - $this->doRequestCallback, - $this, - $request, - $location, - $action, - $version, - $oneWay - ); + return call_user_func( $this->doRequestCallback, $this, $request, $location, $action, $version, $oneWay); } } diff --git a/src/Client/DotNet.php b/src/Client/DotNet.php index 3525dc99..0c93a969 100644 --- a/src/Client/DotNet.php +++ b/src/Client/DotNet.php @@ -26,35 +26,30 @@ class DotNet extends SOAPClient { /** * Curl HTTP client adapter. - * * @var \Zend\Http\Client\Adapter\Curl */ private $curlClient = null; /** * The last request headers. - * * @var string */ private $lastRequestHeaders = ''; /** * The last response headers. - * * @var string */ private $lastResponseHeaders = ''; /** * SOAP client options. - * * @var array */ private $options = array(); /** * Should NTLM authentication be used? - * * @var boolean */ private $useNtlm = false; @@ -81,13 +76,14 @@ public function __construct($wsdl = null, $options = null) * @param string $location The SOAP URI. * @param string $action The SOAP action to call. * @param integer $version The SOAP version to use. - * @param integer $one_way (Optional) The number 1 if a response is not expected. + * @param integer $oneWay (Optional) The number 1 if a response is not expected. + * * @return string The XML SOAP response. */ - public function _doRequest(CommonClient $client, $request, $location, $action, $version, $one_way = null) + public function _doRequest(CommonClient $client, $request, $location, $action, $version, $oneWay = null) { if (!$this->useNtlm) { - return parent::_doRequest($client, $request, $location, $action, $version, $one_way); + return parent::_doRequest($client, $request, $location, $action, $version, $oneWay); } $curlClient = $this->getCurlClient(); @@ -98,7 +94,7 @@ public function _doRequest(CommonClient $client, $request, $location, $action, $ 'User-Agent' => 'PHP-SOAP-CURL'); $uri = new HttpUri($location); - //@todo use parent set options for ssl certificate authorization + //@todo use parent set* options for ssl certificate authorization $curlClient->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_NTLM) ->setCurlOption(CURLOPT_SSL_VERIFYHOST, false) ->setCurlOption(CURLOPT_SSL_VERIFYPEER, false) @@ -157,11 +153,13 @@ public function getLastResponseHeaders() * Sets the cURL client to use. * * @param CurlClient $curlClient The cURL client. - * @return self Fluent interface. + * + * @return DotNet Fluent interface. */ public function setCurlClient(CurlClient $curlClient) { $this->curlClient = $curlClient; + return $this; } @@ -172,7 +170,8 @@ public function setCurlClient(CurlClient $curlClient) * * @param array|\Traversable $options Options. * @throws \InvalidArgumentException If an unsupported option is passed. - * @return self Fluent interface. + * + * @return \Zend\Soap\Client Fluent interface. */ public function setOptions($options) { @@ -182,6 +181,7 @@ public function setOptions($options) } $this->options = $options; + return parent::setOptions($options); } @@ -192,6 +192,7 @@ public function setOptions($options) * * @param array $arguments * @throws Exception\RuntimeException + * * @return array */ protected function _preProcessArguments($arguments) @@ -214,6 +215,7 @@ protected function _preProcessArguments($arguments) * My be overridden in descendant classes * * @param object $result + * * @return mixed */ protected function _preProcessResult($result) @@ -227,6 +229,7 @@ protected function _preProcessResult($result) * Flattens an HTTP headers array into a string. * * @param array $headers The headers to flatten. + * * @return string The headers string. */ private function flattenHeaders(array $headers) diff --git a/src/Client/Local.php b/src/Client/Local.php index e3404991..d82bd17f 100644 --- a/src/Client/Local.php +++ b/src/Client/Local.php @@ -24,7 +24,6 @@ class Local extends SOAPClient { /** * Server object - * * @var \Zend\Soap\Server */ protected $server; @@ -56,11 +55,11 @@ public function __construct(SOAPServer $server, $wsdl, $options = null) * @param string $action * @param int $version * @param int $oneWay + * * @return mixed */ - public function _doRequest(Common $client, $request, $location, $action, - $version, $oneWay = null - ) { + public function _doRequest(Common $client, $request, $location, $action, $version, $oneWay = null) + { // Perform request as is ob_start(); $this->server->handle($request); diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index eadbf193..74f9f6c8 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -11,7 +11,6 @@ /** * Exception thrown when method is badly called - * */ class BadMethodCallException extends \BadMethodCallException diff --git a/src/Server.php b/src/Server.php index 03b4bfd3..a345b12e 100644 --- a/src/Server.php +++ b/src/Server.php @@ -9,12 +9,7 @@ namespace Zend\Soap; -use DOMDocument; -use DOMNode; -use SimpleXMLElement; use SoapFault; -use stdClass; -use Traversable; use Zend\Stdlib\ArrayUtils; /** @@ -66,14 +61,12 @@ class Server implements \Zend\Server\Server /** * SOAP Server Features - * * @var int */ protected $features; /** * WSDL Caching Options of SOAP Server - * * @var mixed */ protected $wsdlCache; @@ -85,8 +78,7 @@ class Server implements \Zend\Server\Server protected $faultExceptions = array(); /** - * Functions registered with this server; may be either an array or the SOAP_FUNCTIONS_ALL - * constant + * Functions registered with this server; may be either an array or the SOAP_FUNCTIONS_ALL constant * @var array|int */ protected $functions = array(); @@ -110,8 +102,7 @@ class Server implements \Zend\Server\Server protected $response; /** - * Flag: whether or not {@link handle()} should return a response instead - * of automatically emitting it. + * Flag: whether or not {@link handle()} should return a response instead of automatically emitting it. * @var bool */ protected $returnResponse = false; @@ -168,13 +159,13 @@ public function __construct($wsdl = null, array $options = null) * * Allows setting options as an associative array of option => value pairs. * - * @param array|Traversable $options + * @param array|\Traversable $options * * @return \Zend\Soap\Server */ public function setOptions($options) { - if ($options instanceof Traversable) { + if ($options instanceof \Traversable) { $options = ArrayUtils::iteratorToArray($options); } @@ -183,6 +174,7 @@ public function setOptions($options) case 'actor': $this->setActor($value); break; + case 'classmap': case 'class_map': $this->setClassmap($value); @@ -196,16 +188,20 @@ public function setOptions($options) case 'encoding': $this->setEncoding($value); break; + case 'soapversion': case 'soap_version': $this->setSoapVersion($value); break; + case 'uri': $this->setUri($value); break; + case 'wsdl': $this->setWSDL($value); break; + case 'cache_wsdl': $this->setWSDLCache($value); break; @@ -213,6 +209,7 @@ public function setOptions($options) case 'features': $this->setSoapFeatures($value); break; + default: break; } @@ -279,6 +276,7 @@ public function setEncoding($encoding) } $this->encoding = $encoding; + return $this; } @@ -307,6 +305,7 @@ public function setSoapVersion($version) } $this->soapVersion = $version; + return $this; } @@ -426,6 +425,8 @@ public function getClassmap() } /** + * Set typemap with xml to php type mappings with appropriate validation. + * * @param array $typeMap * @throws Exception\InvalidArgumentException * @@ -433,7 +434,6 @@ public function getClassmap() */ public function setTypemap($typeMap) { - if (!is_array($typeMap)) { throw new Exception\InvalidArgumentException('Typemap must be an array'); } @@ -453,6 +453,8 @@ public function setTypemap($typeMap) } /** + * Retrieve typemap + * * @return array */ public function getTypemap() @@ -464,11 +466,13 @@ public function getTypemap() * Set wsdl * * @param string $wsdl URI or path to a WSDL + * * @return Server */ public function setWSDL($wsdl) { $this->wsdl = $wsdl; + return $this; } @@ -486,11 +490,13 @@ public function getWSDL() * Set the SOAP Feature options. * * @param string|int $feature + * * @return Server */ public function setSoapFeatures($feature) { $this->features = $feature; + return $this; } @@ -508,11 +514,13 @@ public function getSoapFeatures() * Set the SOAP WSDL Caching Options * * @param string|int|bool $options + * * @return Server */ public function setWSDLCache($options) { $this->wsdlCache = $options; + return $this; } @@ -530,8 +538,9 @@ public function getWSDLCache() * @param array|string $function Function name, array of function names to attach, * or SOAP_FUNCTIONS_ALL to attach all functions * @param string $namespace Ignored - * @return Server * @throws Exception\InvalidArgumentException on invalid functions + * + * @return Server */ public function addFunction($function, $namespace = '') { @@ -572,21 +581,19 @@ public function addFunction($function, $namespace = '') * Accepts a class name to use when handling requests. Any additional * arguments will be passed to that class' constructor when instantiated. * - * See {@link setObject()} to set preconfigured object instances as request handlers. + * See {@link setObject()} to set pre-configured object instances as request handlers. * * @param string|object $class Class name or object instance which executes SOAP Requests at endpoint. * @param string $namespace * @param $argv + * @throws Exception\InvalidArgumentException if called more than once, or if class does not exist + * * @return Server - * @throws Exception\InvalidArgumentException if called more than once, or if class - * does not exist */ public function setClass($class, $namespace = '', $argv = null) { if (isset($this->class)) { - throw new Exception\InvalidArgumentException( - 'A class has already been registered with this soap server instance' - ); + throw new Exception\InvalidArgumentException('A class has already been registered with this soap server instance'); } if (is_object($class)) { @@ -712,19 +719,20 @@ public function getPersistence() * * @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request * @throws Exception\InvalidArgumentException + * * @return Server */ protected function _setRequest($request) { $xml = null; - if ($request instanceof DOMDocument) { + if ($request instanceof \DOMDocument) { $xml = $request->saveXML(); - } elseif ($request instanceof DOMNode) { + } elseif ($request instanceof \DOMNode) { $xml = $request->ownerDocument->saveXML(); - } elseif ($request instanceof SimpleXMLElement) { + } elseif ($request instanceof \SimpleXMLElement) { $xml = $request->asXML(); } elseif (is_object($request) || is_string($request)) { @@ -737,7 +745,7 @@ protected function _setRequest($request) libxml_disable_entity_loader(true); - $dom = new DOMDocument(); + $dom = new \DOMDocument(); $loadStatus = $dom->loadXML($xml); //@todo check libxml errors ? validate document ? @@ -777,11 +785,13 @@ public function getLastRequest() * The response is always available via {@link getResponse()}. * * @param bool $flag + * * @return Server */ public function setReturnResponse($flag = true) { $this->returnResponse = ($flag) ? true : false; + return $this; } @@ -856,7 +866,8 @@ protected function _getSoap() * If no request is passed, pulls request using php:://input (for * cross-platform compatibility purposes). * - * @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request Optional request + * @param \DOMDocument|\DOMNode|\SimpleXMLElement|\stdClass|string $request Optional request + * * @return void|string */ public function handle($request = null) @@ -901,12 +912,14 @@ public function handle($request = null) // Send a fault, if we have one if ($fault instanceof SoapFault && !$this->returnResponse) { $soap->fault($fault->faultcode, $fault->getMessage()); + return; } // Echo the response, if we're not returning it if (!$this->returnResponse) { echo $this->response; + return; } @@ -933,14 +946,15 @@ protected function _initializeSoapErrorContext() } /** - * Register a valid fault exception + * Validate and register fault exception * * @param string|array $class Exception class or array of exception classes + * @throws Exception\InvalidArgumentException + * * @return Server */ public function registerFaultException($class) { - if (is_array($class)) { foreach($class as $row) { $this->registerFaultException($row); @@ -963,7 +977,11 @@ public function registerFaultException($class) } /** - * @param $fault + * Checks if provided fault name is registered as valid in this server. + * + * @param $fault Name of a fault class + * + * @return bool */ public function isRegisteredAsFaultException($fault) { @@ -978,6 +996,7 @@ public function isRegisteredAsFaultException($fault) * Deregister a fault exception from the fault exception stack * * @param string $class + * * @return bool */ public function deregisterFaultException($class) @@ -1013,9 +1032,10 @@ public function getFaultExceptions() * @link http://www.w3.org/TR/soap12-part1/#faultcodes * @param string|\Exception $fault * @param string $code SOAP Fault Codes + * * @return SoapFault */ - public function fault($fault = null, $code = "Receiver") + public function fault($fault = null, $code = 'Receiver') { if ($fault instanceof \Exception) { if ($this->isRegisteredAsFaultException($fault)) { @@ -1031,12 +1051,9 @@ public function fault($fault = null, $code = "Receiver") $message = 'Unknown error'; } - $allowedFaultModes = array( - 'VersionMismatch', 'MustUnderstand', 'DataEncodingUnknown', - 'Sender', 'Receiver', 'Server' - ); + $allowedFaultModes = array('VersionMismatch', 'MustUnderstand', 'DataEncodingUnknown', 'Sender', 'Receiver', 'Server'); if (!in_array($code, $allowedFaultModes)) { - $code = "Receiver"; + $code = 'Receiver'; } return new SoapFault($code, $message); @@ -1050,8 +1067,9 @@ public function fault($fault = null, $code = "Receiver") * @param string $errfile * @param int $errline * @param array $errcontext + * @throws \SoapFault + * * @return void - * @throws SoapFault */ public function handlePhpErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null) { diff --git a/src/Server/DocumentLiteralWrapper.php b/src/Server/DocumentLiteralWrapper.php index c343da66..0a0c4587 100644 --- a/src/Server/DocumentLiteralWrapper.php +++ b/src/Server/DocumentLiteralWrapper.php @@ -10,8 +10,7 @@ namespace Zend\Soap\Server; use ReflectionObject; -use Zend\Soap\Exception\BadMethodCallException; -use Zend\Soap\Exception\UnexpectedValueException; +use Zend\Soap\Exception; /** * Wraps WSDL Document/Literal Style service objects to hide SOAP request @@ -94,6 +93,7 @@ public function __construct($object) * * @param string $method * @param array $args + * * @return mixed */ public function __call($method, $args) @@ -103,6 +103,7 @@ public function __call($method, $args) $delegateArgs = $this->_parseArguments($method, $args[0]); $ret = call_user_func_array(array($this->object, $method), $delegateArgs); + return $this->_getResultMessage($method, $ret); } @@ -112,7 +113,8 @@ public function __call($method, $args) * * @param string $method * @param object $document - * @throws UnexpectedValueException + * @throws \Zend\Soap\Exception\UnexpectedValueException + * * @return array */ protected function _parseArguments($method, $document) @@ -127,7 +129,7 @@ protected function _parseArguments($method, $document) $delegateArgs = array(); foreach (get_object_vars($document) as $argName => $argValue) { if (!isset($params[$argName])) { - throw new UnexpectedValueException(sprintf( + throw new Exception\UnexpectedValueException(sprintf( "Received unknown argument %s which is not an argument to %s::%s", $argName, get_class($this->object), @@ -136,18 +138,33 @@ protected function _parseArguments($method, $document) } $delegateArgs[$params[$argName]->getPosition()] = $argValue; } + return $delegateArgs; } + /** + * Returns result message content + * + * @param $method + * @param $ret + * + * @return array + */ protected function _getResultMessage($method, $ret) { return array($method . 'Result' => $ret); } + /** + * @param $method + * @throws \Zend\Soap\Exception\BadMethodCallException + * + * @return void + */ protected function _assertServiceDelegateHasMethod($method) { if (!$this->reflection->hasMethod($method)) { - throw new BadMethodCallException(sprintf( + throw new Exception\BadMethodCallException(sprintf( "Method %s does not exist on delegate object %s", $method, get_class($this->object) @@ -155,10 +172,16 @@ protected function _assertServiceDelegateHasMethod($method) } } + /** + * @param $args + * @throws \Zend\Soap\Exception\UnexpectedValueException + * + * @return void + */ protected function _assertOnlyOneArgument($args) { if (count($args) != 1) { - throw new UnexpectedValueException(sprintf( + throw new Exception\UnexpectedValueException(sprintf( "Expecting exactly one argument that is the document/literal wrapper, got %d", count($args)) ); diff --git a/src/Wsdl.php b/src/Wsdl.php index 70de56d5..b22517dc 100644 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -9,8 +9,6 @@ namespace Zend\Soap; -use DOMDocument; -use DOMElement; use Zend\Soap\Exception\InvalidArgumentException; use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy; use Zend\Uri\Uri; @@ -22,28 +20,30 @@ class Wsdl { /** - * @var object DomDocument Instance + * DOM Instance + * @var \DOMDocument */ private $dom; /** - * @var object WSDL Root XML_Tree_Node + * Root XML_Tree_Node + * @var \DOMElement WSDL */ private $wsdl; /** - * @var string URI where the WSDL will be available + * URI where the WSDL will be available + * @var string */ private $uri; /** - * @var DOMElement + * @var \DOMElement */ private $schema = null; /** * Types defined on schema - * * @var array */ private $includedTypes = array(); @@ -55,20 +55,12 @@ class Wsdl /** * Map of PHP Class names to WSDL QNames. - * * @var array */ protected $classMap = array(); -// const WSDL_NS_URI = 'http://schemas.xmlsoap.org/wsdl/'; -// const XML_NS_URI = 'http://www.w3.org/2000/xmlns/'; -// const SOAP_11_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap/'; -// const SOAP_12_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap12/'; -// const XSD_NS_URI = 'http://www.w3.org/2001/XMLSchema'; -// const SOAP_ENC_URI = 'http://schemas.xmlsoap.org/soap/encoding/'; - /**#@+ - * XML Namespaces. + * XML Namespace uris and prefixes. */ const XML_NS = 'xmlns'; const XML_NS_URI = 'http://www.w3.org/2000/xmlns/'; @@ -83,6 +75,7 @@ class Wsdl const XSD_NS = 'xsd'; const XSD_NS_URI = 'http://www.w3.org/2001/XMLSchema'; const TYPES_NS = 'tns'; + /**#@-*/ /** * Constructor @@ -114,18 +107,20 @@ public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, a * * @param string $uri * @param string $name + * * @return \DOMDocument */ protected function getDOMDocument($name, $uri = null) { $dom = new \DOMDocument(); - $dom->preserveWhiteSpace = true; - $dom->formatOutput = true; - $dom->resolveExternals = false; - $dom->encoding = 'UTF-8'; - $dom->substituteEntities = false; - - $definitions = $dom->createElementNS(Wsdl::WSDL_NS_URI, 'definitions'); + //@todo new option for debug mode ? + $dom->preserveWhiteSpace = false; + $dom->formatOutput = false; + $dom->resolveExternals = false; + $dom->encoding = 'UTF-8'; + $dom->substituteEntities = false; + + $definitions = $dom->createElementNS(Wsdl::WSDL_NS_URI, 'definitions'); $dom->appendChild($definitions); $uri = $this->sanitizeUri($uri); @@ -143,7 +138,22 @@ protected function getDOMDocument($name, $uri = null) } /** - * Get the class map of php to wsdl qname types. + * Retrieve target namespace of the WSDL document. + * + * @return string + */ + public function getTargetNamespace() + { + $targetNamespace = null; + if ($this->wsdl !== null) { + $targetNamespace = $this->wsdl->getAttribute('targetNamespace'); + } + + return $targetNamespace; + } + + /** + * Get the class map of php to wsdl mappings.. * * @return array */ @@ -153,28 +163,35 @@ public function getClassMap() } /** - * Set the class map of php to wsdl qname types. + * Set the class map of php to wsdl mappings.. */ public function setClassMap($classMap) { $this->classMap = $classMap; + //@todo return Wsdl? } /** * Set a new uri for this WSDL * * @param string|Uri $uri + * * @return \Zend\Soap\Wsdl */ public function setUri($uri) { + if ($uri instanceof Uri){ + $uri = $uri->toString(); + } + $uri = $this->sanitizeUri($uri); $oldUri = $this->uri; $this->uri = $uri; if ($this->dom instanceof \DOMDocument ) { - // namespace declarations are NOT true attributes + // namespace declarations are NOT true attributes so one must explicitly set on root element + // xmlns:tns = $uri $this->dom->documentElement->setAttributeNS(Wsdl::XML_NS_URI, Wsdl::XML_NS . ':' . Wsdl::TYPES_NS, $uri); $xpath = new \DOMXPath($this->dom); @@ -188,7 +205,8 @@ public function setUri($uri) $xpath->registerNamespace(Wsdl::WSDL_NS, Wsdl::WSDL_NS_URI); // select only attribute nodes. Data nodes does not contain uri except for documentation node but - // this is for the user to decide + // this is for the user to decide. This list does not include xmlns:tsn attribute of document root. + // That attribute is changed above $attributeNodes = $xpath->query('//attribute::*[contains(., "' . $oldUri . '")]'); /** @var $node \DOMAttr */ @@ -202,6 +220,8 @@ public function setUri($uri) } /** + * Return WSDL uri + * * @return string */ public function getUri() @@ -213,13 +233,12 @@ public function getUri() * Function for sanitizing uri * * @param $uri - * * @throws Exception\InvalidArgumentException + * * @return string */ public function sanitizeUri($uri) { - if ($uri instanceof Uri) { $uri = $uri->toString(); } @@ -238,11 +257,13 @@ public function sanitizeUri($uri) * Set a strategy for complex type detection and handling * * @param ComplexTypeStrategy $strategy + * * @return \Zend\Soap\Wsdl */ public function setComplexTypeStrategy(ComplexTypeStrategy $strategy) { $this->strategy = $strategy; + return $this; } @@ -262,11 +283,11 @@ public function getComplexTypeStrategy() * @param string $messageName Name for the {@link http://www.w3.org/TR/wsdl#_messages message} * @param array $parts An array of {@link http://www.w3.org/TR/wsdl#_message parts} * The array is constructed like: - * 'name of part' => 'part xml schema data type' or - * 'name of part' => array('type' => 'part xml schema type') or - * 'name of part' => array('element' => 'part xml element name') - * - * @return object The new message's XML_Tree_Node for use in {@link function addDocumentation} + * 'name of part' => 'part xml schema data type' or + * 'name of part' => array('type' => 'part xml schema type') or + * 'name of part' => array('element' => 'part xml element name') + * + * @return \DOMElement The new message's XML_Tree_Node for use in {@link function addDocumentation} */ public function addMessage($messageName, $parts) { @@ -277,13 +298,14 @@ public function addMessage($messageName, $parts) if (count($parts) > 0) { foreach ($parts as $name => $type) { $part = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'part'); + $message->appendChild($part); + $part->setAttribute('name', $name); if (is_array($type)) { $this->arrayToAttributes($part, $type); } else { $this->setAttributeWithSanitization($part, 'type', $type); } - $message->appendChild($part); } } @@ -296,30 +318,35 @@ public function addMessage($messageName, $parts) * Add a {@link http://www.w3.org/TR/wsdl#_porttypes portType} element to the WSDL * * @param string $name portType element's name - * @return object The new portType's XML_Tree_Node for use in {@link function addPortOperation} and {@link function addDocumentation} + * + * @return \DOMElement The new portType's XML_Tree_Node for use in {@link function addPortOperation} and addDocumentation@link function addDocumentation} */ public function addPortType($name) { $portType = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'portType'); - $portType->setAttribute('name', $name); $this->wsdl->appendChild($portType); + $portType->setAttribute('name', $name); + return $portType; } /** * Add an {@link http://www.w3.org/TR/wsdl#request-response operation} element to a portType element * - * @param object $portType a portType XML_Tree_Node, from {@link function addPortType} - * @param string $name Operation name - * @param string $input Input Message - * @param string $output Output Message - * @param string $fault Fault Message - * @return object The new operation's XML_Tree_Node for use in {@link function addDocumentation} + * @param \DOMElement $portType a portType XML_Tree_Node, from {@link function addPortType} + * @param string $name Operation name + * @param bool|string $input Input Message + * @param bool|string $output Output Message + * @param bool|string $fault Fault Message + * + * @return \DOMElement The new operation's XML_Tree_Node for use in {@link function addDocumentation} */ public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false) { $operation = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'operation'); + $portType->appendChild($operation); + $operation->setAttribute('name', $name); if (is_string($input) && (strlen(trim($input)) >= 1)) { @@ -327,19 +354,19 @@ public function addPortOperation($portType, $name, $input = false, $output = fal $operation->appendChild($node); $node->setAttribute('message', $input); } + if (is_string($output) && (strlen(trim($output)) >= 1)) { $node= $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'output'); $operation->appendChild($node); $node->setAttribute('message', $output); } + if (is_string($fault) && (strlen(trim($fault)) >= 1)) { $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'fault'); $operation->appendChild($node); $node->setAttribute('message', $fault); } - $portType->appendChild($operation); - return $operation; } @@ -347,22 +374,17 @@ public function addPortOperation($portType, $name, $input = false, $output = fal * Add a {@link http://www.w3.org/TR/wsdl#_bindings binding} element to WSDL * * @param string $name Name of the Binding - * @param string $portType name of the portType to bind - * - * @return object The new binding's XML_Tree_Node for use with {@link function addBindingOperation} and {@link function addDocumentation} + * @param string $portType name of the portType to bind + * + * @return \DOMElement The new binding's XML_Tree_Node for use with {@link function addBindingOperation} and {@link function addDocumentation} */ public function addBinding($name, $portType) { $binding = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'binding'); $this->wsdl->appendChild($binding); - $attr = $this->dom->createAttribute('name'); - $attr->value = $name; - $binding->appendChild($attr); - - $attr = $this->dom->createAttribute('type'); - $attr->value = $portType; - $binding->appendChild($attr); + $this->setAttribute($binding, 'name', $name); + $this->setAttribute($binding, 'type', $portType); return $binding; } @@ -370,34 +392,33 @@ public function addBinding($name, $portType) /** * Add an operation to a binding element * - * @param object $binding A binding XML_Tree_Node returned by {@link function addBinding} - * @param string $name - * @param array|bool $input An array of attributes for the input element, + * @param \DOMElement $binding A binding XML_Tree_Node returned by {@link function addBinding} + * @param string $name + * @param array|bool $input An array of attributes for the input element, * allowed keys are: 'use', 'namespace', 'encodingStyle'. * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param array|bool $output An array of attributes for the output element, + * @param array|bool $output An array of attributes for the output element, * allowed keys are: 'use', 'namespace', 'encodingStyle'. * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param array|bool $fault An array with attributes for the fault element, + * @param array|bool $fault An array with attributes for the fault element, * allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * - * @return object The new Operation's XML_Tree_Node for use with {@link function addSoapOperation} and {@link function addDocumentation} + * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 + * + * @return \DOMElement The new Operation's XML_Tree_Node for use with {@link function addSoapOperation} and {@link function addDocumentation} */ - public function addBindingOperation($binding, $name, $input = false, $output = false, $fault = false) + public function addBindingOperation($binding, $name, $input = false, $output = false, $fault = false, $soapVersion = SOAP_1_1) { $operation = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'operation'); $binding->appendChild($operation); - $attr = $this->dom->createAttribute('name'); - $operation->appendChild($attr); - $attr->value = $name; + $this->setAttribute($operation, 'name', $name); if (is_array($input) && !empty($input)) { $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'input'); $operation->appendChild($node); - $soapNode = $this->dom->createElementNS(Wsdl::SOAP_11_NS_URI, 'body'); + $soapNode = $this->dom->createElementNS($this->getSoapNamespaceUriByVersion($soapVersion), 'body'); $node->appendChild($soapNode); $this->arrayToAttributes($soapNode, $input); @@ -407,7 +428,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'output'); $operation->appendChild($node); - $soapNode = $this->dom->createElementNS(Wsdl::SOAP_11_NS_URI, 'body'); + $soapNode = $this->dom->createElementNS($this->getSoapNamespaceUriByVersion($soapVersion), 'body'); $node->appendChild($soapNode); $this->arrayToAttributes($soapNode, $output); @@ -426,39 +447,42 @@ public function addBindingOperation($binding, $name, $input = false, $output = f /** * Add a {@link http://www.w3.org/TR/wsdl#_soap:binding SOAP binding} element to a Binding element * - * @param object $binding A binding XML_Tree_Node returned by {@link function addBinding} + * @param \DOMElement $binding A binding XML_Tree_Node returned by {@link function addBinding} * @param string $style binding style, possible values are "rpc" (the default) and "document" * @param string $transport Transport method (defaults to HTTP) - * @return bool + * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 + * + * @return \DOMElement */ - public function addSoapBinding($binding, $style = 'document', $transport = 'http://schemas.xmlsoap.org/soap/http') + public function addSoapBinding($binding, $style = 'document', $transport = 'http://schemas.xmlsoap.org/soap/http', $soapVersion = SOAP_1_1) { + $soapBinding = $this->dom->createElementNS($this->getSoapNamespaceUriByVersion($soapVersion), 'binding'); + $binding->appendChild($soapBinding); - $soapBinding = $this->dom->createElementNS(WSDL::SOAP_11_NS_URI, 'binding'); $soapBinding->setAttribute('style', $style); $soapBinding->setAttribute('transport', $transport); - $binding->appendChild($soapBinding); - return $soapBinding; } /** * Add a {@link http://www.w3.org/TR/wsdl#_soap:operation SOAP operation} to an operation element * - * @param object $operation An operation XML_Tree_Node returned by {@link function addBindingOperation} + * @param \DOMElement $operation An operation XML_Tree_Node returned by {@link function addBindingOperation} * @param string $soapAction SOAP Action - * @return bool + * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 + * + * @return \DOMElement */ - public function addSoapOperation($binding, $soapAction) + public function addSoapOperation($operation, $soapAction, $soapVersion = SOAP_1_1) { if ($soapAction instanceof Uri) { $soapAction = $soapAction->toString(); } - $soapOperation = $this->dom->createElementNS(WSDL::SOAP_11_NS_URI, 'operation'); - $this->setAttributeWithSanitization($soapOperation, 'soapAction', $soapAction); + $soapOperation = $this->dom->createElementNS($this->getSoapNamespaceUriByVersion($soapVersion), 'operation'); + $operation->insertBefore($soapOperation, $operation->firstChild); - $binding->insertBefore($soapOperation, $binding->firstChild); + $this->setAttributeWithSanitization($soapOperation, 'soapAction', $soapAction); return $soapOperation; } @@ -470,29 +494,33 @@ public function addSoapOperation($binding, $soapAction) * @param string $portName Name of the port for the service * @param string $binding Binding for the port * @param string $location SOAP Address for the service - * @return object The new service's XML_Tree_Node for use with {@link function addDocumentation} + * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 + * + * @return \DOMElement The new service's XML_Tree_Node for use with {@link function addDocumentation} */ - public function addService($name, $portName, $binding, $location) + public function addService($name, $portName, $binding, $location, $soapVersion = SOAP_1_1) { if ($location instanceof Uri) { $location = $location->toString(); } $service = $this->dom->createElementNS(WSDL::WSDL_NS_URI, 'service'); + $this->wsdl->appendChild($service); + $service->setAttribute('name', $name); - $this->wsdl->appendChild($service); $port = $this->dom->createElementNS(WSDL::WSDL_NS_URI, 'port'); + $service->appendChild($port); + $port->setAttribute('name', $portName); $port->setAttribute('binding', $binding); - $service->appendChild($port); - - $soapAddress = $this->dom->createElementNS(WSDL::SOAP_11_NS_URI, 'address'); - $this->setAttributeWithSanitization($soapAddress, 'location', $location); + $soapAddress = $this->dom->createElementNS($this->getSoapNamespaceUriByVersion($soapVersion), 'address'); $port->appendChild($soapAddress); + $this->setAttributeWithSanitization($soapAddress, 'location', $location); + return $service; } @@ -503,9 +531,10 @@ public function addService($name, $portName, $binding, $location) * but the WSDL {@link http://schemas.xmlsoap.org/wsdl/ schema} uses 'documentation' instead. * The {@link http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html#WSDL_documentation_Element WS-I Basic Profile 1.1} recommends using 'documentation'. * - * @param object $inputNode An XML_Tree_Node returned by another method to add the documentation to + * @param \DOMElement $inputNode An XML_Tree_Node returned by another method to add the documentation to * @param string $documentation Human readable documentation for the node - * @return DOMElement The documentation element + * + * @return \DOMElement The documentation element */ public function addDocumentation($inputNode, $documentation) { @@ -531,16 +560,17 @@ public function addDocumentation($inputNode, $documentation) /** * Add WSDL Types element * - * @param object $types A DomDocument|DomNode|DomElement|DomDocumentFragment with all the XML Schema types defined in it + * @param \DOMDocument|\DOMNode|\DOMElement|\DOMDocumentFragment $types A DOMDocument|DOMNode|DOMElement|DOMDocumentFragment with all the XML Schema types defined in it * * @return void */ public function addTypes($types) { - if ($types instanceof \DomDocument) { + if ($types instanceof \DOMDocument) { $dom = $this->dom->importNode($types->documentElement); $this->wsdl->appendChild($dom); - } elseif ($types instanceof \DomNode || $types instanceof \DomElement || $types instanceof \DomDocumentFragment ) { + + } elseif ($types instanceof \DOMNode || $types instanceof \DOMElement || $types instanceof \DOMDocumentFragment ) { $dom = $this->dom->importNode($types); $this->wsdl->appendChild($dom); } @@ -551,6 +581,7 @@ public function addTypes($types) * * @param string $type * @param string $wsdlType + * * @return \Zend\Soap\Wsdl */ public function addType($type, $wsdlType) @@ -558,6 +589,7 @@ public function addType($type, $wsdlType) if (!isset($this->includedTypes[$type])) { $this->includedTypes[$type] = $wsdlType; } + return $this; } @@ -574,7 +606,7 @@ public function getTypes() /** * Return the Schema node of the WSDL * - * @return DOMElement + * @return \DOMElement */ public function getSchema() { @@ -612,6 +644,8 @@ public function toDomDocument() /** * Echo the WSDL as XML * + * @param bool $filename + * * @return bool */ public function dump($filename = false) @@ -630,6 +664,7 @@ public function dump($filename = false) * Returns an XSD Type for the given PHP type * * @param string $type PHP Type to get the XSD type for + * * @return string */ public function getType($type) @@ -638,26 +673,36 @@ public function getType($type) case 'string': case 'str': return Wsdl::XSD_NS . ':string'; + case 'long': return Wsdl::XSD_NS . ':long'; + case 'int': case 'integer': return Wsdl::XSD_NS . ':int'; + case 'float': return Wsdl::XSD_NS . ':float'; + case 'double': return Wsdl::XSD_NS . ':double'; + case 'boolean': case 'bool': return Wsdl::XSD_NS . ':boolean'; + case 'array': return Wsdl::SOAP_ENC_NS . ':Array'; + case 'object': return Wsdl::XSD_NS . ':struct'; + case 'mixed': return Wsdl::XSD_NS . ':anyType'; + case 'void': return ''; + default: // delegate retrieval of complex type to current strategy return $this->addComplexType($type); @@ -672,14 +717,13 @@ public function getType($type) public function addSchemaTypeSection() { if ($this->schema === null) { - $types = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'types'); $this->wsdl->appendChild($types); $this->schema = $this->dom->createElementNS(WSDL::XSD_NS_URI, 'schema'); $types->appendChild($this->schema); - $this->schema->setAttribute('targetNamespace', $this->getUri()); + $this->setAttributeWithSanitization($this->schema, 'targetNamespace', $this->getUri()); } return $this; @@ -689,6 +733,7 @@ public function addSchemaTypeSection() * Translate PHP type into WSDL QName * * @param string $type + * * @return string QName */ public function translateType($type) @@ -712,6 +757,7 @@ public function translateType($type) * Add a {@link http://www.w3.org/TR/wsdl#_types types} data type definition * * @param string $type Name of the class to be specified + * * @return string XSD Type for the given PHP type */ public function addComplexType($type) @@ -723,6 +769,7 @@ public function addComplexType($type) $strategy = $this->getComplexTypeStrategy(); $strategy->setContext($this); + // delegates the detection of a complex type to the current strategy return $strategy->addComplexType($type); } @@ -732,7 +779,8 @@ public function addComplexType($type) * * @param array $element an xsd:element represented as an array * @throws Exception\RuntimeException if $element is not an array - * @return DOMElement parsed element + * + * @return \DOMElement parsed element */ private function _parseElement($element) { @@ -759,12 +807,16 @@ private function _parseElement($element) $elementXML->setAttribute($key, $value); } } + return $elementXML; } /** + * Prepare attribute value for specific attributes + * * @param string $name * @param mixed $value + * * @return string safe value or original $value */ private function sanitizeAttributeValueByName($name, $value) @@ -774,7 +826,7 @@ private function sanitizeAttributeValueByName($name, $value) case 'encodingstyle': case 'soapaction': case 'location': - return trim(htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false)); + return $this->sanitizeUri($value); break; default: @@ -784,10 +836,13 @@ private function sanitizeAttributeValueByName($name, $value) } /** + * Convert associative array to attributes of given node using optional {@link function sanitizeAttributeValueByName} * * @param \DOMNode $node * @param array $attributes * @param bool $withSanitizer + * + * @return void */ private function arrayToAttributes(\DOMNode $node, array $attributes, $withSanitizer = true) { @@ -801,9 +856,13 @@ private function arrayToAttributes(\DOMNode $node, array $attributes, $withSanit } /** + * Set attribute to given node using {@link function sanitizeAttributeValueByName} + * * @param \DOMNode $node - * @param $attributeName - * @param $attributeValue + * @param string $attributeName + * @param mixed $attributeValue + * + * @return void */ private function setAttributeWithSanitization(\DOMNode $node, $attributeName, $attributeValue) { @@ -812,9 +871,13 @@ private function setAttributeWithSanitization(\DOMNode $node, $attributeName, $a } /** + * Set attribute to given node + * * @param \DOMNode $node - * @param $attributeName - * @param $attributeValue + * @param string $attributeName + * @param mixed $attributeValue + * + * @return void */ private function setAttribute(\DOMNode $node, $attributeName, $attributeValue) { @@ -825,6 +888,27 @@ private function setAttribute(\DOMNode $node, $attributeName, $attributeValue) $attributeNode->appendChild($attributeNodeValue); } + /** + * Return soap namespace uri according to $soapVersion + * + * @param int $soapVersion SOAP_1_1 or SOAP_1_2 constants + * @throws Exception\InvalidArgumentException + * + * @return string + */ + private function getSoapNamespaceUriByVersion($soapVersion) + { + if ($soapVersion != SOAP_1_1 AND $soapVersion != SOAP_1_2) { + throw new Exception\InvalidArgumentException('Invalid SOAP version, use constants: SOAP_1_1 or SOAP_1_2'); + } + + if ($soapVersion == SOAP_1_1) { + return Wsdl::SOAP_11_NS_URI; + } + + return Wsdl::SOAP_12_NS_URI; + } + /** * Add an xsd:element represented as an array to the schema. * @@ -841,6 +925,7 @@ private function setAttribute(\DOMNode $node, $attributeName, $attributeValue) * * * @param array $element an xsd:element represented as an array + * * @return string xsd:element for the given element array */ public function addElement($element) @@ -848,6 +933,7 @@ public function addElement($element) $schema = $this->getSchema(); $elementXml = $this->_parseElement($element); $schema->appendChild($elementXml); + return Wsdl::TYPES_NS . ':' . $element['name']; } } diff --git a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php index a81f6ba2..b8cbac03 100644 --- a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php +++ b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php @@ -9,6 +9,8 @@ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; +use Zend\Soap\Wsdl; + /** * Abstract class for Zend_Soap_Wsdl_Strategy. * @@ -17,18 +19,18 @@ abstract class AbstractComplexTypeStrategy implements ComplexTypeStrategyInterfa { /** * Context object - * - * @var \Zend\Soap\Wsdl + * @var Wsdl */ protected $context; /** * Set the Zend_Soap_Wsdl Context object this strategy resides in. * - * @param \Zend\Soap\Wsdl $context + * @param Wsdl $context + * * @return void */ - public function setContext(\Zend\Soap\Wsdl $context) + public function setContext(Wsdl $context) { $this->context = $context; } @@ -36,7 +38,7 @@ public function setContext(\Zend\Soap\Wsdl $context) /** * Return the current Zend_Soap_Wsdl context object * - * @return \Zend\Soap\Wsdl + * @return Wsdl */ public function getContext() { @@ -47,6 +49,7 @@ public function getContext() * Look through registered types * * @param string $phpType + * * @return string */ public function scanRegisteredTypes($phpType) diff --git a/src/Wsdl/ComplexTypeStrategy/AnyType.php b/src/Wsdl/ComplexTypeStrategy/AnyType.php index b5637a69..2ab59003 100644 --- a/src/Wsdl/ComplexTypeStrategy/AnyType.php +++ b/src/Wsdl/ComplexTypeStrategy/AnyType.php @@ -15,6 +15,10 @@ */ use Zend\Soap\Wsdl; +/** + * Class AnyType + * + */ class AnyType implements ComplexTypeStrategyInterface { /** @@ -22,13 +26,14 @@ class AnyType implements ComplexTypeStrategyInterface * * @param \Zend\Soap\Wsdl $context */ - public function setContext(\Zend\Soap\Wsdl $context) + public function setContext(Wsdl $context) {} /** * Returns xsd:anyType regardless of the input. * * @param string $type + * * @return string */ public function addComplexType($type) diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php index c5e91fe0..16890b96 100644 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php @@ -24,6 +24,7 @@ class ArrayOfTypeComplex extends DefaultComplexType * * @param string $type * @throws Exception\InvalidArgumentException + * * @return string tns:xsd-type */ public function addComplexType($type) @@ -36,8 +37,10 @@ public function addComplexType($type) $nestingLevel = $this->_getNestedCount($type); if ($nestingLevel == 0) { + return parent::addComplexType($singularType); } elseif ($nestingLevel == 1) { + // The following blocks define the Array of Object structure return $this->_addArrayOfComplexType($singularType, $type); } else { @@ -53,6 +56,7 @@ public function addComplexType($type) * * @param string $singularType e.g. '\MyNamespace\MyClassname' * @param string $type e.g. '\MyNamespace\MyClassname[]' + * * @return string tns:xsd-type e.g. 'tns:ArrayOfMyNamespace.MyClassname' */ protected function _addArrayOfComplexType($singularType, $type) @@ -83,8 +87,8 @@ protected function _addArrayOfComplexType($singularType, $type) $complexType->appendChild($complexContent); $xsdRestriction = $dom->createElementNS(Wsdl::XSD_NS_URI, 'restriction'); - $xsdRestriction->setAttribute('base', Wsdl::SOAP_ENC_NS . ':Array'); $complexContent->appendChild($xsdRestriction); + $xsdRestriction->setAttribute('base', Wsdl::SOAP_ENC_NS . ':Array'); $xsdAttribute = $dom->createElementNS(Wsdl::XSD_NS_URI, 'attribute'); $xsdRestriction->appendChild($xsdAttribute); @@ -103,6 +107,7 @@ protected function _addArrayOfComplexType($singularType, $type) * From a nested definition with type[], get the singular PHP Type * * @param string $type + * * @return string */ protected function _getSingularPhpType($type) @@ -114,6 +119,7 @@ protected function _getSingularPhpType($type) * Return the array nesting level based on the type name * * @param string $type + * * @return integer */ protected function _getNestedCount($type) diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php index df14d595..4199a949 100644 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php @@ -22,6 +22,7 @@ class ArrayOfTypeSequence extends DefaultComplexType * type[] is detected in return value doc comment. * * @param string $type + * * @return string tns:xsd-type */ public function addComplexType($type) @@ -42,9 +43,11 @@ public function addComplexType($type) return $complexType; } elseif (($soapType = $this->scanRegisteredTypes($type)) !== null) { + // Existing complex type return $soapType; } else { + // New singular complex type return parent::addComplexType($type); } @@ -56,6 +59,7 @@ public function addComplexType($type) * * @param string $singularType * @param int $level + * * @return string */ protected function _getTypeBasedOnNestingLevel($singularType, $level) @@ -72,6 +76,7 @@ protected function _getTypeBasedOnNestingLevel($singularType, $level) * From a nested definition with type[], get the singular xsd:type * * @param string $type + * * @return string */ protected function _getSingularType($type) @@ -83,6 +88,7 @@ protected function _getSingularType($type) * Return the array nesting level based on the type name * * @param string $type + * * @return integer */ protected function _getNestedCount($type) @@ -96,6 +102,7 @@ protected function _getNestedCount($type) * @param string $arrayType Array type name (e.g. 'tns:ArrayOfArrayOfInt') * @param string $childType Qualified array items type (e.g. 'xsd:int', 'tns:ArrayOfInt') * @param string $phpArrayType PHP type (e.g. 'int[][]', '\MyNamespace\MyClassName[][][]') + * * @return void */ protected function _addSequenceType($arrayType, $childType, $phpArrayType) @@ -113,6 +120,8 @@ protected function _addSequenceType($arrayType, $childType, $phpArrayType) $arrayTypeName = substr($arrayType, strpos($arrayType, ':') + 1); $complexType = $dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType'); + $this->getContext()->getSchema()->appendChild($complexType); + $complexType->setAttribute('name', $arrayTypeName); $sequence = $dom->createElementNS(Wsdl::XSD_NS_URI, 'sequence'); @@ -125,7 +134,5 @@ protected function _addSequenceType($arrayType, $childType, $phpArrayType) $element->setAttribute('type', $childType); $element->setAttribute('minOccurs', 0); $element->setAttribute('maxOccurs', 'unbounded'); - - $this->getContext()->getSchema()->appendChild($complexType); } } diff --git a/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php b/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php index 9bc22502..36a01165 100644 --- a/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php +++ b/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php @@ -28,6 +28,7 @@ public function setContext(Wsdl $context); * Create a complex type based on a strategy * * @param string $type + * * @return string XSD type */ public function addComplexType($type); diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php index f585187d..acf01a40 100644 --- a/src/Wsdl/ComplexTypeStrategy/Composite.php +++ b/src/Wsdl/ComplexTypeStrategy/Composite.php @@ -21,21 +21,18 @@ class Composite implements ComplexTypeStrategy { /** * Typemap of Complex Type => Strategy pairs. - * * @var array */ protected $typeMap = array(); /** * Default Strategy of this composite - * * @var string|ComplexTypeStrategy */ protected $defaultStrategy; /** * Context WSDL file that this composite serves - * * @var \Zend\Soap\Wsdl|null */ protected $context; @@ -46,22 +43,22 @@ class Composite implements ComplexTypeStrategy * @param array $typeMap * @param string|ComplexTypeStrategy $defaultStrategy */ - public function __construct( - array $typeMap=array(), - $defaultStrategy = '\Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType' - ) { + public function __construct(array $typeMap=array(),$defaultStrategy = '\Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType') + { foreach ($typeMap AS $type => $strategy) { $this->connectTypeToStrategy($type, $strategy); } + $this->defaultStrategy = $defaultStrategy; } /** * Connect a complex type to a given strategy. * - * @throws Exception\InvalidArgumentException * @param string $type * @param string|ComplexTypeStrategy $strategy + * @throws Exception\InvalidArgumentException + * * @return Composite */ public function connectTypeToStrategy($type, $strategy) @@ -70,13 +67,15 @@ public function connectTypeToStrategy($type, $strategy) throw new Exception\InvalidArgumentException('Invalid type given to Composite Type Map.'); } $this->typeMap[$type] = $strategy; + return $this; } /** * Return default strategy of this composite * - * @throws Exception\InvalidArgumentException + * @throws Exception\InvalidArgumentException + * * @return ComplexTypeStrategy */ public function getDefaultStrategy() @@ -91,14 +90,16 @@ public function getDefaultStrategy() ); } $this->defaultStrategy = $strategy; + return $strategy; } /** * Return specific strategy or the default strategy of this type. * - * @throws Exception\InvalidArgumentException - * @param string $type + * @param string $type + * @throws Exception\InvalidArgumentException + * * @return ComplexTypeStrategy */ public function getStrategyOfType($type) @@ -119,6 +120,7 @@ public function getStrategyOfType($type) } else { $strategy = $this->getDefaultStrategy(); } + return $strategy; } @@ -126,19 +128,22 @@ public function getStrategyOfType($type) * Method accepts the current WSDL context file. * * @param \Zend\Soap\Wsdl $context + * * @return Composite */ public function setContext(Wsdl $context) { $this->context = $context; + return $this; } /** * Create a complex type based on a strategy * - * @throws Exception\InvalidArgumentException * @param string $type + * @throws Exception\InvalidArgumentException + * * @return string XSD type */ public function addComplexType($type) @@ -151,6 +156,7 @@ public function addComplexType($type) $strategy = $this->getStrategyOfType($type); $strategy->setContext($this->context); + return $strategy->addComplexType($type); } } diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php index a5080f13..ce437861 100644 --- a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php +++ b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php @@ -19,10 +19,11 @@ class DefaultComplexType extends AbstractComplexTypeStrategy { /** - * Add a complex type by recursivly using all the class properties fetched via Reflection. + * Add a complex type by recursively using all the class properties fetched via Reflection. * * @param string $type Name of the class to be specified * @throws Exception\InvalidArgumentException if class does not exist + * * @return string XSD Type for the given PHP type */ public function addComplexType($type) @@ -56,9 +57,7 @@ public function addComplexType($type) $all = $dom->createElementNS(Wsdl::XSD_NS_URI, 'all'); foreach ($class->getProperties() as $property) { - if ($property->isPublic() - && preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches) - ) { + if ($property->isPublic() && preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches)) { /** * @todo check if 'xsd:element' must be used here (it may not be diff --git a/test/WsdlTest.php b/test/WsdlTest.php index 2f729622..40cef4c6 100644 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -118,17 +118,17 @@ public function dataProviderForURITesting() ); } - /** - * @dataProvider dataProviderForAddMessage - * - * @param array $parameters message parameters - */ - function testAddMessage($parameters) - { - $messageParts = array(); - foreach($parameters as $i => $parameter) { - $messageParts['parameter'.$i] = $this->wsdl->getType($parameter); - } + /** + * @dataProvider dataProviderForAddMessage + * + * @param array $parameters message parameters + */ + function testAddMessage($parameters) + { + $messageParts = array(); + foreach($parameters as $i => $parameter) { + $messageParts['parameter'.$i] = $this->wsdl->getType($parameter); + } $messageName = 'myMessage'; @@ -180,19 +180,19 @@ public function testAddComplexMessage($parameters) } - /** - * @return array - */ - public function dataProviderForAddMessage() + /** + * @return array + */ + public function dataProviderForAddMessage() { - return array( - array(array('int', 'int', 'int')), - array(array('string', 'string', 'string', 'string')), - array(array('mixed')), - array(array('int', 'int', 'string', 'string')), - array(array('int', 'string', 'int', 'string')), - ); - } + return array( + array(array('int', 'int', 'int')), + array(array('string', 'string', 'string', 'string')), + array(array('mixed')), + array(array('int', 'int', 'string', 'string')), + array(array('int', 'string', 'int', 'string')), + ); + } function testAddPortType() { @@ -229,26 +229,26 @@ function testAddPortOperation($operationName, $inputRequest = null, $outputRespo $operationNodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $portTypeNodes->item(0)); $this->assertGreaterThan(0, $operationNodes->length); - if (empty($inputRequest) AND empty($outputResponse) AND empty($fail)) { + if (empty($inputRequest) AND empty($outputResponse) AND empty($fail)) { $this->assertFalse($operationNodes->item(0)->hasChildNodes()); } else { $this->assertTrue($operationNodes->item(0)->hasChildNodes()); - } + } - if (!empty($inputRequest)) { + if (!empty($inputRequest)) { $inputNodes = $operationNodes->item(0)->getElementsByTagName('input'); $this->assertEquals($inputRequest, $inputNodes->item(0)->getAttribute('message')); } - if (!empty($outputResponse)) { - $outputNodes = $operationNodes->item(0)->getElementsByTagName('output'); - $this->assertEquals($outputResponse, $outputNodes->item(0)->getAttribute('message')); - } + if (!empty($outputResponse)) { + $outputNodes = $operationNodes->item(0)->getElementsByTagName('output'); + $this->assertEquals($outputResponse, $outputNodes->item(0)->getAttribute('message')); + } - if (!empty($fail)) { - $faultNodes = $operationNodes->item(0)->getElementsByTagName('fault'); - $this->assertEquals($fail, $faultNodes->item(0)->getAttribute('message')); - } + if (!empty($fail)) { + $faultNodes = $operationNodes->item(0)->getElementsByTagName('fault'); + $this->assertEquals($fail, $faultNodes->item(0)->getAttribute('message')); + } } /** @@ -263,8 +263,8 @@ function dataProviderForAddPortOperation() array('operation', 'tns:operationRequest', null, 'tns:operationFault'), array('operation', null, null, 'tns:operationFault'), array('operation', null, 'tns:operationResponse', 'tns:operationFault'), - array('operation', null, 'tns:operationResponse'), - ); + array('operation', null, 'tns:operationResponse'), + ); } function testAddBinding() @@ -284,62 +284,62 @@ function testAddBinding() } - /** - * @dataProvider dataProviderForAddBindingOperation - * - * @param $operationName - * @param null $input - * @param null $inputEncoding - * @param null $output - * @param null $outputEncoding - * @param null $fault - * @param null $faultEncoding - * @param null $faultName - */ - function testAddBindingOperation($operationName, - $input = null, $inputEncoding = null, - $output = null, $outputEncoding = null, - $fault = null, $faultEncoding = null, $faultName = null) + /** + * @dataProvider dataProviderForAddBindingOperation + * + * @param $operationName + * @param null $input + * @param null $inputEncoding + * @param null $output + * @param null $outputEncoding + * @param null $fault + * @param null $faultEncoding + * @param null $faultName + */ + function testAddBindingOperation($operationName, + $input = null, $inputEncoding = null, + $output = null, $outputEncoding = null, + $fault = null, $faultEncoding = null, $faultName = null) { $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); - $inputArray = array(); - if (!empty($input) AND !empty($inputEncoding)) { - $inputArray = array('use' => $input, 'encodingStyle' => $inputEncoding); - } + $inputArray = array(); + if (!empty($input) AND !empty($inputEncoding)) { + $inputArray = array('use' => $input, 'encodingStyle' => $inputEncoding); + } - $outputArray = array(); - if (!empty($output) AND !empty($outputEncoding)) { - $outputArray = array('use' => $output, 'encodingStyle' => $outputEncoding); - } + $outputArray = array(); + if (!empty($output) AND !empty($outputEncoding)) { + $outputArray = array('use' => $output, 'encodingStyle' => $outputEncoding); + } - $faultArray = array(); - if (!empty($fault) AND !empty($faultEncoding) AND !empty($faultName)) { - $faultArray = array('use' => $fault, 'encodingStyle' => $faultEncoding, 'name'=>$faultName); - } + $faultArray = array(); + if (!empty($fault) AND !empty($faultEncoding) AND !empty($faultName)) { + $faultArray = array('use' => $fault, 'encodingStyle' => $faultEncoding, 'name'=>$faultName); + } - $this->wsdl->addBindingOperation($binding, - $operationName, - $inputArray, - $outputArray, - $faultArray - ); + $this->wsdl->addBindingOperation($binding, + $operationName, + $inputArray, + $outputArray, + $faultArray + ); $this->testDocumentNodes(); $bindingNodes = $this->xpath->query('//wsdl:binding'); - $this->assertGreaterThan(0, $bindingNodes->length, 'Missing binding node in definition.'); + $this->assertGreaterThan(0, $bindingNodes->length, 'Missing binding node in definition.'); $this->assertEquals('MyServiceBinding', $bindingNodes->item(0)->getAttribute('name')); $this->assertEquals('myPortType', $bindingNodes->item(0)->getAttribute('type')); - $operationNodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $bindingNodes->item(0)); - $this->assertEquals(1, $operationNodes->length, 'Missing operation node in definition.'); + $operationNodes = $this->xpath->query('wsdl:operation[@name="'.$operationName.'"]', $bindingNodes->item(0)); + $this->assertEquals(1, $operationNodes->length, 'Missing operation node in definition.'); - if (empty($inputArray) AND empty($outputArray) AND empty($faultArray)) { - $this->assertFalse($operationNodes->item(0)->hasChildNodes()); - } + if (empty($inputArray) AND empty($outputArray) AND empty($faultArray)) { + $this->assertFalse($operationNodes->item(0)->hasChildNodes()); + } foreach (array( '//wsdl:input/soap:body' => $inputArray, @@ -360,30 +360,30 @@ function testAddBindingOperation($operationName, } } - /** - * - */ - public function dataProviderForAddBindingOperation() + /** + * + */ + public function dataProviderForAddBindingOperation() { - $enc = 'http://schemas.xmlsoap.org/soap/encoding/'; + $enc = 'http://schemas.xmlsoap.org/soap/encoding/'; - return array( - array('operation'), - array('operation', 'encoded', $enc, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), - array('operation', null, null, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), - array('operation', null, null, 'encoded', $enc, 'encoded'), - array('operation', 'encoded', $enc), - array('operation', null, null, null, null, 'encoded', $enc, 'myFaultName'), - array('operation', 'encoded1', $enc.'1', 'encoded2', $enc.'2', 'encoded3', $enc.'3', 'myFaultName'), + return array( + array('operation'), + array('operation', 'encoded', $enc, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), + array('operation', null, null, 'encoded', $enc, 'encoded', $enc, 'myFaultName'), + array('operation', null, null, 'encoded', $enc, 'encoded'), + array('operation', 'encoded', $enc), + array('operation', null, null, null, null, 'encoded', $enc, 'myFaultName'), + array('operation', 'encoded1', $enc.'1', 'encoded2', $enc.'2', 'encoded3', $enc.'3', 'myFaultName'), - ); - } + ); + } - /** - * @dataProvider dataProviderForSoapBindingStyle - */ - function testAddSoapBinding($style) + /** + * @dataProvider dataProviderForSoapBindingStyle + */ + function testAddSoapBinding($style) { $this->wsdl->addPortType('myPortType'); $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); @@ -394,17 +394,17 @@ function testAddSoapBinding($style) $nodes = $this->xpath->query('//soap:binding'); - $this->assertGreaterThan(0, $nodes->length); - $this->assertEquals($style, $nodes->item(0)->getAttribute('style')); + $this->assertGreaterThan(0, $nodes->length); + $this->assertEquals($style, $nodes->item(0)->getAttribute('style')); } - public function dataProviderForSoapBindingStyle() + public function dataProviderForSoapBindingStyle() { - return array( - array('document'), - array('rpc'), - ); - } + return array( + array('document'), + array('rpc'), + ); + } /** * @dataProvider dataProviderForAddSoapOperation From 7764905988124a045e8b8eedd4cc2ee8f1c0389c Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Sun, 3 Mar 2013 20:54:29 +0100 Subject: [PATCH 16/22] Fixes in class import and type checks and some new tests data. --- src/Client.php | 5 ++- src/Client/Common.php | 9 +++-- src/Exception/BadMethodCallException.php | 4 +- src/Exception/ExtensionNotLoadedException.php | 2 + src/Exception/InvalidArgumentException.php | 4 +- src/Exception/RuntimeException.php | 4 +- src/Exception/UnexpectedValueException.php | 4 +- src/Server.php | 37 +++++++++++-------- src/Wsdl.php | 22 +++++++---- .../DefaultComplexType.php | 3 +- test/ServerTest.php | 2 +- test/WsdlTest.php | 2 + test/schemas/wsdl.xsd | 22 +++++------ 13 files changed, 75 insertions(+), 45 deletions(-) diff --git a/src/Client.php b/src/Client.php index 8e7a891c..45662666 100644 --- a/src/Client.php +++ b/src/Client.php @@ -11,6 +11,7 @@ use SoapClient; use SoapHeader; +use Traversable; use Zend\Server\Client as ServerClient; use Zend\Stdlib\ArrayUtils; @@ -98,7 +99,7 @@ class Client implements ServerClient /** * Array of SoapHeader objects - * @var array + * @var SoapHeader[] */ protected $soapInputHeaders = array(); @@ -172,7 +173,7 @@ public function getWSDL() */ public function setOptions($options) { - if ($options instanceof \Traversable) { + if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } diff --git a/src/Client/Common.php b/src/Client/Common.php index bdc06dcf..95b282b2 100644 --- a/src/Client/Common.php +++ b/src/Client/Common.php @@ -9,11 +9,13 @@ namespace Zend\Soap\Client; +use SoapClient; + if (extension_loaded('soap')) { /** */ -class Common extends \SoapClient +class Common extends SoapClient { /** * doRequest() pre-processing method @@ -51,11 +53,12 @@ public function __construct($doRequestCallback, $wsdl, $options) */ public function __doRequest($request, $location, $action, $version, $oneWay = null) { + // ltrim is a workaround for https://bugs.php.net/bug.php?id=63780 if ($oneWay === null) { - return call_user_func($this->doRequestCallback, $this, $request, $location, $action, $version); + return call_user_func($this->doRequestCallback, $this, ltrim($request), $location, $action, $version); } - return call_user_func( $this->doRequestCallback, $this, $request, $location, $action, $version, $oneWay); + return call_user_func($this->doRequestCallback, $this, ltrim($request), $location, $action, $version, $oneWay); } } diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index 74f9f6c8..47ac5ed9 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -9,10 +9,12 @@ namespace Zend\Soap\Exception; +use BadMethodCallException as SPLBadMethodCallException; + /** * Exception thrown when method is badly called */ class BadMethodCallException - extends \BadMethodCallException + extends SPLBadMethodCallException implements ExceptionInterface {} diff --git a/src/Exception/ExtensionNotLoadedException.php b/src/Exception/ExtensionNotLoadedException.php index 40d81740..c5661731 100644 --- a/src/Exception/ExtensionNotLoadedException.php +++ b/src/Exception/ExtensionNotLoadedException.php @@ -9,6 +9,8 @@ namespace Zend\Soap\Exception; +use RuntimeException; + /** * Exception thrown when soap php extension is not loaded * diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 9e9d12f3..814669c5 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -9,11 +9,13 @@ namespace Zend\Soap\Exception; +use InvalidArgumentException as SPLInvalidArgumentException; + /** * Exception thrown when arguments to method are invalid * */ class InvalidArgumentException - extends \InvalidArgumentException + extends SPLInvalidArgumentException implements ExceptionInterface {} diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index b9080286..7cf1701c 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -9,11 +9,13 @@ namespace Zend\Soap\Exception; +use RuntimeException as SPLRuntimeException; + /** * Exception thrown when there is an error during program execution * */ class RuntimeException - extends \RuntimeException + extends SPLRuntimeException implements ExceptionInterface {} diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php index b17433e7..d4622d45 100644 --- a/src/Exception/UnexpectedValueException.php +++ b/src/Exception/UnexpectedValueException.php @@ -9,11 +9,13 @@ namespace Zend\Soap\Exception; +use UnexpectedValueException as SPLUnexpectedValueException; + /** * Exception thrown when provided arguments are invalid * */ class UnexpectedValueException - extends \UnexpectedValueException + extends SPLUnexpectedValueException implements ExceptionInterface {} diff --git a/src/Server.php b/src/Server.php index a345b12e..c018eef7 100644 --- a/src/Server.php +++ b/src/Server.php @@ -9,14 +9,22 @@ namespace Zend\Soap; +use SoapServer; use SoapFault; +use Traversable; +use DOMDocument; +use DOMNode; +use SimpleXMLElement; +use ReflectionClass; +use Zend\Soap\Exception; +use Zend\Server\Server as ZendServerServer; use Zend\Stdlib\ArrayUtils; /** * Zend_Soap_Server * */ -class Server implements \Zend\Server\Server +class Server implements ZendServerServer { /** * Actor URI @@ -165,7 +173,7 @@ public function __construct($wsdl = null, array $options = null) */ public function setOptions($options) { - if ($options instanceof \Traversable) { + if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } @@ -726,13 +734,13 @@ protected function _setRequest($request) { $xml = null; - if ($request instanceof \DOMDocument) { + if ($request instanceof DOMDocument) { $xml = $request->saveXML(); - } elseif ($request instanceof \DOMNode) { + } elseif ($request instanceof DOMNode) { $xml = $request->ownerDocument->saveXML(); - } elseif ($request instanceof \SimpleXMLElement) { + } elseif ($request instanceof SimpleXMLElement) { $xml = $request->asXML(); } elseif (is_object($request) || is_string($request)) { @@ -745,7 +753,7 @@ protected function _setRequest($request) libxml_disable_entity_loader(true); - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $loadStatus = $dom->loadXML($xml); //@todo check libxml errors ? validate document ? @@ -827,7 +835,7 @@ public function getResponse() protected function _getSoap() { $options = $this->getOptions(); - $server = new \SoapServer($this->wsdl, $options); + $server = new SoapServer($this->wsdl, $options); if (!empty($this->functions)) { $server->addFunction($this->functions); @@ -891,11 +899,10 @@ public function handle($request = null) $fault = false; $this->response = ''; - if ($setRequestException instanceof \Exception) { + if (is_object($setRequestException) && is_subclass_of($setRequestException, 'Exception')) { // Create SOAP fault message if we've caught a request exception $fault = $this->fault($setRequestException->getMessage(), 'Sender'); - } - if (!$setRequestException instanceof \Exception) { + } else { ob_start(); try { $soap->handle($this->request); @@ -960,10 +967,8 @@ public function registerFaultException($class) $this->registerFaultException($row); } - } elseif (is_string($class) && class_exists($class) - && is_subclass_of($class, 'Exception') - ) { - $ref = new \ReflectionClass($class); + } elseif (is_string($class) && class_exists($class) && is_subclass_of($class, 'Exception')) { + $ref = new ReflectionClass($class); $this->faultExceptions[] = $ref->getName(); $this->faultExceptions = array_unique($this->faultExceptions); @@ -985,7 +990,7 @@ public function registerFaultException($class) */ public function isRegisteredAsFaultException($fault) { - $ref = new \ReflectionClass($fault); + $ref = new ReflectionClass($fault); $classNames = $ref->getName(); @@ -1037,7 +1042,7 @@ public function getFaultExceptions() */ public function fault($fault = null, $code = 'Receiver') { - if ($fault instanceof \Exception) { + if (is_object($fault) && is_subclass_of($fault, 'Exception')) { if ($this->isRegisteredAsFaultException($fault)) { $message = $fault->getMessage(); $eCode = $fault->getCode(); diff --git a/src/Wsdl.php b/src/Wsdl.php index b22517dc..3928a8ee 100644 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -9,6 +9,11 @@ namespace Zend\Soap; +use DOMNode; +use DOMDocument; +use DOMDocumentFragment; +use DOMElement; +use DOMXPath; use Zend\Soap\Exception\InvalidArgumentException; use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy; use Zend\Uri\Uri; @@ -112,7 +117,7 @@ public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, a */ protected function getDOMDocument($name, $uri = null) { - $dom = new \DOMDocument(); + $dom = new DOMDocument(); //@todo new option for debug mode ? $dom->preserveWhiteSpace = false; $dom->formatOutput = false; @@ -164,11 +169,14 @@ public function getClassMap() /** * Set the class map of php to wsdl mappings.. + * + * @return \Zend\Soap\Wsdl */ public function setClassMap($classMap) { $this->classMap = $classMap; - //@todo return Wsdl? + + return $this; } /** @@ -189,12 +197,12 @@ public function setUri($uri) $oldUri = $this->uri; $this->uri = $uri; - if ($this->dom instanceof \DOMDocument ) { + if ($this->dom instanceof DOMDocument ) { // namespace declarations are NOT true attributes so one must explicitly set on root element // xmlns:tns = $uri $this->dom->documentElement->setAttributeNS(Wsdl::XML_NS_URI, Wsdl::XML_NS . ':' . Wsdl::TYPES_NS, $uri); - $xpath = new \DOMXPath($this->dom); + $xpath = new DOMXPath($this->dom); $xpath->registerNamespace('default', Wsdl::WSDL_NS_URI); $xpath->registerNamespace(Wsdl::TYPES_NS, $uri); @@ -564,13 +572,13 @@ public function addDocumentation($inputNode, $documentation) * * @return void */ - public function addTypes($types) + public function addTypes(DOMNode $types) { - if ($types instanceof \DOMDocument) { + if ($types instanceof DOMDocument) { $dom = $this->dom->importNode($types->documentElement); $this->wsdl->appendChild($dom); - } elseif ($types instanceof \DOMNode || $types instanceof \DOMElement || $types instanceof \DOMDocumentFragment ) { + } elseif ($types instanceof DOMNode || $types instanceof DOMElement || $types instanceof DOMDocumentFragment ) { $dom = $this->dom->importNode($types); $this->wsdl->appendChild($dom); } diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php index ce437861..2c6fde2f 100644 --- a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php +++ b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php @@ -9,6 +9,7 @@ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; +use ReflectionClass; use Zend\Soap\Exception; use Zend\Soap\Wsdl; @@ -40,7 +41,7 @@ public function addComplexType($type) } $dom = $this->getContext()->toDomDocument(); - $class = new \ReflectionClass($type); + $class = new ReflectionClass($type); $soapTypeName = $this->getContext()->translateType($type); $soapType = Wsdl::TYPES_NS . ':' . $soapTypeName; diff --git a/test/ServerTest.php b/test/ServerTest.php index d8b87d9b..6eaebdd2 100644 --- a/test/ServerTest.php +++ b/test/ServerTest.php @@ -747,7 +747,6 @@ public function testFaultWithRegisteredException() $server->registerFaultException('\Zend\Soap\Exception\RuntimeException'); $server->registerFaultException('\Zend\Soap\Exception\InvalidArgumentException'); $fault = $server->fault(new \Zend\Soap\Exception\RuntimeException('MyException')); - $this->assertTrue($fault instanceof \SoapFault); $this->assertNotContains('Unknown error', $fault->getMessage()); $this->assertContains('MyException', $fault->getMessage()); @@ -937,6 +936,7 @@ public function testShouldThrowExceptionIfHandledRequestContainsDoctype() . '' . '' . "\n"; $response = $server->handle($request); + var_dump($response->getMessage()); $this->assertContains('Invalid XML', $response->getMessage()); } diff --git a/test/WsdlTest.php b/test/WsdlTest.php index 40cef4c6..5f1df995 100644 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -768,6 +768,8 @@ public function dataProviderForTranslateType() { array('SomeType\\','SomeType'), array('\\SomeType\\','SomeType'), array('\\SomeNamespace\SomeType\\','SomeType'), + array('\\SomeNamespace\SomeType\\SomeOtherType','SomeOtherType'), + array('\\SomeNamespace\SomeType\\SomeOtherType\\YetAnotherType','YetAnotherType'), ); } diff --git a/test/schemas/wsdl.xsd b/test/schemas/wsdl.xsd index 0546b338..da851ce0 100644 --- a/test/schemas/wsdl.xsd +++ b/test/schemas/wsdl.xsd @@ -51,7 +51,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -133,7 +133,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -204,7 +204,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -221,9 +221,9 @@ No other rights are granted by implication, estoppel or otherwise. - - - + + + @@ -231,10 +231,10 @@ No other rights are granted by implication, estoppel or otherwise. - - - - + + + + @@ -331,4 +331,4 @@ No other rights are granted by implication, estoppel or otherwise. - \ No newline at end of file + From 27a3663038d2aa5ceb73c1ea9f1846344c6528f1 Mon Sep 17 00:00:00 2001 From: Grzegorz Drozd Date: Wed, 6 Mar 2013 10:46:46 +0100 Subject: [PATCH 17/22] Removed debug. --- test/ServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ServerTest.php b/test/ServerTest.php index 6eaebdd2..1a127b6b 100644 --- a/test/ServerTest.php +++ b/test/ServerTest.php @@ -936,7 +936,7 @@ public function testShouldThrowExceptionIfHandledRequestContainsDoctype() . '' . '' . "\n"; $response = $server->handle($request); - var_dump($response->getMessage()); + $this->assertContains('Invalid XML', $response->getMessage()); } From 9cc16d3f5d4dbf72acf2ef8018f97331915c5ba6 Mon Sep 17 00:00:00 2001 From: Nicolas Eeckeloo Date: Mon, 29 Apr 2013 09:38:13 +0200 Subject: [PATCH 18/22] Fix coding standards PSR-2 --- src/Client.php | 2 +- src/Wsdl/ComplexTypeStrategy/Composite.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 5d409e6f..662eef96 100644 --- a/src/Client.php +++ b/src/Client.php @@ -954,7 +954,7 @@ public function _doRequest(Client\Common $client, $request, $location, $action, { // Perform request as is if ($oneWay === null) { - return call_user_func(array($client,'SoapClient::__doRequest'), $request, $location, $action, $version); + return call_user_func(array($client, 'SoapClient::__doRequest'), $request, $location, $action, $version); } return call_user_func(array($client, 'SoapClient::__doRequest'), $request, $location, $action, $version, $oneWay); } diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php index 9939c824..d8bd756a 100644 --- a/src/Wsdl/ComplexTypeStrategy/Composite.php +++ b/src/Wsdl/ComplexTypeStrategy/Composite.php @@ -82,7 +82,7 @@ public function getDefaultStrategy() if (is_string($strategy) && class_exists($strategy)) { $strategy = new $strategy; } - if ( !($strategy instanceof ComplexTypeStrategy) ) { + if (!($strategy instanceof ComplexTypeStrategy)) { throw new Exception\InvalidArgumentException( 'Default Strategy for Complex Types is not a valid strategy object.' ); @@ -107,7 +107,7 @@ public function getStrategyOfType($type) $strategy = new $strategy(); } - if ( !($strategy instanceof ComplexTypeStrategy) ) { + if (!($strategy instanceof ComplexTypeStrategy)) { throw new Exception\InvalidArgumentException(sprintf( 'Strategy for Complex Type "%s" is not a valid strategy object.', $type @@ -141,7 +141,7 @@ public function setContext(Wsdl $context) */ public function addComplexType($type) { - if (!($this->context instanceof Wsdl) ) { + if (!($this->context instanceof Wsdl)) { throw new Exception\InvalidArgumentException(sprintf( 'Cannot add complex type "%s", no context is set for this composite strategy.', $type From d9e8bf09ebc47a572734d37a13ec1524c7a589d3 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 30 Apr 2013 11:40:39 -0500 Subject: [PATCH 19/22] [zendframework/zf2#3919] Incorporate feedback - Ensure params/return/throws annotations are in correct order, with no whitespace between. - Remove unnecessary empty lines. - Ensure properties are in alphabetical order. - Ensure classes referenced in docblocks are imported and/or resolved from current namespace. --- src/AutoDiscover.php | 96 ++-- .../DiscoveryStrategyInterface.php | 16 +- .../DiscoveryStrategy/ReflectionDiscovery.php | 18 +- src/Client.php | 316 +++++-------- src/Client/Common.php | 14 +- src/Client/DotNet.php | 49 +-- src/Client/Local.php | 20 +- src/Exception/BadMethodCallException.php | 6 +- src/Exception/ExceptionInterface.php | 1 - src/Exception/ExtensionNotLoadedException.php | 3 +- src/Exception/InvalidArgumentException.php | 7 +- src/Exception/RuntimeException.php | 5 +- src/Exception/UnexpectedValueException.php | 5 +- src/Server.php | 182 +++----- src/Server/DocumentLiteralWrapper.php | 38 +- src/Wsdl.php | 415 ++++++++---------- .../AbstractComplexTypeStrategy.php | 13 +- src/Wsdl/ComplexTypeStrategy/AnyType.php | 16 +- .../ArrayOfTypeComplex.php | 28 +- .../ArrayOfTypeSequence.php | 23 +- .../ComplexTypeStrategyInterface.php | 2 - src/Wsdl/ComplexTypeStrategy/Composite.php | 32 +- .../DefaultComplexType.php | 7 +- 23 files changed, 508 insertions(+), 804 deletions(-) diff --git a/src/AutoDiscover.php b/src/AutoDiscover.php index 8529afd6..2f0ecea5 100644 --- a/src/AutoDiscover.php +++ b/src/AutoDiscover.php @@ -17,10 +17,6 @@ use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy; use Zend\Uri; -/** - * \Zend\Soap\AutoDiscover - * - */ class AutoDiscover { /** @@ -29,7 +25,7 @@ class AutoDiscover protected $serviceName; /** - * @var \Zend\Server\Reflection + * @var Reflection */ protected $reflection = null; @@ -100,8 +96,12 @@ class AutoDiscover * @param null|string $wsdlClass * @param null|array $classMap */ - public function __construct(ComplexTypeStrategy $strategy = null, $endpointUri = null, $wsdlClass = null, array $classMap = array()) - { + public function __construct( + ComplexTypeStrategy $strategy = null, + $endpointUri = null, + $wsdlClass = null, + array $classMap = array() + ) { $this->reflection = new Reflection(); $this->setDiscoveryStrategy(new ReflectionDiscovery()); @@ -121,13 +121,11 @@ public function __construct(ComplexTypeStrategy $strategy = null, $endpointUri = * Set the discovery strategy for method type and other information. * * @param DiscoveryStrategy $discoveryStrategy - * - * @return AutoDiscover + * @return self */ public function setDiscoveryStrategy(DiscoveryStrategy $discoveryStrategy) { $this->discoveryStrategy = $discoveryStrategy; - return $this; } @@ -155,7 +153,7 @@ public function getClassMap() * Set the class map of php to wsdl mappings. * * @param array $classmap - * @return AutoDiscover + * @return self * @throws Exception\InvalidArgumentException */ public function setClassMap($classMap) @@ -167,8 +165,8 @@ public function setClassMap($classMap) (is_object($classMap) ? get_class($classMap) : gettype($classMap)) )); } - $this->classMap = $classMap; + $this->classMap = $classMap; return $this; } @@ -176,13 +174,13 @@ public function setClassMap($classMap) * Set service name * * @param string $serviceName + * @return self * @throws Exception\InvalidArgumentException - * - * @return AutoDiscover */ public function setServiceName($serviceName) { $matches = array(); + // first character must be letter or underscore {@see http://www.w3.org/TR/wsdl#_document-n} $i = preg_match('/^[a-z\_]/ims', $serviceName, $matches); if ($i != 1) { @@ -190,16 +188,14 @@ public function setServiceName($serviceName) } $this->serviceName = $serviceName; - return $this; } /** * Get service name * - * @throws Exception\RuntimeException - * * @return string + * @throws Exception\RuntimeException */ public function getServiceName() { @@ -210,7 +206,6 @@ public function getServiceName() throw new Exception\RuntimeException('No service name given. Call AutoDiscover::setServiceName().'); } } - return $this->serviceName; } @@ -219,9 +214,8 @@ public function getServiceName() * Set the location at which the WSDL file will be available. * * @param Uri\Uri|string $uri + * @return self * @throws Exception\InvalidArgumentException - * - * @return AutoDiscover */ public function setUri($uri) { @@ -239,16 +233,14 @@ public function setUri($uri) } $this->uri = $uri; - return $this; } /** * Return the current Uri that the SOAP WSDL Service will be located at. * - * @throws Exception\RuntimeException - * * @return Uri\Uri + * @throws Exception\RuntimeException */ public function getUri() { @@ -260,7 +252,6 @@ public function getUri() if (is_string($this->uri)) { $this->uri = Uri\UriFactory::factory($this->uri); } - return $this->uri; } @@ -268,9 +259,8 @@ public function getUri() * Set the name of the WSDL handling class. * * @param string $wsdlClass + * @return self * @throws Exception\InvalidArgumentException - * - * @return AutoDiscover */ public function setWsdlClass($wsdlClass) { @@ -281,7 +271,6 @@ public function setWsdlClass($wsdlClass) } $this->wsdlClass = $wsdlClass; - return $this; } @@ -302,9 +291,8 @@ public function getWsdlClass() * 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/". * * @param array $operationStyle + * @return self * @throws Exception\InvalidArgumentException - * - * @return AutoDiscover */ public function setOperationBodyStyle(array $operationStyle = array()) { @@ -312,7 +300,6 @@ public function setOperationBodyStyle(array $operationStyle = array()) throw new Exception\InvalidArgumentException('Key "use" is required in Operation soap:body style.'); } $this->operationBodyStyle = $operationStyle; - return $this; } @@ -322,8 +309,7 @@ public function setOperationBodyStyle(array $operationStyle = array()) * By default 'style' is 'rpc' and 'transport' is 'http://schemas.xmlsoap.org/soap/http'. * * @param array $bindingStyle - * - * @return AutoDiscover + * @return self */ public function setBindingStyle(array $bindingStyle = array()) { @@ -333,7 +319,6 @@ public function setBindingStyle(array $bindingStyle = array()) if (isset($bindingStyle['transport'])) { $this->bindingStyle['transport'] = $bindingStyle['transport']; } - return $this; } @@ -341,13 +326,11 @@ public function setBindingStyle(array $bindingStyle = array()) * Set the strategy that handles functions and classes that are added AFTER this call. * * @param ComplexTypeStrategy $strategy - * - * @return AutoDiscover + * @return self */ public function setComplexTypeStrategy(ComplexTypeStrategy $strategy) { $this->strategy = $strategy; - return $this; } @@ -355,23 +338,20 @@ public function setComplexTypeStrategy(ComplexTypeStrategy $strategy) * Set the Class the SOAP server will use * * @param string $class Class Name - * - * @return AutoDiscover + * @return self */ public function setClass($class) { $this->class = $class; - return $this; } /** * Add a Single or Multiple Functions to the WSDL * - * @param string $function Function Name + * @param string $function Function Name + * @return self * @throws Exception\InvalidArgumentException - * - * @return AutoDiscover */ public function addFunction($function) { @@ -393,7 +373,6 @@ public function addFunction($function) 'Argument to Zend\Soap\AutoDiscover::addFunction should be string or array of strings.' ); } - return $this; } @@ -418,15 +397,13 @@ protected function _generateFunctions() foreach (array_unique($this->functions) as $func) { $methods[] = $this->reflection->reflectFunction($func); } - return $this->_generateWsdl($methods); } /** * Generate the WSDL for a set of reflection method instances. * - * @param array $reflectionMethods - * + * @param array $reflectionMethods * @return Wsdl */ protected function _generateWsdl(array $reflectionMethods) @@ -435,7 +412,6 @@ protected function _generateWsdl(array $reflectionMethods) $serviceName = $this->getServiceName(); - /** @var $wsdl \Zend\Soap\Wsdl */ $wsdl = new $this->wsdlClass($serviceName, $uri, $this->strategy, $this->classMap); // The wsdl:types element must precede all other elements (WS-I Basic Profile 1.1 R2023) @@ -457,13 +433,11 @@ protected function _generateWsdl(array $reflectionMethods) /** * Add a function to the WSDL document. * - * @param $function \Zend\Server\Reflection\AbstractFunction function to add - * @param $wsdl \Zend\Soap\Wsdl WSDL document - * @param $port \DOMElement wsdl:portType - * @param $binding \DOMElement wsdl:binding + * @param $function Reflection\AbstractFunction function to add + * @param $wsdl Wsdl WSDL document + * @param $port \DOMElement wsdl:portType + * @param $binding \DOMElement wsdl:binding * @throws Exception\InvalidArgumentException - * - * @return void */ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) { @@ -472,7 +446,6 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) // We only support one prototype: the one with the maximum number of arguments $prototype = null; $maxNumArgumentsOfPrototype = -1; - /** @var $tmpPrototype \Zend\Server\Reflection\Prototype */ foreach ($function->getPrototypes() as $tmpPrototype) { $numParams = count($tmpPrototype->getParameters()); if ($numParams > $maxNumArgumentsOfPrototype) { @@ -494,7 +467,6 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) if ($this->bindingStyle['style'] == 'document') { // Document style: wrap all parameters in a sequence element $sequence = array(); - /** @var $param Reflection\ReflectionParameter */ foreach ($prototype->getParameters() as $param) { $sequenceElement = array( 'name' => $param->getName(), @@ -516,7 +488,6 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) } else { // RPC style: add each parameter as a typed part - /** @var $param Reflection\ReflectionParameter */ foreach ($prototype->getParameters() as $param) { $args[$param->getName()] = array( 'type' => $wsdl->getType($this->discoveryStrategy->getFunctionParameterType($param)) @@ -597,9 +568,8 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding) /** * Generate the WSDL file from the configured input. * - * @throws Exception\RuntimeException - * * @return Wsdl + * @throws Exception\RuntimeException */ public function generate() { @@ -619,10 +589,9 @@ public function generate() /** * Proxy to WSDL dump function * - * @param string $filename - * @throws \Zend\Soap\Exception\RuntimeException - * + * @param string $filename * @return bool + * @throws Exception\RuntimeException */ public function dump($filename) { @@ -632,9 +601,8 @@ public function dump($filename) /** * Proxy to WSDL toXml() function * - * @throws \Zend\Soap\Exception\RuntimeException - * * @return string + * @throws Exception\RuntimeException */ public function toXml() { @@ -643,8 +611,6 @@ public function toXml() /** * Handle WSDL document. - * - * @return void */ public function handle() { diff --git a/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php b/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php index 5c042b63..5ac8a6e8 100644 --- a/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php +++ b/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php @@ -14,8 +14,8 @@ use Zend\Server\Reflection\ReflectionParameter; /** - * Describes how types, return values and method details are detected during AutoDiscovery of a WSDL. - * + * Describes how types, return values and method details are detected during + * AutoDiscovery of a WSDL. */ interface DiscoveryStrategyInterface { @@ -24,7 +24,7 @@ interface DiscoveryStrategyInterface * * Default implementation assumes the default param doc-block tag. * - * @param ReflectionParameter $param + * @param ReflectionParameter $param * @return string */ public function getFunctionParameterType(ReflectionParameter $param); @@ -34,8 +34,8 @@ public function getFunctionParameterType(ReflectionParameter $param); * * Default implementation assumes the value of the return doc-block tag. * - * @param AbstractFunction $function - * @param Prototype $prototype + * @param AbstractFunction $function + * @param Prototype $prototype * @return string */ public function getFunctionReturnType(AbstractFunction $function, Prototype $prototype); @@ -45,8 +45,8 @@ public function getFunctionReturnType(AbstractFunction $function, Prototype $pro * * Default implementation assumes one-way, when return value is "void". * - * @param AbstractFunction $function - * @param Prototype $prototype + * @param AbstractFunction $function + * @param Prototype $prototype * @return bool */ public function isFunctionOneWay(AbstractFunction $function, Prototype $prototype); @@ -56,7 +56,7 @@ public function isFunctionOneWay(AbstractFunction $function, Prototype $prototyp * * Default implementation uses docblock description. * - * @param AbstractFunction $function + * @param AbstractFunction $function * @return string */ public function getFunctionDocumentation(AbstractFunction $function); diff --git a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php index 981e3fd9..44559de9 100644 --- a/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php +++ b/src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php @@ -16,16 +16,13 @@ /** * Describes how types, return values and method details are detected during * AutoDiscovery of a WSDL. - * */ - class ReflectionDiscovery implements DiscoveryStrategyInterface { /** * Returns description from phpdoc block * - * @param \Zend\Server\Reflection\AbstractFunction $function - * + * @param AbstractFunction $function * @return string */ public function getFunctionDocumentation(AbstractFunction $function) @@ -36,8 +33,7 @@ public function getFunctionDocumentation(AbstractFunction $function) /** * Return parameter type * - * @param \Zend\Server\Reflection\ReflectionParameter $param - * + * @param ReflectionParameter $param * @return string */ public function getFunctionParameterType(ReflectionParameter $param) @@ -48,9 +44,8 @@ public function getFunctionParameterType(ReflectionParameter $param) /** * Return function return type * - * @param \Zend\Server\Reflection\AbstractFunction $function - * @param \Zend\Server\Reflection\Prototype $prototype - * + * @param AbstractFunction $function + * @param Prototype $prototype * @return string */ public function getFunctionReturnType(AbstractFunction $function, Prototype $prototype) @@ -61,9 +56,8 @@ public function getFunctionReturnType(AbstractFunction $function, Prototype $pro /** * Return true if function is one way (return nothing) * - * @param \Zend\Server\Reflection\AbstractFunction $function - * @param \Zend\Server\Reflection\Prototype $prototype - * + * @param AbstractFunction $function + * @param Prototype $prototype * @return bool */ public function isFunctionOneWay(AbstractFunction $function, Prototype $prototype) diff --git a/src/Client.php b/src/Client.php index 09cc10f5..ef9b9ef0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -15,24 +15,20 @@ use Zend\Server\Client as ServerClient; use Zend\Stdlib\ArrayUtils; -/** - * \Zend\Soap\Client - * - */ class Client implements ServerClient { - /** - * Encoding - * @var string - */ - protected $encoding = 'UTF-8'; - /** * Array of SOAP type => PHP class pairings for handling return/incoming values * @var array */ protected $classmap = null; + /** + * Encoding + * @var string + */ + protected $encoding = 'UTF-8'; + /** * Registered fault exceptions * @var array @@ -40,50 +36,16 @@ class Client implements ServerClient protected $faultExceptions = array(); /** - * SOAP version to use; SOAP_1_2 by default, to allow processing of headers - * @var int - */ - protected $soapVersion = SOAP_1_2; - - /**#@+ + * Last invoked method * @var string */ - protected $uri = null; - protected $location = null; - protected $style = null; - protected $use = null; - protected $login = null; - protected $password = null; - protected $proxyHost = null; - protected $proxyPort = null; - protected $proxyLogin = null; - protected $proxyPassword = null; - protected $localCert = null; - protected $passphrase = null; - protected $connectionTimeout = null; - protected $streamContext = null; - protected $userAgent = null; - /**#@-*/ - - /**#@+ - * @var int - */ - protected $cacheWsdl = null; - protected $features = null; - protected $compression = null; - /**#@-*/ + protected $lastMethod = ''; /** + * Permanent SOAP request headers (shared between requests). * @var array */ - protected $typemap = null; - - /** - * WSDL used to access server - * It also defines Client working mode (WSDL vs non-WSDL) - * @var string - */ - protected $wsdl = null; + protected $permanentSoapInputHeaders = array(); /** * SoapClient object @@ -91,12 +53,6 @@ class Client implements ServerClient */ protected $soapClient; - /** - * Last invoked method - * @var string - */ - protected $lastMethod = ''; - /** * Array of SoapHeader objects * @var SoapHeader[] @@ -104,20 +60,58 @@ class Client implements ServerClient protected $soapInputHeaders = array(); /** - * Permanent SOAP request headers (shared between requests). + * Array of SoapHeader objects * @var array */ - protected $permanentSoapInputHeaders = array(); + protected $soapOutputHeaders = array(); + + /** + * SOAP version to use; SOAP_1_2 by default, to allow processing of headers + * @var int + */ + protected $soapVersion = SOAP_1_2; /** - * Array of SoapHeader objects * @var array */ - protected $soapOutputHeaders = array(); + protected $typemap = null; + + /** + * WSDL used to access server + * It also defines Client working mode (WSDL vs non-WSDL) + * @var string + */ + protected $wsdl = null; + + /**#@+ + * @var string + */ + protected $connectionTimeout = null; + protected $localCert = null; + protected $location = null; + protected $login = null; + protected $passphrase = null; + protected $password = null; + protected $proxyHost = null; + protected $proxyLogin = null; + protected $proxyPassword = null; + protected $proxyPort = null; + protected $streamContext = null; + protected $style = null; + protected $uri = null; + protected $use = null; + protected $userAgent = null; + /**#@-*/ + + /**#@+ + * @var int + */ + protected $cacheWsdl = null; + protected $compression = null; + protected $features = null; + /**#@-*/ /** - * Constructor - * * @param string $wsdl * @param array|Traversable $options * @throws Exception\ExtensionNotLoadedException @@ -139,9 +133,8 @@ public function __construct($wsdl = null, $options = null) /** * Set wsdl * - * @param string $wsdl - * - * @return Client + * @param string $wsdl + * @return self */ public function setWSDL($wsdl) { @@ -167,9 +160,8 @@ public function getWSDL() * Allows setting options as an associative array of option => value pairs. * * @param array|Traversable $options + * @return self * @throws Exception\InvalidArgumentException - * - * @return Client */ public function setOptions($options) { @@ -341,9 +333,8 @@ public function getOptions() * Set SOAP version * * @param int $version One of the SOAP_1_1 or SOAP_1_2 constants + * @return self * @throws Exception\InvalidArgumentException with invalid soap version argument - * - * @return Client */ public function setSoapVersion($version) { @@ -352,10 +343,9 @@ public function setSoapVersion($version) 'Invalid soap version specified. Use SOAP_1_1 or SOAP_1_2 constants.' ); } - $this->soapVersion = $version; - - $this->soapClient = null; + $this->soapVersion = $version; + $this->soapClient = null; return $this; } @@ -373,9 +363,8 @@ public function getSoapVersion() * Set classmap * * @param array $classmap + * @return self * @throws Exception\InvalidArgumentException for any invalid class in the class map - * - * @return Client */ public function setClassmap(array $classmap) { @@ -387,7 +376,6 @@ public function setClassmap(array $classmap) $this->classmap = $classmap; $this->soapClient = null; - return $this; } @@ -405,9 +393,8 @@ public function getClassmap() * Set typemap with xml to php type mappings with appropriate validation. * * @param array $typeMap + * @return self * @throws Exception\InvalidArgumentException - * - * @return Client */ public function setTypemap(array $typeMap) { @@ -422,7 +409,6 @@ public function setTypemap(array $typeMap) $this->typemap = $typeMap; $this->soapClient = null; - return $this; } @@ -440,9 +426,8 @@ public function getTypemap() * Set encoding * * @param string $encoding + * @return self * @throws Exception\InvalidArgumentException with invalid encoding argument - * - * @return Client */ public function setEncoding($encoding) { @@ -450,9 +435,8 @@ public function setEncoding($encoding) throw new Exception\InvalidArgumentException('Invalid encoding specified'); } - $this->encoding = $encoding; + $this->encoding = $encoding; $this->soapClient = null; - return $this; } @@ -470,9 +454,8 @@ public function getEncoding() * Check for valid URN * * @param string $urn - * @throws Exception\InvalidArgumentException on invalid URN - * * @return bool + * @throws Exception\InvalidArgumentException on invalid URN */ public function validateUrn($urn) { @@ -480,9 +463,7 @@ public function validateUrn($urn) if ($scheme === false || $scheme === null) { throw new Exception\InvalidArgumentException('Invalid URN'); } - return true; - } /** @@ -491,17 +472,14 @@ public function validateUrn($urn) * URI in Web Service the target namespace * * @param string $uri + * @return self * @throws Exception\InvalidArgumentException with invalid uri argument - * - * @return Client */ public function setUri($uri) { $this->validateUrn($uri); - $this->uri = $uri; - + $this->uri = $uri; $this->soapClient = null; - return $this; } @@ -521,17 +499,14 @@ public function getUri() * URI in Web Service the target namespace * * @param string $location + * @return self * @throws Exception\InvalidArgumentException with invalid uri argument - * - * @return Client */ public function setLocation($location) { $this->validateUrn($location); - $this->location = $location; - + $this->location = $location; $this->soapClient = null; - return $this; } @@ -549,9 +524,8 @@ public function getLocation() * Set request style * * @param int $style One of the SOAP_RPC or SOAP_DOCUMENT constants + * @return self * @throws Exception\InvalidArgumentException with invalid style argument - * - * @return Client */ public function setStyle($style) { @@ -561,10 +535,8 @@ public function setStyle($style) ); } - $this->style = $style; - + $this->style = $style; $this->soapClient = null; - return $this; } @@ -582,9 +554,8 @@ public function getStyle() * Set message encoding method * * @param int $use One of the SOAP_ENCODED or SOAP_LITERAL constants + * @return self * @throws Exception\InvalidArgumentException with invalid message encoding method argument - * - * @return Client */ public function setEncodingMethod($use) { @@ -594,10 +565,8 @@ public function setEncodingMethod($use) ); } - $this->use = $use; - + $this->use = $use; $this->soapClient = null; - return $this; } @@ -615,15 +584,12 @@ public function getEncodingMethod() * Set HTTP login * * @param string $login - * - * @return Client + * @return self */ public function setHttpLogin($login) { - $this->login = $login; - + $this->login = $login; $this->soapClient = null; - return $this; } @@ -641,15 +607,12 @@ public function getHttpLogin() * Set HTTP password * * @param string $password - * - * @return Client + * @return self */ public function setHttpPassword($password) { - $this->password = $password; - + $this->password = $password; $this->soapClient = null; - return $this; } @@ -667,15 +630,12 @@ public function getHttpPassword() * Set proxy host * * @param string $proxyHost - * - * @return Client + * @return self */ public function setProxyHost($proxyHost) { - $this->proxyHost = $proxyHost; - + $this->proxyHost = $proxyHost; $this->soapClient = null; - return $this; } @@ -693,15 +653,12 @@ public function getProxyHost() * Set proxy port * * @param int $proxyPort - * - * @return Client + * @return self */ public function setProxyPort($proxyPort) { - $this->proxyPort = (int) $proxyPort; - + $this->proxyPort = (int) $proxyPort; $this->soapClient = null; - return $this; } @@ -719,15 +676,12 @@ public function getProxyPort() * Set proxy login * * @param string $proxyLogin - * - * @return Client + * @return self */ public function setProxyLogin($proxyLogin) { $this->proxyLogin = $proxyLogin; - $this->soapClient = null; - return $this; } @@ -745,15 +699,12 @@ public function getProxyLogin() * Set proxy password * * @param string $proxyPassword - * - * @return Client + * @return self */ public function setProxyPassword($proxyPassword) { $this->proxyPassword = $proxyPassword; - - $this->soapClient = null; - + $this->soapClient = null; return $this; } @@ -761,9 +712,8 @@ public function setProxyPassword($proxyPassword) * Set HTTPS client certificate path * * @param string $localCert local certificate path + * @return self * @throws Exception\InvalidArgumentException with invalid local certificate path argument - * - * @return Client */ public function setHttpsCertificate($localCert) { @@ -771,10 +721,8 @@ public function setHttpsCertificate($localCert) throw new Exception\InvalidArgumentException('Invalid HTTPS client certificate path.'); } - $this->localCert = $localCert; - + $this->localCert = $localCert; $this->soapClient = null; - return $this; } @@ -792,15 +740,12 @@ public function getHttpsCertificate() * Set HTTPS client certificate passphrase * * @param string $passphrase - * - * @return Client + * @return self */ public function setHttpsCertPassphrase($passphrase) { $this->passphrase = $passphrase; - $this->soapClient = null; - return $this; } @@ -818,8 +763,7 @@ public function getHttpsCertPassphrase() * Set compression options * * @param int|null $compressionOptions - * - * @return Client + * @return self */ public function setCompressionOptions($compressionOptions) { @@ -857,9 +801,8 @@ public function getProxyPassword() * Set Stream Context * * @param resource $context + * @return self * @throws Exception\InvalidArgumentException - * - * @return Client */ public function setStreamContext($context) { @@ -868,7 +811,6 @@ public function setStreamContext($context) } $this->streamContext = $context; - return $this; } @@ -886,15 +828,12 @@ public function getStreamContext() * Set the SOAP Feature options. * * @param string|int $feature - * - * @return Client + * @return self */ public function setSoapFeatures($feature) { - $this->features = $feature; - + $this->features = $feature; $this->soapClient = null; - return $this; } @@ -911,9 +850,8 @@ public function getSoapFeatures() /** * Set the SOAP WSDL Caching Options * - * @param string|int|bool|null $caching - * - * @return Client + * @param string|int|bool|null $caching + * @return self */ public function setWSDLCache($caching) { @@ -941,8 +879,7 @@ public function getWSDLCache() * Set the string to use in User-Agent header * * @param string|null $userAgent - * - * @return Client + * @return self */ public function setUserAgent($userAgent) { @@ -989,7 +926,6 @@ public function getLastResponse() if ($this->soapClient !== null) { return $this->soapClient->__getLastResponse(); } - return ''; } @@ -1003,7 +939,6 @@ public function getLastRequestHeaders() if ($this->soapClient !== null) { return $this->soapClient->__getLastRequestHeaders(); } - return ''; } @@ -1017,7 +952,6 @@ public function getLastResponseHeaders() if ($this->soapClient !== null) { return $this->soapClient->__getLastResponseHeaders(); } - return ''; } @@ -1036,14 +970,12 @@ public function getLastMethod() * * May be overridden in subclasses * - * @internal - * @param Client\Common $client - * @param string $request - * @param string $location - * @param string $action - * @param int $version - * @param int $oneWay - * + * @param Client\Common $client + * @param string $request + * @param string $location + * @param string $action + * @param int $version + * @param int $oneWay * @return mixed */ public function _doRequest(Client\Common $client, $request, $location,$action, $version, $oneWay = null) @@ -1091,8 +1023,7 @@ protected function _initSoapClientObject() * * My be overridden in descendant classes * - * @param array $arguments - * + * @param array $arguments * @return array */ protected function _preProcessArguments($arguments) @@ -1106,8 +1037,7 @@ protected function _preProcessArguments($arguments) * * My be overridden in descendant classes * - * @param array $result - * + * @param array $result * @return array */ protected function _preProcessResult($result) @@ -1119,10 +1049,9 @@ protected function _preProcessResult($result) /** * Add SOAP input header * - * @param SoapHeader $header - * @param bool $permanent - * - * @return Client + * @param SoapHeader $header + * @param bool $permanent + * @return self */ public function addSoapInputHeader(SoapHeader $header, $permanent = false) { @@ -1131,20 +1060,18 @@ public function addSoapInputHeader(SoapHeader $header, $permanent = false) } else { $this->soapInputHeaders[] = $header; } - return $this; } /** * Reset SOAP input headers * - * @return Client + * @return self */ public function resetSoapInputHeaders() { $this->permanentSoapInputHeaders = array(); - $this->soapInputHeaders = array(); - + $this->soapInputHeaders = array(); return $this; } @@ -1161,9 +1088,8 @@ public function getLastSoapOutputHeaderObjects() /** * Perform a SOAP call * - * @param string $name - * @param array $arguments - * + * @param string $name + * @param array $arguments * @return mixed */ public function __call($name, $arguments) @@ -1195,7 +1121,6 @@ public function __call($name, $arguments) * * @param string $method Name of the method we want to call. * @param array $params List of parameters for the method. - * * @return mixed Returned results. */ public function call($method, $params = array()) @@ -1206,9 +1131,8 @@ public function call($method, $params = array()) /** * Return a list of available functions * - * @throws Exception\UnexpectedValueException - * * @return array + * @throws Exception\UnexpectedValueException */ public function getFunctions() { @@ -1220,16 +1144,14 @@ public function getFunctions() } $soapClient = $this->getSoapClient(); - return $soapClient->__getFunctions(); } /** * Return a list of SOAP types * - * @throws Exception\UnexpectedValueException - * * @return array + * @throws Exception\UnexpectedValueException */ public function getTypes() { @@ -1241,21 +1163,18 @@ public function getTypes() } $soapClient = $this->getSoapClient(); - return $soapClient->__getTypes(); } /** * Set SoapClient object * - * @param SoapClient $soapClient - * - * @return Client + * @param SoapClient $soapClient + * @return self */ public function setSoapClient(SoapClient $soapClient) { $this->soapClient = $soapClient; - return $this; } @@ -1269,23 +1188,20 @@ public function getSoapClient() if ($this->soapClient == null) { $this->_initSoapClientObject(); } - return $this->soapClient; } /** * Set cookie * - * @param string $cookieName - * @param string $cookieValue - * - * @return Client + * @param string $cookieName + * @param string $cookieValue + * @return self */ public function setCookie($cookieName, $cookieValue=null) { $soapClient = $this->getSoapClient(); $soapClient->__setCookie($cookieName, $cookieValue); - return $this; } } diff --git a/src/Client/Common.php b/src/Client/Common.php index 95b282b2..bf9eb5c8 100644 --- a/src/Client/Common.php +++ b/src/Client/Common.php @@ -13,8 +13,6 @@ if (extension_loaded('soap')) { -/** - */ class Common extends SoapClient { /** @@ -34,7 +32,6 @@ class Common extends SoapClient public function __construct($doRequestCallback, $wsdl, $options) { $this->doRequestCallback = $doRequestCallback; - parent::__construct($wsdl, $options); } @@ -43,12 +40,11 @@ public function __construct($doRequestCallback, $wsdl, $options) * Overridden to implement different transport layers, perform additional * XML processing or other purpose. * - * @param string $request - * @param string $location - * @param string $action - * @param int $version - * @param int $oneWay - * + * @param string $request + * @param string $location + * @param string $action + * @param int $version + * @param int $oneWay * @return mixed */ public function __doRequest($request, $location, $action, $version, $oneWay = null) diff --git a/src/Client/DotNet.php b/src/Client/DotNet.php index fa0248a9..7c47245f 100644 --- a/src/Client/DotNet.php +++ b/src/Client/DotNet.php @@ -19,14 +19,13 @@ /** * .NET SOAP client * - * Class is intended to be used with .Net Web Services. - * + * Class is intended to be used with .NET Web Services. */ class DotNet extends SOAPClient { /** * Curl HTTP client adapter. - * @var \Zend\Http\Client\Adapter\Curl + * @var CurlClient */ private $curlClient = null; @@ -77,7 +76,6 @@ public function __construct($wsdl = null, $options = null) * @param string $action The SOAP action to call. * @param int $version The SOAP version to use. * @param int $oneWay (Optional) The number 1 if a response is not expected. - * * @return string The XML SOAP response. */ public function _doRequest(CommonClient $client, $request, $location, $action, $version, $oneWay = null) @@ -87,14 +85,17 @@ public function _doRequest(CommonClient $client, $request, $location, $action, $ } $curlClient = $this->getCurlClient(); - //@todo persistent connection ? - $headers = array('Content-Type' => 'text/xml; charset=utf-8', - 'Method' => 'POST', - 'SOAPAction' => '"' . $action . '"', - 'User-Agent' => 'PHP-SOAP-CURL'); - $uri = new HttpUri($location); - - //@todo use parent set* options for ssl certificate authorization + + // @todo persistent connection ? + $headers = array( + 'Content-Type' => 'text/xml; charset=utf-8', + 'Method' => 'POST', + 'SOAPAction' => '"' . $action . '"', + 'User-Agent' => 'PHP-SOAP-CURL', + ); + $uri = new HttpUri($location); + + // @todo use parent set* options for ssl certificate authorization $curlClient->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_NTLM) ->setCurlOption(CURLOPT_SSL_VERIFYHOST, false) ->setCurlOption(CURLOPT_SSL_VERIFYPEER, false) @@ -104,7 +105,8 @@ public function _doRequest(CommonClient $client, $request, $location, $action, $ $curlClient->connect($uri->getHost(), $uri->getPort()); $curlClient->write('POST', $uri, 1.1, $headers, $request); $response = HttpResponse::fromString($curlClient->read()); - //@todo persistent connection ? + + // @todo persistent connection ? $curlClient->close(); // Save headers @@ -118,14 +120,13 @@ public function _doRequest(CommonClient $client, $request, $location, $action, $ /** * Returns the cURL client that is being used. * - * @return \Zend\Http\Client\Adapter\Curl The cURL client. + * @return CurlClient */ public function getCurlClient() { if ($this->curlClient === null) { $this->curlClient = new CurlClient(); } - return $this->curlClient; } @@ -153,13 +154,11 @@ public function getLastResponseHeaders() * Sets the cURL client to use. * * @param CurlClient $curlClient The cURL client. - * - * @return DotNet Fluent interface. + * @return self */ public function setCurlClient(CurlClient $curlClient) { $this->curlClient = $curlClient; - return $this; } @@ -170,8 +169,7 @@ public function setCurlClient(CurlClient $curlClient) * * @param array|\Traversable $options Options. * @throws \InvalidArgumentException If an unsupported option is passed. - * - * @return \Zend\Soap\Client Fluent interface. + * @return self */ public function setOptions($options) { @@ -181,7 +179,6 @@ public function setOptions($options) } $this->options = $options; - return parent::setOptions($options); } @@ -190,10 +187,9 @@ public function setOptions($options) * * My be overridden in descendant classes * - * @param array $arguments - * @throws Exception\RuntimeException - * + * @param array $arguments * @return array + * @throws Exception\RuntimeException */ protected function _preProcessArguments($arguments) { @@ -214,14 +210,12 @@ protected function _preProcessArguments($arguments) * * My be overridden in descendant classes * - * @param object $result - * + * @param object $result * @return mixed */ protected function _preProcessResult($result) { $resultProperty = $this->getLastMethod() . 'Result'; - return $result->$resultProperty; } @@ -229,7 +223,6 @@ protected function _preProcessResult($result) * Flattens an HTTP headers array into a string. * * @param array $headers The headers to flatten. - * * @return string The headers string. */ private function flattenHeaders(array $headers) diff --git a/src/Client/Local.php b/src/Client/Local.php index d82bd17f..6c634206 100644 --- a/src/Client/Local.php +++ b/src/Client/Local.php @@ -13,8 +13,6 @@ use Zend\Soap\Server as SOAPServer; /** - * \Zend\Soap\Client\Local - * * Class is intended to be used as local SOAP client which works * with a provided Server object. * @@ -24,14 +22,14 @@ class Local extends SOAPClient { /** * Server object - * @var \Zend\Soap\Server + * @var SOAPServer */ protected $server; /** * Local client constructor * - * @param \Zend\Soap\Server $server + * @param SOAPServer $server * @param string $wsdl * @param array $options */ @@ -48,14 +46,12 @@ public function __construct(SOAPServer $server, $wsdl, $options = null) /** * Actual "do request" method. * - * @internal - * @param \Zend\Soap\Client\Common $client - * @param string $request - * @param string $location - * @param string $action - * @param int $version - * @param int $oneWay - * + * @param Common $client + * @param string $request + * @param string $location + * @param string $action + * @param int $version + * @param int $oneWay * @return mixed */ public function _doRequest(Common $client, $request, $location, $action, $version, $oneWay = null) diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index 47ac5ed9..30af2d0c 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -12,9 +12,7 @@ use BadMethodCallException as SPLBadMethodCallException; /** - * Exception thrown when method is badly called + * Exception thrown when unrecognized method is called via overloading */ -class BadMethodCallException - extends SPLBadMethodCallException - implements ExceptionInterface +class BadMethodCallException extends SPLBadMethodCallException implements ExceptionInterface {} diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 2612fef8..e1bc31c0 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -11,7 +11,6 @@ /** * Common Exception interface - * */ interface ExceptionInterface {} diff --git a/src/Exception/ExtensionNotLoadedException.php b/src/Exception/ExtensionNotLoadedException.php index c5661731..94bb9efe 100644 --- a/src/Exception/ExtensionNotLoadedException.php +++ b/src/Exception/ExtensionNotLoadedException.php @@ -12,8 +12,7 @@ use RuntimeException; /** - * Exception thrown when soap php extension is not loaded - * + * Exception thrown when SOAP PHP extension is not loaded */ class ExtensionNotLoadedException extends RuntimeException {} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 814669c5..c71eec6f 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -12,10 +12,7 @@ use InvalidArgumentException as SPLInvalidArgumentException; /** - * Exception thrown when arguments to method are invalid - * + * Exception thrown when one or more method arguments are invalid */ -class InvalidArgumentException - extends SPLInvalidArgumentException - implements ExceptionInterface +class InvalidArgumentException extends SPLInvalidArgumentException implements ExceptionInterface {} diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 7cf1701c..b1290234 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -13,9 +13,6 @@ /** * Exception thrown when there is an error during program execution - * */ -class RuntimeException - extends SPLRuntimeException - implements ExceptionInterface +class RuntimeException extends SPLRuntimeException implements ExceptionInterface {} diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php index d4622d45..a3133d35 100644 --- a/src/Exception/UnexpectedValueException.php +++ b/src/Exception/UnexpectedValueException.php @@ -13,9 +13,6 @@ /** * Exception thrown when provided arguments are invalid - * */ -class UnexpectedValueException - extends SPLUnexpectedValueException - implements ExceptionInterface +class UnexpectedValueException extends SPLUnexpectedValueException implements ExceptionInterface {} diff --git a/src/Server.php b/src/Server.php index 63260baa..cf70071e 100644 --- a/src/Server.php +++ b/src/Server.php @@ -16,14 +16,9 @@ use DOMNode; use SimpleXMLElement; use ReflectionClass; -use Zend\Soap\Exception; use Zend\Server\Server as ZendServerServer; use Zend\Stdlib\ArrayUtils; -/** - * Zend_Soap_Server - * - */ class Server implements ZendServerServer { /** @@ -44,53 +39,41 @@ class Server implements ZendServerServer */ protected $classArgs = array(); - /** - * Object registered with this server - */ - protected $object; - /** * Array of SOAP type => PHP class pairings for handling return/incoming values * @var array */ protected $classmap; - /** - * Array of type mappings - * @var array - */ - protected $typemap; - /** * Encoding * @var string */ protected $encoding; - /** - * SOAP Server Features - * @var int - */ - protected $features; - - /** - * WSDL Caching Options of SOAP Server - * @var mixed - */ - protected $wsdlCache; - /** * Registered fault exceptions * @var array */ protected $faultExceptions = array(); + /** + * SOAP Server Features + * @var int + */ + protected $features; + /** * Functions registered with this server; may be either an array or the SOAP_FUNCTIONS_ALL constant * @var array|int */ protected $functions = array(); + /** + * Object registered with this server + */ + protected $object; + /** * Persistence mode; should be one of the SOAP persistence constants * @var int @@ -122,10 +105,10 @@ class Server implements ZendServerServer protected $soapVersion = SOAP_1_2; /** - * URI or path to WSDL - * @var string + * Array of type mappings + * @var array */ - protected $wsdl; + protected $typemap; /** * URI namespace for SOAP server @@ -133,6 +116,18 @@ class Server implements ZendServerServer */ protected $uri; + /** + * URI or path to WSDL + * @var string + */ + protected $wsdl; + + /** + * WSDL Caching Options of SOAP Server + * @var mixed + */ + protected $wsdlCache; + /** * Constructor * @@ -143,8 +138,8 @@ class Server implements ZendServerServer * If $wsdl is provided, it is passed on to {@link setWSDL()}; if any * options are specified, they are passed on to {@link setOptions()}. * - * @param string $wsdl - * @param array $options + * @param string $wsdl + * @param array $options * @throws Exception\ExtensionNotLoadedException */ public function __construct($wsdl = null, array $options = null) @@ -168,8 +163,7 @@ public function __construct($wsdl = null, array $options = null) * Allows setting options as an associative array of option => value pairs. * * @param array|\Traversable $options - * - * @return \Zend\Soap\Server + * @return self */ public function setOptions($options) { @@ -273,9 +267,8 @@ public function getOptions() * Set encoding * * @param string $encoding + * @return self * @throws Exception\InvalidArgumentException with invalid encoding argument - * - * @return Server */ public function setEncoding($encoding) { @@ -284,7 +277,6 @@ public function setEncoding($encoding) } $this->encoding = $encoding; - return $this; } @@ -302,9 +294,8 @@ public function getEncoding() * Set SOAP version * * @param int $version One of the SOAP_1_1 or SOAP_1_2 constants + * @return self * @throws Exception\InvalidArgumentException with invalid soap version argument - * - * @return Server */ public function setSoapVersion($version) { @@ -313,7 +304,6 @@ public function setSoapVersion($version) } $this->soapVersion = $version; - return $this; } @@ -331,9 +321,8 @@ public function getSoapVersion() * Check for valid URN * * @param string $urn - * @throws Exception\InvalidArgumentException on invalid URN - * * @return true + * @throws Exception\InvalidArgumentException on invalid URN */ public function validateUrn($urn) { @@ -351,13 +340,12 @@ public function validateUrn($urn) * Actor is the actor URI for the server. * * @param string $actor - * @return Server + * @return self */ public function setActor($actor) { $this->validateUrn($actor); $this->actor = $actor; - return $this; } @@ -377,14 +365,12 @@ public function getActor() * URI in SoapServer is actually the target namespace, not a URI; $uri must begin with 'urn:'. * * @param string $uri - * - * @return Server + * @return self */ public function setUri($uri) { $this->validateUrn($uri); $this->uri = $uri; - return $this; } @@ -402,9 +388,8 @@ public function getUri() * Set classmap * * @param array $classmap + * @return self * @throws Exception\InvalidArgumentException for any invalid class in the class map - * - * @return Server */ public function setClassmap($classmap) { @@ -418,7 +403,6 @@ public function setClassmap($classmap) } $this->classmap = $classmap; - return $this; } @@ -435,10 +419,9 @@ public function getClassmap() /** * Set typemap with xml to php type mappings with appropriate validation. * - * @param array $typeMap + * @param array $typeMap + * @return self * @throws Exception\InvalidArgumentException - * - * @return Server */ public function setTypemap($typeMap) { @@ -456,7 +439,6 @@ public function setTypemap($typeMap) } $this->typemap = $typeMap; - return $this; } @@ -473,14 +455,12 @@ public function getTypemap() /** * Set wsdl * - * @param string $wsdl URI or path to a WSDL - * - * @return Server + * @param string $wsdl URI or path to a WSDL + * @return self */ public function setWSDL($wsdl) { $this->wsdl = $wsdl; - return $this; } @@ -498,13 +478,11 @@ public function getWSDL() * Set the SOAP Feature options. * * @param string|int $feature - * - * @return Server + * @return self */ public function setSoapFeatures($feature) { $this->features = $feature; - return $this; } @@ -521,14 +499,12 @@ public function getSoapFeatures() /** * Set the SOAP WSDL Caching Options * - * @param string|int|bool $options - * - * @return Server + * @param string|int|bool $options + * @return self */ public function setWSDLCache($options) { $this->wsdlCache = $options; - return $this; } @@ -543,12 +519,11 @@ public function getWSDLCache() /** * Attach a function as a server method * - * @param array|string $function Function name, array of function names to attach, - * or SOAP_FUNCTIONS_ALL to attach all functions + * @param array|string $function Function name, array of function names to attach, + * or SOAP_FUNCTIONS_ALL to attach all functions * @param string $namespace Ignored + * @return self * @throws Exception\InvalidArgumentException on invalid functions - * - * @return Server */ public function addFunction($function, $namespace = '') { @@ -591,12 +566,12 @@ public function addFunction($function, $namespace = '') * * See {@link setObject()} to set pre-configured object instances as request handlers. * - * @param string|object $class Class name or object instance which executes SOAP Requests at endpoint. - * @param string $namespace - * @param $argv + * @param string|object $class Class name or object instance which executes + * SOAP Requests at endpoint. + * @param string $namespace + * @param null|array $argv + * @return self * @throws Exception\InvalidArgumentException if called more than once, or if class does not exist - * - * @return Server */ public function setClass($class, $namespace = '', $argv = null) { @@ -636,10 +611,9 @@ public function setClass($class, $namespace = '', $argv = null) * * Accepts an instantiated object to use when handling requests. * - * @param object $object + * @param object $object + * @return self * @throws Exception\InvalidArgumentException - * - * @return Server */ public function setObject($object) { @@ -657,7 +631,6 @@ public function setObject($object) } $this->object = $object; - return $this; } @@ -685,10 +658,8 @@ public function getFunctions() /** * Unimplemented: Load server definition * - * @param array $definition + * @param array $definition * @throws Exception\RuntimeException Unimplemented - * - * @return void */ public function loadFunctions($definition) { @@ -698,10 +669,9 @@ public function loadFunctions($definition) /** * Set server persistence * - * @param int $mode SOAP_PERSISTENCE_SESSION or SOAP_PERSISTENCE_REQUEST constants + * @param int $mode SOAP_PERSISTENCE_SESSION or SOAP_PERSISTENCE_REQUEST constants + * @return self * @throws Exception\InvalidArgumentException - * - * @return Server */ public function setPersistence($mode) { @@ -710,7 +680,6 @@ public function setPersistence($mode) } $this->persistence = $mode; - return $this; } @@ -734,10 +703,9 @@ public function getPersistence() * - stdClass; if so, calls __toString() and verifies XML * - string; if so, verifies XML * - * @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request + * @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request + * @return self * @throws Exception\InvalidArgumentException - * - * @return Server */ protected function _setRequest($request) { @@ -765,7 +733,7 @@ protected function _setRequest($request) $dom = new DOMDocument(); $loadStatus = $dom->loadXML($xml); - //@todo check libxml errors ? validate document ? + // @todo check libxml errors ? validate document ? if (strlen($xml) == 0 || !$loadStatus) { throw new Exception\InvalidArgumentException('Invalid XML'); } @@ -779,7 +747,6 @@ protected function _setRequest($request) } $this->request = $xml; - return $this; } @@ -802,13 +769,11 @@ public function getLastRequest() * The response is always available via {@link getResponse()}. * * @param bool $flag - * - * @return Server + * @return self */ public function setReturnResponse($flag = true) { $this->returnResponse = ($flag) ? true : false; - return $this; } @@ -839,7 +804,7 @@ public function getResponse() * SoapServer object, and then registers any functions or class with it, as * well as persistence. * - * @return \SoapServer + * @return SoapServer */ protected function _getSoap() { @@ -883,8 +848,7 @@ protected function _getSoap() * If no request is passed, pulls request using php:://input (for * cross-platform compatibility purposes). * - * @param \DOMDocument|\DOMNode|\SimpleXMLElement|\stdClass|string $request Optional request - * + * @param DOMDocument|DOMNode|SimpleXMLElement|stdClass|string $request Optional request * @return void|string */ public function handle($request = null) @@ -965,9 +929,8 @@ protected function _initializeSoapErrorContext() * Validate and register fault exception * * @param string|array $class Exception class or array of exception classes + * @return self * @throws Exception\InvalidArgumentException - * - * @return Server */ public function registerFaultException($class) { @@ -994,15 +957,12 @@ public function registerFaultException($class) * Checks if provided fault name is registered as valid in this server. * * @param $fault Name of a fault class - * * @return bool */ public function isRegisteredAsFaultException($fault) { - $ref = new ReflectionClass($fault); - + $ref = new ReflectionClass($fault); $classNames = $ref->getName(); - return in_array($classNames, $this->faultExceptions); } @@ -1010,7 +970,6 @@ public function isRegisteredAsFaultException($fault) * Deregister a fault exception from the fault exception stack * * @param string $class - * * @return bool */ public function deregisterFaultException($class) @@ -1046,7 +1005,6 @@ public function getFaultExceptions() * @link http://www.w3.org/TR/soap12-part1/#faultcodes * @param string|\Exception $fault * @param string $code SOAP Fault Codes - * * @return SoapFault */ public function fault($fault = null, $code = 'Receiver') @@ -1076,14 +1034,12 @@ public function fault($fault = null, $code = 'Receiver') /** * Throw PHP errors as SoapFaults * - * @param int $errno - * @param string $errstr - * @param string $errfile - * @param int $errline - * @param array $errcontext - * @throws \SoapFault - * - * @return void + * @param int $errno + * @param string $errstr + * @param string $errfile + * @param int $errline + * @param array $errcontext + * @throws SoapFault */ public function handlePhpErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null) { diff --git a/src/Server/DocumentLiteralWrapper.php b/src/Server/DocumentLiteralWrapper.php index ada86ae4..7c30208b 100644 --- a/src/Server/DocumentLiteralWrapper.php +++ b/src/Server/DocumentLiteralWrapper.php @@ -59,11 +59,12 @@ * of SOAP this wrapper service handles the parsing between the formats. * * @example - * + * * $service = new MyCalculatorService(); * $soap = new \Zend\Soap\Server($wsdlFile); * $soap->setObject(new \Zend\Soap\Server\DocumentLiteralWrapper($service)); * $soap->handle(); + * */ class DocumentLiteralWrapper { @@ -91,9 +92,8 @@ public function __construct($object) /** * Proxy method that does the heavy document/literal decomposing. * - * @param string $method - * @param array $args - * + * @param string $method + * @param array $args * @return mixed */ public function __call($method, $args) @@ -102,8 +102,7 @@ public function __call($method, $args) $this->_assertServiceDelegateHasMethod($method); $delegateArgs = $this->_parseArguments($method, $args[0]); - $ret = call_user_func_array(array($this->object, $method), $delegateArgs); - + $ret = call_user_func_array(array($this->object, $method), $delegateArgs); return $this->_getResultMessage($method, $ret); } @@ -111,16 +110,14 @@ public function __call($method, $args) * Parse the document/literal wrapper into arguments to call the real * service. * - * @param string $method - * @param object $document - * @throws \Zend\Soap\Exception\UnexpectedValueException - * + * @param string $method + * @param object $document * @return array + * @throws Exception\UnexpectedValueException */ protected function _parseArguments($method, $document) { $reflMethod = $this->reflection->getMethod($method); - /* @var \Zend\Server\Reflection\ReflectionParameter[] $params */ $params = array(); foreach ($reflMethod->getParameters() as $param) { $params[$param->getName()] = $param; @@ -145,9 +142,8 @@ protected function _parseArguments($method, $document) /** * Returns result message content * - * @param $method - * @param $ret - * + * @param string $method + * @param mixed $ret * @return array */ protected function _getResultMessage($method, $ret) @@ -156,10 +152,8 @@ protected function _getResultMessage($method, $ret) } /** - * @param $method - * @throws \Zend\Soap\Exception\BadMethodCallException - * - * @return void + * @param string $method + * @throws Exception\BadMethodCallException */ protected function _assertServiceDelegateHasMethod($method) { @@ -173,12 +167,10 @@ protected function _assertServiceDelegateHasMethod($method) } /** - * @param $args - * @throws \Zend\Soap\Exception\UnexpectedValueException - * - * @return void + * @param array $args + * @throws Exception\UnexpectedValueException */ - protected function _assertOnlyOneArgument($args) + protected function _assertOnlyOneArgument(array $args) { if (count($args) != 1) { throw new Exception\UnexpectedValueException(sprintf( diff --git a/src/Wsdl.php b/src/Wsdl.php index 3928a8ee..37180748 100644 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -18,34 +18,37 @@ use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy; use Zend\Uri\Uri; -/** - * \Zend\Soap\Wsdl - * - */ class Wsdl { - /** - * DOM Instance - * @var \DOMDocument - */ - private $dom; - - /** - * Root XML_Tree_Node - * @var \DOMElement WSDL + /**#@+ + * XML Namespace uris and prefixes. */ - private $wsdl; + const XML_NS = 'xmlns'; + const XML_NS_URI = 'http://www.w3.org/2000/xmlns/'; + const WSDL_NS = 'wsdl'; + const WSDL_NS_URI = 'http://schemas.xmlsoap.org/wsdl/'; + const SOAP_11_NS = 'soap'; + const SOAP_11_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap/'; + const SOAP_12_NS = 'soap12'; + const SOAP_12_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap12/'; + const SOAP_ENC_NS = 'soap-enc'; + const SOAP_ENC_URI = 'http://schemas.xmlsoap.org/soap/encoding/'; + const XSD_NS = 'xsd'; + const XSD_NS_URI = 'http://www.w3.org/2001/XMLSchema'; + const TYPES_NS = 'tns'; + /**#@-*/ /** - * URI where the WSDL will be available - * @var string + * Map of PHP Class names to WSDL QNames. + * @var array */ - private $uri; + protected $classMap = array(); /** - * @var \DOMElement + * DOM Instance + * @var DOMDocument */ - private $schema = null; + private $dom; /** * Types defined on schema @@ -53,56 +56,50 @@ class Wsdl */ private $includedTypes = array(); + /** + * @var DOMElement + */ + private $schema = null; + /** * Strategy for detection of complex types */ protected $strategy = null; /** - * Map of PHP Class names to WSDL QNames. - * @var array + * URI where the WSDL will be available + * @var string */ - protected $classMap = array(); + private $uri; - /**#@+ - * XML Namespace uris and prefixes. + /** + * Root XML_Tree_Node + * @var DOMElement WSDL */ - const XML_NS = 'xmlns'; - const XML_NS_URI = 'http://www.w3.org/2000/xmlns/'; - const WSDL_NS = 'wsdl'; - const WSDL_NS_URI = 'http://schemas.xmlsoap.org/wsdl/'; - const SOAP_11_NS = 'soap'; - const SOAP_11_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap/'; - const SOAP_12_NS = 'soap12'; - const SOAP_12_NS_URI = 'http://schemas.xmlsoap.org/wsdl/soap12/'; - const SOAP_ENC_NS = 'soap-enc'; - const SOAP_ENC_URI = 'http://schemas.xmlsoap.org/soap/encoding/'; - const XSD_NS = 'xsd'; - const XSD_NS_URI = 'http://www.w3.org/2001/XMLSchema'; - const TYPES_NS = 'tns'; - /**#@-*/ + private $wsdl; /** - * Constructor - * - * @param string $name Name of the Web Service being Described - * @param string|Uri $uri URI where the WSDL will be available - * @param null|ComplexTypeStrategy $strategy Strategy for detection of complex types - * @param null|array $classMap Map of PHP Class names to WSDL QNames + * @param string $name Name of the Web Service being Described + * @param string|Uri $uri URI where the WSDL will be available + * @param null|ComplexTypeStrategy $strategy Strategy for detection of complex types + * @param null|array $classMap Map of PHP Class names to WSDL QNames * @throws Exception\RuntimeException */ - public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, array $classMap = array()) - { + public function __construct( + $name, + $uri, + ComplexTypeStrategy $strategy = null, + array $classMap = array() + ) { if ($uri instanceof Uri) { $uri = $uri->toString(); } $this->setUri($uri); - $this->classMap = $classMap; - $this->dom = $this->getDOMDocument($name, $this->getUri()); - - $this->wsdl = $this->dom->documentElement; + $this->classMap = $classMap; + $this->dom = $this->getDOMDocument($name, $this->getUri()); + $this->wsdl = $this->dom->documentElement; $this->setComplexTypeStrategy($strategy ?: new Wsdl\ComplexTypeStrategy\DefaultComplexType); } @@ -110,34 +107,34 @@ public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, a /** * Get the wsdl XML document with all namespaces and required attributes * - * @param string $uri - * @param string $name - * - * @return \DOMDocument + * @param string $uri + * @param string $name + * @return DOMDocument */ protected function getDOMDocument($name, $uri = null) { $dom = new DOMDocument(); - //@todo new option for debug mode ? + + // @todo new option for debug mode ? $dom->preserveWhiteSpace = false; $dom->formatOutput = false; $dom->resolveExternals = false; $dom->encoding = 'UTF-8'; $dom->substituteEntities = false; - $definitions = $dom->createElementNS(Wsdl::WSDL_NS_URI, 'definitions'); + $definitions = $dom->createElementNS(self::WSDL_NS_URI, 'definitions'); $dom->appendChild($definitions); $uri = $this->sanitizeUri($uri); $this->setAttributeWithSanitization($definitions, 'name', $name); $this->setAttributeWithSanitization($definitions, 'targetNamespace', $uri); - $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::WSDL_NS, Wsdl::WSDL_NS_URI); - $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::TYPES_NS, $uri); - $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::SOAP_11_NS, Wsdl::SOAP_11_NS_URI); - $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::XSD_NS, Wsdl::XSD_NS_URI); - $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::SOAP_ENC_NS, Wsdl::SOAP_ENC_URI); - $definitions->setAttributeNS(Wsdl::XML_NS_URI, 'xmlns:'.Wsdl::SOAP_12_NS, Wsdl::SOAP_12_NS_URI); + $definitions->setAttributeNS(self::XML_NS_URI, 'xmlns:'. self::WSDL_NS, self::WSDL_NS_URI); + $definitions->setAttributeNS(self::XML_NS_URI, 'xmlns:'. self::TYPES_NS, $uri); + $definitions->setAttributeNS(self::XML_NS_URI, 'xmlns:'. self::SOAP_11_NS, self::SOAP_11_NS_URI); + $definitions->setAttributeNS(self::XML_NS_URI, 'xmlns:'. self::XSD_NS, self::XSD_NS_URI); + $definitions->setAttributeNS(self::XML_NS_URI, 'xmlns:'. self::SOAP_ENC_NS, self::SOAP_ENC_URI); + $definitions->setAttributeNS(self::XML_NS_URI, 'xmlns:'. self::SOAP_12_NS, self::SOAP_12_NS_URI); return $dom; } @@ -153,7 +150,6 @@ public function getTargetNamespace() if ($this->wsdl !== null) { $targetNamespace = $this->wsdl->getAttribute('targetNamespace'); } - return $targetNamespace; } @@ -170,12 +166,11 @@ public function getClassMap() /** * Set the class map of php to wsdl mappings.. * - * @return \Zend\Soap\Wsdl + * @return self */ public function setClassMap($classMap) { $this->classMap = $classMap; - return $this; } @@ -183,8 +178,7 @@ public function setClassMap($classMap) * Set a new uri for this WSDL * * @param string|Uri $uri - * - * @return \Zend\Soap\Wsdl + * @return self */ public function setUri($uri) { @@ -200,24 +194,24 @@ public function setUri($uri) if ($this->dom instanceof DOMDocument ) { // namespace declarations are NOT true attributes so one must explicitly set on root element // xmlns:tns = $uri - $this->dom->documentElement->setAttributeNS(Wsdl::XML_NS_URI, Wsdl::XML_NS . ':' . Wsdl::TYPES_NS, $uri); + $this->dom->documentElement->setAttributeNS(self::XML_NS_URI, self::XML_NS . ':' . self::TYPES_NS, $uri); $xpath = new DOMXPath($this->dom); - $xpath->registerNamespace('default', Wsdl::WSDL_NS_URI); - - $xpath->registerNamespace(Wsdl::TYPES_NS, $uri); - $xpath->registerNamespace(Wsdl::SOAP_11_NS, Wsdl::SOAP_11_NS_URI); - $xpath->registerNamespace(Wsdl::SOAP_12_NS, Wsdl::SOAP_12_NS_URI); - $xpath->registerNamespace(Wsdl::XSD_NS, Wsdl::XSD_NS_URI); - $xpath->registerNamespace(Wsdl::SOAP_ENC_NS, Wsdl::SOAP_ENC_URI); - $xpath->registerNamespace(Wsdl::WSDL_NS, Wsdl::WSDL_NS_URI); - - // select only attribute nodes. Data nodes does not contain uri except for documentation node but - // this is for the user to decide. This list does not include xmlns:tsn attribute of document root. - // That attribute is changed above + $xpath->registerNamespace('default', self::WSDL_NS_URI); + + $xpath->registerNamespace(self::TYPES_NS, $uri); + $xpath->registerNamespace(self::SOAP_11_NS, self::SOAP_11_NS_URI); + $xpath->registerNamespace(self::SOAP_12_NS, self::SOAP_12_NS_URI); + $xpath->registerNamespace(self::XSD_NS, self::XSD_NS_URI); + $xpath->registerNamespace(self::SOAP_ENC_NS, self::SOAP_ENC_URI); + $xpath->registerNamespace(self::WSDL_NS, self::WSDL_NS_URI); + + // Select only attribute nodes. Data nodes does not contain uri + // except for documentation node but this is for the user to decide. + // This list does not include xmlns:tsn attribute of document root. + // That attribute is changed above. $attributeNodes = $xpath->query('//attribute::*[contains(., "' . $oldUri . '")]'); - /** @var $node \DOMAttr */ foreach ($attributeNodes as $node) { $attributeValue = $this->dom->createTextNode(str_replace($oldUri, $uri, $node->nodeValue)); $node->replaceChild($attributeValue, $node->childNodes->item(0)); @@ -240,10 +234,9 @@ public function getUri() /** * Function for sanitizing uri * - * @param $uri - * @throws Exception\InvalidArgumentException - * + * @param string|Uri $uri * @return string + * @throws Exception\InvalidArgumentException */ public function sanitizeUri($uri) { @@ -255,7 +248,7 @@ public function sanitizeUri($uri) $uri = htmlspecialchars($uri, ENT_QUOTES, 'UTF-8', false); if (empty($uri)) { - throw new InvalidArgumentException('Uri contains invalid characters or is empty'); + throw new Exception\InvalidArgumentException('Uri contains invalid characters or is empty'); } return $uri; @@ -264,14 +257,12 @@ public function sanitizeUri($uri) /** * Set a strategy for complex type detection and handling * - * @param ComplexTypeStrategy $strategy - * - * @return \Zend\Soap\Wsdl + * @param ComplexTypeStrategy $strategy + * @return self */ public function setComplexTypeStrategy(ComplexTypeStrategy $strategy) { $this->strategy = $strategy; - return $this; } @@ -288,24 +279,22 @@ public function getComplexTypeStrategy() /** * Add a {@link http://www.w3.org/TR/wsdl#_messages message} element to the WSDL * - * @param string $messageName Name for the {@link http://www.w3.org/TR/wsdl#_messages message} - * @param array $parts An array of {@link http://www.w3.org/TR/wsdl#_message parts} - * The array is constructed like: - * 'name of part' => 'part xml schema data type' or - * 'name of part' => array('type' => 'part xml schema type') or - * 'name of part' => array('element' => 'part xml element name') - * - * @return \DOMElement The new message's XML_Tree_Node for use in {@link function addDocumentation} + * @param string $messageName Name for the {@link http://www.w3.org/TR/wsdl#_messages message} + * @param array $parts An array of {@link http://www.w3.org/TR/wsdl#_message parts} + * The array is constructed like: + * 'name of part' => 'part xml schema data type' or + * 'name of part' => array('type' => 'part xml schema type') or + * 'name of part' => array('element' => 'part xml element name') + * @return DOMElement The new message's XML_Tree_Node for use in {@link function addDocumentation} */ public function addMessage($messageName, $parts) { - $message = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'message'); - + $message = $this->dom->createElementNS(self::WSDL_NS_URI, 'message'); $message->setAttribute('name', $messageName); if (count($parts) > 0) { foreach ($parts as $name => $type) { - $part = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'part'); + $part = $this->dom->createElementNS(self::WSDL_NS_URI, 'part'); $message->appendChild($part); $part->setAttribute('name', $name); @@ -318,59 +307,54 @@ public function addMessage($messageName, $parts) } $this->wsdl->appendChild($message); - return $message; } /** * Add a {@link http://www.w3.org/TR/wsdl#_porttypes portType} element to the WSDL * - * @param string $name portType element's name - * - * @return \DOMElement The new portType's XML_Tree_Node for use in {@link function addPortOperation} and addDocumentation@link function addDocumentation} + * @param string $name portType element's name + * @return DOMElement The new portType's XML_Tree_Node for use in {@link function addPortOperation} and addDocumentation@link function addDocumentation} */ public function addPortType($name) { - $portType = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'portType'); + $portType = $this->dom->createElementNS(self::WSDL_NS_URI, 'portType'); $this->wsdl->appendChild($portType); - $portType->setAttribute('name', $name); - return $portType; } /** * Add an {@link http://www.w3.org/TR/wsdl#request-response operation} element to a portType element * - * @param \DOMElement $portType a portType XML_Tree_Node, from {@link function addPortType} - * @param string $name Operation name - * @param bool|string $input Input Message - * @param bool|string $output Output Message - * @param bool|string $fault Fault Message - * - * @return \DOMElement The new operation's XML_Tree_Node for use in {@link function addDocumentation} + * @param DOMElement $portType a portType XML_Tree_Node, from {@link function addPortType} + * @param string $name Operation name + * @param bool|string $input Input Message + * @param bool|string $output Output Message + * @param bool|string $fault Fault Message + * @return DOMElement The new operation's XML_Tree_Node for use in {@link function addDocumentation} */ public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false) { - $operation = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'operation'); + $operation = $this->dom->createElementNS(self::WSDL_NS_URI, 'operation'); $portType->appendChild($operation); $operation->setAttribute('name', $name); if (is_string($input) && (strlen(trim($input)) >= 1)) { - $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'input'); + $node = $this->dom->createElementNS(self::WSDL_NS_URI, 'input'); $operation->appendChild($node); $node->setAttribute('message', $input); } if (is_string($output) && (strlen(trim($output)) >= 1)) { - $node= $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'output'); + $node= $this->dom->createElementNS(self::WSDL_NS_URI, 'output'); $operation->appendChild($node); $node->setAttribute('message', $output); } if (is_string($fault) && (strlen(trim($fault)) >= 1)) { - $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'fault'); + $node = $this->dom->createElementNS(self::WSDL_NS_URI, 'fault'); $operation->appendChild($node); $node->setAttribute('message', $fault); } @@ -381,14 +365,13 @@ public function addPortOperation($portType, $name, $input = false, $output = fal /** * Add a {@link http://www.w3.org/TR/wsdl#_bindings binding} element to WSDL * - * @param string $name Name of the Binding - * @param string $portType name of the portType to bind - * - * @return \DOMElement The new binding's XML_Tree_Node for use with {@link function addBindingOperation} and {@link function addDocumentation} + * @param string $name Name of the Binding + * @param string $portType name of the portType to bind + * @return DOMElement The new binding's XML_Tree_Node for use with {@link function addBindingOperation} and {@link function addDocumentation} */ public function addBinding($name, $portType) { - $binding = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'binding'); + $binding = $this->dom->createElementNS(self::WSDL_NS_URI, 'binding'); $this->wsdl->appendChild($binding); $this->setAttribute($binding, 'name', $name); @@ -400,30 +383,29 @@ public function addBinding($name, $portType) /** * Add an operation to a binding element * - * @param \DOMElement $binding A binding XML_Tree_Node returned by {@link function addBinding} - * @param string $name - * @param array|bool $input An array of attributes for the input element, - * allowed keys are: 'use', 'namespace', 'encodingStyle'. - * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param array|bool $output An array of attributes for the output element, - * allowed keys are: 'use', 'namespace', 'encodingStyle'. - * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param array|bool $fault An array with attributes for the fault element, - * allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. - * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} - * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 - * - * @return \DOMElement The new Operation's XML_Tree_Node for use with {@link function addSoapOperation} and {@link function addDocumentation} + * @param DOMElement $binding A binding XML_Tree_Node returned by {@link function addBinding} + * @param string $name + * @param array|bool $input An array of attributes for the input element, + * allowed keys are: 'use', 'namespace', 'encodingStyle'. + * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * @param array|bool $output An array of attributes for the output element, + * allowed keys are: 'use', 'namespace', 'encodingStyle'. + * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * @param array|bool $fault An array with attributes for the fault element, + * allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. + * {@link http://www.w3.org/TR/wsdl#_soap:body More Information} + * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 + * @return DOMElement The new Operation's XML_Tree_Node for use with {@link function addSoapOperation} and {@link function addDocumentation} */ public function addBindingOperation($binding, $name, $input = false, $output = false, $fault = false, $soapVersion = SOAP_1_1) { - $operation = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'operation'); + $operation = $this->dom->createElementNS(self::WSDL_NS_URI, 'operation'); $binding->appendChild($operation); $this->setAttribute($operation, 'name', $name); if (is_array($input) && !empty($input)) { - $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'input'); + $node = $this->dom->createElementNS(self::WSDL_NS_URI, 'input'); $operation->appendChild($node); $soapNode = $this->dom->createElementNS($this->getSoapNamespaceUriByVersion($soapVersion), 'body'); @@ -433,7 +415,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f } if (is_array($output) && !empty($output)) { - $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'output'); + $node = $this->dom->createElementNS(self::WSDL_NS_URI, 'output'); $operation->appendChild($node); $soapNode = $this->dom->createElementNS($this->getSoapNamespaceUriByVersion($soapVersion), 'body'); @@ -443,7 +425,7 @@ public function addBindingOperation($binding, $name, $input = false, $output = f } if (is_array($fault) && !empty($fault)) { - $node = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'fault'); + $node = $this->dom->createElementNS(self::WSDL_NS_URI, 'fault'); $operation->appendChild($node); $this->arrayToAttributes($node, $fault); @@ -455,12 +437,11 @@ public function addBindingOperation($binding, $name, $input = false, $output = f /** * Add a {@link http://www.w3.org/TR/wsdl#_soap:binding SOAP binding} element to a Binding element * - * @param \DOMElement $binding A binding XML_Tree_Node returned by {@link function addBinding} - * @param string $style binding style, possible values are "rpc" (the default) and "document" - * @param string $transport Transport method (defaults to HTTP) - * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 - * - * @return \DOMElement + * @param DOMElement $binding A binding XML_Tree_Node returned by {@link function addBinding} + * @param string $style binding style, possible values are "rpc" (the default) and "document" + * @param string $transport Transport method (defaults to HTTP) + * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 + * @return DOMElement */ public function addSoapBinding($binding, $style = 'document', $transport = 'http://schemas.xmlsoap.org/soap/http', $soapVersion = SOAP_1_1) { @@ -476,11 +457,10 @@ public function addSoapBinding($binding, $style = 'document', $transport = 'http /** * Add a {@link http://www.w3.org/TR/wsdl#_soap:operation SOAP operation} to an operation element * - * @param \DOMElement $operation An operation XML_Tree_Node returned by {@link function addBindingOperation} - * @param string $soapAction SOAP Action - * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 - * - * @return \DOMElement + * @param DOMElement $operation An operation XML_Tree_Node returned by {@link function addBindingOperation} + * @param string $soapAction SOAP Action + * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 + * @return DOMElement */ public function addSoapOperation($operation, $soapAction, $soapVersion = SOAP_1_1) { @@ -498,13 +478,12 @@ public function addSoapOperation($operation, $soapAction, $soapVersion = SOAP_1_ /** * Add a {@link http://www.w3.org/TR/wsdl#_services service} element to the WSDL * - * @param string $name Service Name - * @param string $portName Name of the port for the service - * @param string $binding Binding for the port - * @param string $location SOAP Address for the service - * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 - * - * @return \DOMElement The new service's XML_Tree_Node for use with {@link function addDocumentation} + * @param string $name Service Name + * @param string $portName Name of the port for the service + * @param string $binding Binding for the port + * @param string $location SOAP Address for the service + * @param int $soapVersion SOAP version: SOAP_1_1 or SOAP_1_2, default: SOAP_1_1 + * @return DOMElement The new service's XML_Tree_Node for use with {@link function addDocumentation} */ public function addService($name, $portName, $binding, $location, $soapVersion = SOAP_1_1) { @@ -523,12 +502,10 @@ public function addService($name, $portName, $binding, $location, $soapVersion = $port->setAttribute('name', $portName); $port->setAttribute('binding', $binding); - $soapAddress = $this->dom->createElementNS($this->getSoapNamespaceUriByVersion($soapVersion), 'address'); $port->appendChild($soapAddress); $this->setAttributeWithSanitization($soapAddress, 'location', $location); - return $service; } @@ -539,10 +516,9 @@ public function addService($name, $portName, $binding, $location, $soapVersion = * but the WSDL {@link http://schemas.xmlsoap.org/wsdl/ schema} uses 'documentation' instead. * The {@link http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html#WSDL_documentation_Element WS-I Basic Profile 1.1} recommends using 'documentation'. * - * @param \DOMElement $inputNode An XML_Tree_Node returned by another method to add the documentation to - * @param string $documentation Human readable documentation for the node - * - * @return \DOMElement The documentation element + * @param DOMElement $inputNode An XML_Tree_Node returned by another method to add the documentation to + * @param string $documentation Human readable documentation for the node + * @return DOMElement The documentation element */ public function addDocumentation($inputNode, $documentation) { @@ -561,23 +537,19 @@ public function addDocumentation($inputNode, $documentation) $docCData = $this->dom->createTextNode(str_replace(array("\r\n", "\r"), "\n", $documentation)); $doc->appendChild($docCData); - return $doc; } /** * Add WSDL Types element * - * @param \DOMDocument|\DOMNode|\DOMElement|\DOMDocumentFragment $types A DOMDocument|DOMNode|DOMElement|DOMDocumentFragment with all the XML Schema types defined in it - * - * @return void + * @param DOMDocument|DOMNode|DOMElement|DOMDocumentFragment $types A DOMDocument|DOMNode|DOMElement|DOMDocumentFragment with all the XML Schema types defined in it */ public function addTypes(DOMNode $types) { if ($types instanceof DOMDocument) { $dom = $this->dom->importNode($types->documentElement); $this->wsdl->appendChild($dom); - } elseif ($types instanceof DOMNode || $types instanceof DOMElement || $types instanceof DOMDocumentFragment ) { $dom = $this->dom->importNode($types); $this->wsdl->appendChild($dom); @@ -587,17 +559,15 @@ public function addTypes(DOMNode $types) /** * Add a complex type name that is part of this WSDL and can be used in signatures. * - * @param string $type - * @param string $wsdlType - * - * @return \Zend\Soap\Wsdl + * @param string $type + * @param string $wsdlType + * @return self */ public function addType($type, $wsdlType) { if (!isset($this->includedTypes[$type])) { $this->includedTypes[$type] = $wsdlType; } - return $this; } @@ -614,14 +584,13 @@ public function getTypes() /** * Return the Schema node of the WSDL * - * @return \DOMElement + * @return DOMElement */ public function getSchema() { if ($this->schema == null) { $this->addSchemaTypeSection(); } - return $this->schema; } @@ -633,27 +602,24 @@ public function getSchema() public function toXML() { $this->dom->normalizeDocument(); - return $this->dom->saveXML(); } /** * Return DOM Document * - * @return \DOMDocument + * @return DOMDocument */ public function toDomDocument() { $this->dom->normalizeDocument(); - return $this->dom; } /** * Echo the WSDL as XML * - * @param bool $filename - * + * @param bool $filename * @return bool */ public function dump($filename = false) @@ -671,8 +637,7 @@ public function dump($filename = false) /** * Returns an XSD Type for the given PHP type * - * @param string $type PHP Type to get the XSD type for - * + * @param string $type PHP Type to get the XSD type for * @return string */ public function getType($type) @@ -680,33 +645,33 @@ public function getType($type) switch (strtolower($type)) { case 'string': case 'str': - return Wsdl::XSD_NS . ':string'; + return self::XSD_NS . ':string'; case 'long': - return Wsdl::XSD_NS . ':long'; + return self::XSD_NS . ':long'; case 'int': case 'integer': - return Wsdl::XSD_NS . ':int'; + return self::XSD_NS . ':int'; case 'float': - return Wsdl::XSD_NS . ':float'; + return self::XSD_NS . ':float'; case 'double': - return Wsdl::XSD_NS . ':double'; + return self::XSD_NS . ':double'; case 'boolean': case 'bool': - return Wsdl::XSD_NS . ':boolean'; + return self::XSD_NS . ':boolean'; case 'array': - return Wsdl::SOAP_ENC_NS . ':Array'; + return self::SOAP_ENC_NS . ':Array'; case 'object': - return Wsdl::XSD_NS . ':struct'; + return self::XSD_NS . ':struct'; case 'mixed': - return Wsdl::XSD_NS . ':anyType'; + return self::XSD_NS . ':anyType'; case 'void': return ''; @@ -720,12 +685,12 @@ public function getType($type) /** * This function makes sure a complex types section and schema additions are set. * - * @return \Zend\Soap\Wsdl + * @return self */ public function addSchemaTypeSection() { if ($this->schema === null) { - $types = $this->dom->createElementNS(Wsdl::WSDL_NS_URI, 'types'); + $types = $this->dom->createElementNS(self::WSDL_NS_URI, 'types'); $this->wsdl->appendChild($types); $this->schema = $this->dom->createElementNS(WSDL::XSD_NS_URI, 'schema'); @@ -740,8 +705,7 @@ public function addSchemaTypeSection() /** * Translate PHP type into WSDL QName * - * @param string $type - * + * @param string $type * @return string QName */ public function translateType($type) @@ -764,8 +728,7 @@ public function translateType($type) /** * Add a {@link http://www.w3.org/TR/wsdl#_types types} data type definition * - * @param string $type Name of the class to be specified - * + * @param string $type Name of the class to be specified * @return string XSD Type for the given PHP type */ public function addComplexType($type) @@ -785,10 +748,9 @@ public function addComplexType($type) /** * Parse an xsd:element represented as an array into a DOMElement. * - * @param array $element an xsd:element represented as an array + * @param array $element an xsd:element represented as an array + * @return DOMElement parsed element * @throws Exception\RuntimeException if $element is not an array - * - * @return \DOMElement parsed element */ private function _parseElement($element) { @@ -796,13 +758,13 @@ private function _parseElement($element) throw new Exception\RuntimeException('The "element" parameter needs to be an associative array.'); } - $elementXML = $this->dom->createElementNS(Wsdl::XSD_NS_URI, 'element'); + $elementXML = $this->dom->createElementNS(self::XSD_NS_URI, 'element'); foreach ($element as $key => $value) { if (in_array($key, array('sequence', 'all', 'choice'))) { if (is_array($value)) { - $complexType = $this->dom->createElementNS(Wsdl::XSD_NS_URI, 'complexType'); + $complexType = $this->dom->createElementNS(self::XSD_NS_URI, 'complexType'); if (count($value) > 0) { - $container = $this->dom->createElementNS(Wsdl::XSD_NS_URI, $key); + $container = $this->dom->createElementNS(self::XSD_NS_URI, $key); foreach ($value as $subElement) { $subElementXML = $this->_parseElement($subElement); $container->appendChild($subElementXML); @@ -822,9 +784,8 @@ private function _parseElement($element) /** * Prepare attribute value for specific attributes * - * @param string $name - * @param mixed $value - * + * @param string $name + * @param mixed $value * @return string safe value or original $value */ private function sanitizeAttributeValueByName($name, $value) @@ -846,11 +807,9 @@ private function sanitizeAttributeValueByName($name, $value) /** * Convert associative array to attributes of given node using optional {@link function sanitizeAttributeValueByName} * - * @param \DOMNode $node - * @param array $attributes - * @param bool $withSanitizer - * - * @return void + * @param DOMNode $node + * @param array $attributes + * @param bool $withSanitizer */ private function arrayToAttributes(\DOMNode $node, array $attributes, $withSanitizer = true) { @@ -866,11 +825,9 @@ private function arrayToAttributes(\DOMNode $node, array $attributes, $withSanit /** * Set attribute to given node using {@link function sanitizeAttributeValueByName} * - * @param \DOMNode $node - * @param string $attributeName - * @param mixed $attributeValue - * - * @return void + * @param DOMNode $node + * @param string $attributeName + * @param mixed $attributeValue */ private function setAttributeWithSanitization(\DOMNode $node, $attributeName, $attributeValue) { @@ -881,11 +838,9 @@ private function setAttributeWithSanitization(\DOMNode $node, $attributeName, $a /** * Set attribute to given node * - * @param \DOMNode $node - * @param string $attributeName - * @param mixed $attributeValue - * - * @return void + * @param DOMNode $node + * @param string $attributeName + * @param mixed $attributeValue */ private function setAttribute(\DOMNode $node, $attributeName, $attributeValue) { @@ -899,10 +854,9 @@ private function setAttribute(\DOMNode $node, $attributeName, $attributeValue) /** * Return soap namespace uri according to $soapVersion * - * @param int $soapVersion SOAP_1_1 or SOAP_1_2 constants - * @throws Exception\InvalidArgumentException - * + * @param int $soapVersion SOAP_1_1 or SOAP_1_2 constants * @return string + * @throws Exception\InvalidArgumentException */ private function getSoapNamespaceUriByVersion($soapVersion) { @@ -911,10 +865,10 @@ private function getSoapNamespaceUriByVersion($soapVersion) } if ($soapVersion == SOAP_1_1) { - return Wsdl::SOAP_11_NS_URI; + return self::SOAP_11_NS_URI; } - return Wsdl::SOAP_12_NS_URI; + return self::SOAP_12_NS_URI; } /** @@ -932,8 +886,7 @@ private function getSoapNamespaceUriByVersion($soapVersion) * * * - * @param array $element an xsd:element represented as an array - * + * @param array $element an xsd:element represented as an array * @return string xsd:element for the given element array */ public function addElement($element) @@ -942,6 +895,6 @@ public function addElement($element) $elementXml = $this->_parseElement($element); $schema->appendChild($elementXml); - return Wsdl::TYPES_NS . ':' . $element['name']; + return self::TYPES_NS . ':' . $element['name']; } } diff --git a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php index b8cbac03..36bc8bfc 100644 --- a/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php +++ b/src/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php @@ -12,8 +12,7 @@ use Zend\Soap\Wsdl; /** - * Abstract class for Zend_Soap_Wsdl_Strategy. - * + * Abstract class for Zend\Soap\Wsdl\Strategy. */ abstract class AbstractComplexTypeStrategy implements ComplexTypeStrategyInterface { @@ -24,11 +23,9 @@ abstract class AbstractComplexTypeStrategy implements ComplexTypeStrategyInterfa protected $context; /** - * Set the Zend_Soap_Wsdl Context object this strategy resides in. + * Set the WSDL Context object this strategy resides in. * * @param Wsdl $context - * - * @return void */ public function setContext(Wsdl $context) { @@ -36,7 +33,7 @@ public function setContext(Wsdl $context) } /** - * Return the current Zend_Soap_Wsdl context object + * Return the current WSDL context object * * @return Wsdl */ @@ -48,8 +45,7 @@ public function getContext() /** * Look through registered types * - * @param string $phpType - * + * @param string $phpType * @return string */ public function scanRegisteredTypes($phpType) @@ -59,7 +55,6 @@ public function scanRegisteredTypes($phpType) $soapTypes = $this->getContext()->getTypes(); return $soapTypes[$phpType]; } - return null; } } diff --git a/src/Wsdl/ComplexTypeStrategy/AnyType.php b/src/Wsdl/ComplexTypeStrategy/AnyType.php index 2ab59003..26365054 100644 --- a/src/Wsdl/ComplexTypeStrategy/AnyType.php +++ b/src/Wsdl/ComplexTypeStrategy/AnyType.php @@ -9,31 +9,23 @@ namespace Zend\Soap\Wsdl\ComplexTypeStrategy; -/** - * Zend_Soap_Wsdl_Strategy_AnyType - * - */ use Zend\Soap\Wsdl; -/** - * Class AnyType - * - */ class AnyType implements ComplexTypeStrategyInterface { /** * Not needed in this strategy. * - * @param \Zend\Soap\Wsdl $context + * @param Wsdl $context */ public function setContext(Wsdl $context) - {} + { + } /** * Returns xsd:anyType regardless of the input. * - * @param string $type - * + * @param string $type * @return string */ public function addComplexType($type) diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php index 40a044cf..b9b4a4c7 100644 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeComplex.php @@ -12,20 +12,15 @@ use Zend\Soap\Exception; use Zend\Soap\Wsdl; -/** - * ArrayOfTypeComplex strategy - * - */ class ArrayOfTypeComplex extends DefaultComplexType { /** * Add an ArrayOfType based on the xsd:complexType syntax if type[] is * detected in return value doc comment. * - * @param string $type - * @throws Exception\InvalidArgumentException - * + * @param string $type * @return string tns:xsd-type + * @throws Exception\InvalidArgumentException */ public function addComplexType($type) { @@ -37,26 +32,26 @@ public function addComplexType($type) $nestingLevel = $this->_getNestedCount($type); if ($nestingLevel == 0) { - return parent::addComplexType($singularType); - } elseif ($nestingLevel == 1) { + } - // The following blocks define the Array of Object structure - return $this->_addArrayOfComplexType($singularType, $type); - } else { + if ($nestingLevel != 1) { throw new Exception\InvalidArgumentException( - 'ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than one level. Use array object properties to return deep nested data.' + 'ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than one level. ' + . 'Use array object properties to return deep nested data.' ); } + + // The following blocks define the Array of Object structure + return $this->_addArrayOfComplexType($singularType, $type); } /** * Add an ArrayOfType based on the xsd:complexType syntax if type[] is * detected in return value doc comment. * - * @param string $singularType e.g. '\MyNamespace\MyClassname' - * @param string $type e.g. '\MyNamespace\MyClassname[]' - * + * @param string $singularType e.g. '\MyNamespace\MyClassname' + * @param string $type e.g. '\MyNamespace\MyClassname[]' * @return string tns:xsd-type e.g. 'tns:ArrayOfMyNamespace.MyClassname' */ protected function _addArrayOfComplexType($singularType, $type) @@ -107,7 +102,6 @@ protected function _addArrayOfComplexType($singularType, $type) * From a nested definition with type[], get the singular PHP Type * * @param string $type - * * @return string */ protected function _getSingularPhpType($type) diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php index 11f1ec6f..13255d9d 100644 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php @@ -11,18 +11,13 @@ use Zend\Soap\Wsdl; -/** - * Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence - * - */ class ArrayOfTypeSequence extends DefaultComplexType { /** * Add an unbounded ArrayOfType based on the xsd:sequence syntax if * type[] is detected in return value doc comment. * - * @param string $type - * + * @param string $type * @return string tns:xsd-type */ public function addComplexType($type) @@ -42,15 +37,15 @@ public function addComplexType($type) } return $complexType; - } elseif (($soapType = $this->scanRegisteredTypes($type)) !== null) { - + } + + if (($soapType = $this->scanRegisteredTypes($type)) !== null) { // Existing complex type return $soapType; - } else { - - // New singular complex type - return parent::addComplexType($type); } + + // New singular complex type + return parent::addComplexType($type); } /** @@ -59,7 +54,6 @@ public function addComplexType($type) * * @param string $singularType * @param int $level - * * @return string */ protected function _getTypeBasedOnNestingLevel($singularType, $level) @@ -76,7 +70,6 @@ protected function _getTypeBasedOnNestingLevel($singularType, $level) * From a nested definition with type[], get the singular xsd:type * * @param string $type - * * @return string */ protected function _getSingularType($type) @@ -101,8 +94,6 @@ protected function _getNestedCount($type) * @param string $arrayType Array type name (e.g. 'tns:ArrayOfArrayOfInt') * @param string $childType Qualified array items type (e.g. 'xsd:int', 'tns:ArrayOfInt') * @param string $phpArrayType PHP type (e.g. 'int[][]', '\MyNamespace\MyClassName[][][]') - * - * @return void */ protected function _addSequenceType($arrayType, $childType, $phpArrayType) { diff --git a/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php b/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php index 36a01165..1324ecf5 100644 --- a/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php +++ b/src/Wsdl/ComplexTypeStrategy/ComplexTypeStrategyInterface.php @@ -13,7 +13,6 @@ /** * Interface strategies that generate an XSD-Schema for complex data types in WSDL files. - * */ interface ComplexTypeStrategyInterface { @@ -28,7 +27,6 @@ public function setContext(Wsdl $context); * Create a complex type based on a strategy * * @param string $type - * * @return string XSD type */ public function addComplexType($type); diff --git a/src/Wsdl/ComplexTypeStrategy/Composite.php b/src/Wsdl/ComplexTypeStrategy/Composite.php index 3ec72df9..ea8f0a12 100644 --- a/src/Wsdl/ComplexTypeStrategy/Composite.php +++ b/src/Wsdl/ComplexTypeStrategy/Composite.php @@ -13,10 +13,6 @@ use Zend\Soap\Wsdl; use Zend\Soap\Wsdl\ComplexTypeStrategy\ComplexTypeStrategyInterface as ComplexTypeStrategy; -/** - * Zend_Soap_Wsdl_Strategy_Composite - * - */ class Composite implements ComplexTypeStrategy { /** @@ -33,7 +29,7 @@ class Composite implements ComplexTypeStrategy /** * Context WSDL file that this composite serves - * @var \Zend\Soap\Wsdl|null + * @var Wsdl|null */ protected $context; @@ -43,9 +39,11 @@ class Composite implements ComplexTypeStrategy * @param array $typeMap * @param string|ComplexTypeStrategy $defaultStrategy */ - public function __construct(array $typeMap=array(),$defaultStrategy = '\Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType') - { - foreach ($typeMap AS $type => $strategy) { + public function __construct( + array $typeMap = array(), + $defaultStrategy = 'Zend\Soap\Wsdl\ComplexTypeStrategy\DefaultComplexType' + ) { + foreach ($typeMap as $type => $strategy) { $this->connectTypeToStrategy($type, $strategy); } @@ -57,9 +55,8 @@ public function __construct(array $typeMap=array(),$defaultStrategy = '\Zend\Soa * * @param string $type * @param string|ComplexTypeStrategy $strategy - * @throws Exception\InvalidArgumentException - * * @return Composite + * @throws Exception\InvalidArgumentException */ public function connectTypeToStrategy($type, $strategy) { @@ -67,16 +64,14 @@ public function connectTypeToStrategy($type, $strategy) throw new Exception\InvalidArgumentException('Invalid type given to Composite Type Map.'); } $this->typeMap[$type] = $strategy; - return $this; } /** * Return default strategy of this composite * - * @throws Exception\InvalidArgumentException - * * @return ComplexTypeStrategy + * @throws Exception\InvalidArgumentException */ public function getDefaultStrategy() { @@ -90,7 +85,6 @@ public function getDefaultStrategy() ); } $this->defaultStrategy = $strategy; - return $strategy; } @@ -98,9 +92,8 @@ public function getDefaultStrategy() * Return specific strategy or the default strategy of this type. * * @param string $type - * @throws Exception\InvalidArgumentException - * * @return ComplexTypeStrategy + * @throws Exception\InvalidArgumentException */ public function getStrategyOfType($type) { @@ -128,14 +121,12 @@ public function getStrategyOfType($type) /** * Method accepts the current WSDL context file. * - * @param \Zend\Soap\Wsdl $context - * + * @param Wsdl $context * @return Composite */ public function setContext(Wsdl $context) { $this->context = $context; - return $this; } @@ -143,9 +134,8 @@ public function setContext(Wsdl $context) * Create a complex type based on a strategy * * @param string $type - * @throws Exception\InvalidArgumentException - * * @return string XSD type + * @throws Exception\InvalidArgumentException */ public function addComplexType($type) { diff --git a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php index af8186e6..779cd2bf 100644 --- a/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php +++ b/src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php @@ -13,19 +13,14 @@ use Zend\Soap\Exception; use Zend\Soap\Wsdl; -/** - * Zend_Soap_Wsdl_Strategy_DefaultComplexType - * - */ class DefaultComplexType extends AbstractComplexTypeStrategy { /** * Add a complex type by recursively using all the class properties fetched via Reflection. * * @param string $type Name of the class to be specified - * @throws Exception\InvalidArgumentException if class does not exist - * * @return string XSD Type for the given PHP type + * @throws Exception\InvalidArgumentException if class does not exist */ public function addComplexType($type) { From 57b865c8380f192ef92496888dd61b6cd9212207 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 30 Apr 2013 11:42:26 -0500 Subject: [PATCH 20/22] [zendframework/zf2#3919] Use instanceof - instead of is_object() && is_subclass_of() --- src/Server.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Server.php b/src/Server.php index cf70071e..9b8c05ee 100644 --- a/src/Server.php +++ b/src/Server.php @@ -872,7 +872,7 @@ public function handle($request = null) $fault = false; $this->response = ''; - if (is_object($setRequestException) && is_subclass_of($setRequestException, 'Exception')) { + if ($setRequestException instanceof \Exception) { // Create SOAP fault message if we've caught a request exception $fault = $this->fault($setRequestException->getMessage(), 'Sender'); } else { @@ -1009,7 +1009,7 @@ public function getFaultExceptions() */ public function fault($fault = null, $code = 'Receiver') { - if (is_object($fault) && is_subclass_of($fault, 'Exception')) { + if ($fault instanceof \Exception) { if ($this->isRegisteredAsFaultException($fault)) { $message = $fault->getMessage(); $eCode = $fault->getCode(); From 951b6e5aaf217cba0bc31f2ebb5682bc48bf5be9 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 30 Apr 2013 11:43:57 -0500 Subject: [PATCH 21/22] [zendframework/zf2#3919] Replace private with protected visibility --- src/Client/DotNet.php | 12 ++++++------ src/Wsdl.php | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Client/DotNet.php b/src/Client/DotNet.php index 7c47245f..b65e167b 100644 --- a/src/Client/DotNet.php +++ b/src/Client/DotNet.php @@ -27,31 +27,31 @@ class DotNet extends SOAPClient * Curl HTTP client adapter. * @var CurlClient */ - private $curlClient = null; + protected $curlClient = null; /** * The last request headers. * @var string */ - private $lastRequestHeaders = ''; + protected $lastRequestHeaders = ''; /** * The last response headers. * @var string */ - private $lastResponseHeaders = ''; + protected $lastResponseHeaders = ''; /** * SOAP client options. * @var array */ - private $options = array(); + protected $options = array(); /** * Should NTLM authentication be used? * @var boolean */ - private $useNtlm = false; + protected $useNtlm = false; /** * Constructor @@ -225,7 +225,7 @@ protected function _preProcessResult($result) * @param array $headers The headers to flatten. * @return string The headers string. */ - private function flattenHeaders(array $headers) + protected function flattenHeaders(array $headers) { $result = ''; diff --git a/src/Wsdl.php b/src/Wsdl.php index 37180748..12f8d468 100644 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -48,18 +48,18 @@ class Wsdl * DOM Instance * @var DOMDocument */ - private $dom; + protected $dom; /** * Types defined on schema * @var array */ - private $includedTypes = array(); + protected $includedTypes = array(); /** * @var DOMElement */ - private $schema = null; + protected $schema = null; /** * Strategy for detection of complex types @@ -70,13 +70,13 @@ class Wsdl * URI where the WSDL will be available * @var string */ - private $uri; + protected $uri; /** * Root XML_Tree_Node * @var DOMElement WSDL */ - private $wsdl; + protected $wsdl; /** * @param string $name Name of the Web Service being Described @@ -752,7 +752,7 @@ public function addComplexType($type) * @return DOMElement parsed element * @throws Exception\RuntimeException if $element is not an array */ - private function _parseElement($element) + protected function _parseElement($element) { if (!is_array($element)) { throw new Exception\RuntimeException('The "element" parameter needs to be an associative array.'); @@ -788,7 +788,7 @@ private function _parseElement($element) * @param mixed $value * @return string safe value or original $value */ - private function sanitizeAttributeValueByName($name, $value) + protected function sanitizeAttributeValueByName($name, $value) { switch (strtolower($name)) { case 'targetnamespace': @@ -811,7 +811,7 @@ private function sanitizeAttributeValueByName($name, $value) * @param array $attributes * @param bool $withSanitizer */ - private function arrayToAttributes(\DOMNode $node, array $attributes, $withSanitizer = true) + protected function arrayToAttributes(\DOMNode $node, array $attributes, $withSanitizer = true) { foreach($attributes as $attributeName => $attributeValue) { if ($withSanitizer) { @@ -829,7 +829,7 @@ private function arrayToAttributes(\DOMNode $node, array $attributes, $withSanit * @param string $attributeName * @param mixed $attributeValue */ - private function setAttributeWithSanitization(\DOMNode $node, $attributeName, $attributeValue) + protected function setAttributeWithSanitization(\DOMNode $node, $attributeName, $attributeValue) { $attributeValue = $this->sanitizeAttributeValueByName($attributeName, $attributeValue); $this->setAttribute($node, $attributeName, $attributeValue); @@ -842,7 +842,7 @@ private function setAttributeWithSanitization(\DOMNode $node, $attributeName, $a * @param string $attributeName * @param mixed $attributeValue */ - private function setAttribute(\DOMNode $node, $attributeName, $attributeValue) + protected function setAttribute(\DOMNode $node, $attributeName, $attributeValue) { $attributeNode = $node->ownerDocument->createAttribute($attributeName); $node->appendChild($attributeNode); @@ -858,7 +858,7 @@ private function setAttribute(\DOMNode $node, $attributeName, $attributeValue) * @return string * @throws Exception\InvalidArgumentException */ - private function getSoapNamespaceUriByVersion($soapVersion) + protected function getSoapNamespaceUriByVersion($soapVersion) { if ($soapVersion != SOAP_1_1 AND $soapVersion != SOAP_1_2) { throw new Exception\InvalidArgumentException('Invalid SOAP version, use constants: SOAP_1_1 or SOAP_1_2'); From 427505acb362971fca2e2d22018cad7440a83cf9 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 30 Apr 2013 11:45:09 -0500 Subject: [PATCH 22/22] [zendframework/zf2#3919] CS fixes - per php-cs-fixer --- .../DiscoveryStrategyInterface.php | 2 +- src/Server.php | 2 +- src/Wsdl.php | 2 +- .../ArrayOfTypeSequence.php | 2 +- test/TestAsset/commontypes.php | 4 +- test/Wsdl/ArrayOfTypeSequenceStrategyTest.php | 6 +- test/Wsdl/CompositeStrategyTest.php | 7 +- test/Wsdl/DefaultComplexTypeTest.php | 1 - test/WsdlTest.php | 39 +-- test/WsdlTestHelper.php | 242 +++++++++--------- test/schemas/wsdl.xsd | 80 +++--- 11 files changed, 195 insertions(+), 192 deletions(-) diff --git a/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php b/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php index 5ac8a6e8..22f33dbf 100644 --- a/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php +++ b/src/AutoDiscover/DiscoveryStrategy/DiscoveryStrategyInterface.php @@ -14,7 +14,7 @@ use Zend\Server\Reflection\ReflectionParameter; /** - * Describes how types, return values and method details are detected during + * Describes how types, return values and method details are detected during * AutoDiscovery of a WSDL. */ interface DiscoveryStrategyInterface diff --git a/src/Server.php b/src/Server.php index 9b8c05ee..5d276a26 100644 --- a/src/Server.php +++ b/src/Server.php @@ -566,7 +566,7 @@ public function addFunction($function, $namespace = '') * * See {@link setObject()} to set pre-configured object instances as request handlers. * - * @param string|object $class Class name or object instance which executes + * @param string|object $class Class name or object instance which executes * SOAP Requests at endpoint. * @param string $namespace * @param null|array $argv diff --git a/src/Wsdl.php b/src/Wsdl.php index 12f8d468..cab0c17b 100644 --- a/src/Wsdl.php +++ b/src/Wsdl.php @@ -206,7 +206,7 @@ public function setUri($uri) $xpath->registerNamespace(self::SOAP_ENC_NS, self::SOAP_ENC_URI); $xpath->registerNamespace(self::WSDL_NS, self::WSDL_NS_URI); - // Select only attribute nodes. Data nodes does not contain uri + // Select only attribute nodes. Data nodes does not contain uri // except for documentation node but this is for the user to decide. // This list does not include xmlns:tsn attribute of document root. // That attribute is changed above. diff --git a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php index 13255d9d..0c223bda 100644 --- a/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php +++ b/src/Wsdl/ComplexTypeStrategy/ArrayOfTypeSequence.php @@ -38,7 +38,7 @@ public function addComplexType($type) return $complexType; } - + if (($soapType = $this->scanRegisteredTypes($type)) !== null) { // Existing complex type return $soapType; diff --git a/test/TestAsset/commontypes.php b/test/TestAsset/commontypes.php index f18adc90..1e96fbb2 100644 --- a/test/TestAsset/commontypes.php +++ b/test/TestAsset/commontypes.php @@ -686,8 +686,8 @@ class PublicPrivateProtected private $baz; } -class errorClass { - +class errorClass +{ public function triggerError() { trigger_error('TestError', E_USER_ERROR); diff --git a/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php index c5f052d2..3a45834c 100644 --- a/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php +++ b/test/Wsdl/ArrayOfTypeSequenceStrategyTest.php @@ -64,7 +64,8 @@ public function testFunctionReturningSimpleArrayOfBasicTypes($type, $arrayTypeNa $this->testDocumentNodes(); } - public function dataProviderForFunctionReturningSimpleArrayOfBasicTypes(){ + public function dataProviderForFunctionReturningSimpleArrayOfBasicTypes() + { return array( array('int', 'ArrayOfInt'), array('string', 'ArrayOfString'), @@ -113,7 +114,8 @@ public function testNestedTypesDefinitions($stringDefinition, $definedTypeName, /** * @return array */ - public function dataProviderForNestedTypesDefinitions() { + public function dataProviderForNestedTypesDefinitions() + { return array( array( 'string[][]', diff --git a/test/Wsdl/CompositeStrategyTest.php b/test/Wsdl/CompositeStrategyTest.php index d70260e1..f239d080 100644 --- a/test/Wsdl/CompositeStrategyTest.php +++ b/test/Wsdl/CompositeStrategyTest.php @@ -36,7 +36,8 @@ class CompositeStrategyTest extends WsdlTestHelper { - public function setUp() { + public function setUp() + { // override parent setup because it is needed only in one method } @@ -129,7 +130,8 @@ public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrows /** * */ - public function testGetDefaultStrategy() { + public function testGetDefaultStrategy() + { $strategyClass = 'Zend\Soap\Wsdl\ComplexTypeStrategy\AnyType'; $strategy = new Composite(array(), $strategyClass); @@ -137,4 +139,3 @@ public function testGetDefaultStrategy() { $this->assertEquals($strategyClass, get_class($strategy->getDefaultStrategy())); } } - diff --git a/test/Wsdl/DefaultComplexTypeTest.php b/test/Wsdl/DefaultComplexTypeTest.php index a420aa52..1914ba14 100644 --- a/test/Wsdl/DefaultComplexTypeTest.php +++ b/test/Wsdl/DefaultComplexTypeTest.php @@ -54,4 +54,3 @@ public function testOnlyPublicPropertiesAreDiscoveredByStrategy() $this->testDocumentNodes(); } } - diff --git a/test/WsdlTest.php b/test/WsdlTest.php index 5f1df995..d50e0d3e 100644 --- a/test/WsdlTest.php +++ b/test/WsdlTest.php @@ -25,7 +25,7 @@ class WsdlTest extends WsdlTestHelper { - function testConstructor() + public function testConstructor() { $this->assertEquals(Wsdl::WSDL_NS_URI, $this->dom->lookupNamespaceUri(null)); $this->assertEquals(Wsdl::SOAP_11_NS_URI, $this->dom->lookupNamespaceUri('soap')); @@ -123,7 +123,7 @@ public function dataProviderForURITesting() * * @param array $parameters message parameters */ - function testAddMessage($parameters) + public function testAddMessage($parameters) { $messageParts = array(); foreach($parameters as $i => $parameter) { @@ -194,7 +194,7 @@ public function dataProviderForAddMessage() ); } - function testAddPortType() + public function testAddPortType() { $portName = 'myPortType'; $this->wsdl->addPortType($portName); @@ -214,7 +214,7 @@ function testAddPortType() * * @param string $operationName */ - function testAddPortOperation($operationName, $inputRequest = null, $outputResponse = null, $fail = null) + public function testAddPortOperation($operationName, $inputRequest = null, $outputResponse = null, $fail = null) { $portName = 'myPortType'; $portType = $this->wsdl->addPortType($portName); @@ -254,7 +254,7 @@ function testAddPortOperation($operationName, $inputRequest = null, $outputRespo /** * */ - function dataProviderForAddPortOperation() + public function dataProviderForAddPortOperation() { return array( array('operation'), @@ -267,7 +267,7 @@ function dataProviderForAddPortOperation() ); } - function testAddBinding() + public function testAddBinding() { $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); @@ -296,7 +296,7 @@ function testAddBinding() * @param null $faultEncoding * @param null $faultName */ - function testAddBindingOperation($operationName, + public function testAddBindingOperation($operationName, $input = null, $inputEncoding = null, $output = null, $outputEncoding = null, $fault = null, $faultEncoding = null, $faultName = null) @@ -383,7 +383,7 @@ public function dataProviderForAddBindingOperation() /** * @dataProvider dataProviderForSoapBindingStyle */ - function testAddSoapBinding($style) + public function testAddSoapBinding($style) { $this->wsdl->addPortType('myPortType'); $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); @@ -409,7 +409,7 @@ public function dataProviderForSoapBindingStyle() /** * @dataProvider dataProviderForAddSoapOperation */ - function testAddSoapOperation($operationUrl) + public function testAddSoapOperation($operationUrl) { $this->wsdl->addPortType('myPortType'); $binding = $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); @@ -434,7 +434,7 @@ public function dataProviderForAddSoapOperation() /** * @dataProvider dataProviderForAddService */ - function testAddService($serviceUrl) + public function testAddService($serviceUrl) { $this->wsdl->addPortType('myPortType'); $this->wsdl->addBinding('MyServiceBinding', 'myPortType'); @@ -539,7 +539,7 @@ public function ampersandInUrlDataProvider() /** * */ - function testAddDocumentation() + public function testAddDocumentation() { $doc = 'This is a description for Port Type node.'; $this->wsdl->addDocumentation($this->wsdl, $doc); @@ -552,7 +552,7 @@ function testAddDocumentation() } - function testAddDocumentationToSomeElmenet() + public function testAddDocumentationToSomeElmenet() { $portType = $this->wsdl->addPortType('myPortType'); @@ -644,13 +644,13 @@ public function testGetType() $this->assertEquals('', $this->wsdl->getType('void'), 'void detection failed.'); } - function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() + public function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean() { $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof Wsdl\ComplexTypeStrategy\DefaultComplexType); } - function testGetComplexTypeBasedOnStrategiesStringNames() + public function testGetComplexTypeBasedOnStrategiesStringNames() { $this->wsdl = new Wsdl($this->defaultServiceName, 'http://localhost/MyService.php', new Wsdl\ComplexTypeStrategy\DefaultComplexType); $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\ZendTest\Soap\TestAsset\WsdlTestClass')); @@ -661,7 +661,7 @@ function testGetComplexTypeBasedOnStrategiesStringNames() $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof Wsdl\ComplexTypeStrategy\AnyType); } - function testAddingSameComplexTypeMoreThanOnceIsIgnored() + public function testAddingSameComplexTypeMoreThanOnceIsIgnored() { $this->wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:SomeTypeName'); $this->wsdl->addType('\ZendTest\Soap\TestAsset\WsdlTestClass', 'tns:AnotherTypeName'); @@ -677,7 +677,7 @@ function testAddingSameComplexTypeMoreThanOnceIsIgnored() $this->testDocumentNodes(); } - function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition() + public function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition() { $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); $this->assertEquals( @@ -705,7 +705,7 @@ public function testGetSchema() $this->assertEquals($this->defaultServiceUri, $schema->getAttribute('targetNamespace')); } - function testAddComplexType() + public function testAddComplexType() { $this->wsdl->addComplexType('\ZendTest\Soap\TestAsset\WsdlTestClass'); @@ -762,7 +762,8 @@ public function testTranslateType($type, $expected) /** * @return array */ - public function dataProviderForTranslateType() { + public function dataProviderForTranslateType() + { return array( array('\\SomeType','SomeType'), array('SomeType\\','SomeType'), @@ -778,7 +779,7 @@ public function dataProviderForTranslateType() { * @group ZF-3910 * @group ZF-11937 */ - function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() + public function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910() { $this->assertEquals("xsd:string", $this->wsdl->getType("StrIng")); $this->assertEquals("xsd:string", $this->wsdl->getType("sTr")); diff --git a/test/WsdlTestHelper.php b/test/WsdlTestHelper.php index 6c2a8491..409b7690 100644 --- a/test/WsdlTestHelper.php +++ b/test/WsdlTestHelper.php @@ -1,121 +1,121 @@ -strategy) OR !($this->strategy instanceof ComplexTypeStrategyInterface)) { - $this->strategy = new Wsdl\ComplexTypeStrategy\DefaultComplexType(); - } - - $this->wsdl = new Wsdl($this->defaultServiceName, $this->defaultServiceUri, $this->strategy); - - if ($this->strategy instanceof ComplexTypeStrategyInterface) { - $this->strategy->setContext($this->wsdl); - } - - $this->dom = $this->wsdl->toDomDocument(); - $this->dom = $this->registerNamespaces($this->dom); - } - - /** - * @param \DOMDocument $obj - * @param string $documentNamespace - * @return \DOMDocument - */ - public function registerNamespaces($obj, $documentNamespace = null) - { - - if (empty($documentNamespace)) { - $documentNamespace = $this->defaultServiceUri; - } - - $this->xpath = new \DOMXPath($obj); - $this->xpath->registerNamespace('unittest', Wsdl::WSDL_NS_URI); - - $this->xpath->registerNamespace('tns', $documentNamespace); - $this->xpath->registerNamespace('soap', Wsdl::SOAP_11_NS_URI); - $this->xpath->registerNamespace('soap12', Wsdl::SOAP_12_NS_URI); - $this->xpath->registerNamespace('xsd', Wsdl::XSD_NS_URI); - $this->xpath->registerNamespace('soap-enc', Wsdl::SOAP_ENC_URI); - $this->xpath->registerNamespace('wsdl', Wsdl::WSDL_NS_URI); - - return $obj; - } - - /** - * @param \DOMElement $element - */ - public function testDocumentNodes($element = null) - { - if (!($this->wsdl instanceof Wsdl)) { - return; - } - - if (is_null($element)) { - $element = $this->wsdl->toDomDocument()->documentElement; - } - - /** @var $node \DOMElement */ - foreach ($element->childNodes as $node) { - if (in_array($node->nodeType, array(XML_ELEMENT_NODE))) { - $this->assertNotEmpty($node->namespaceURI, 'Document element: ' . $node->nodeName . ' has no valid namespace. Line: ' . $node->getLineNo()); - $this->testDocumentNodes($node); - } - } - } -} +strategy) OR !($this->strategy instanceof ComplexTypeStrategyInterface)) { + $this->strategy = new Wsdl\ComplexTypeStrategy\DefaultComplexType(); + } + + $this->wsdl = new Wsdl($this->defaultServiceName, $this->defaultServiceUri, $this->strategy); + + if ($this->strategy instanceof ComplexTypeStrategyInterface) { + $this->strategy->setContext($this->wsdl); + } + + $this->dom = $this->wsdl->toDomDocument(); + $this->dom = $this->registerNamespaces($this->dom); + } + + /** + * @param \DOMDocument $obj + * @param string $documentNamespace + * @return \DOMDocument + */ + public function registerNamespaces($obj, $documentNamespace = null) + { + + if (empty($documentNamespace)) { + $documentNamespace = $this->defaultServiceUri; + } + + $this->xpath = new \DOMXPath($obj); + $this->xpath->registerNamespace('unittest', Wsdl::WSDL_NS_URI); + + $this->xpath->registerNamespace('tns', $documentNamespace); + $this->xpath->registerNamespace('soap', Wsdl::SOAP_11_NS_URI); + $this->xpath->registerNamespace('soap12', Wsdl::SOAP_12_NS_URI); + $this->xpath->registerNamespace('xsd', Wsdl::XSD_NS_URI); + $this->xpath->registerNamespace('soap-enc', Wsdl::SOAP_ENC_URI); + $this->xpath->registerNamespace('wsdl', Wsdl::WSDL_NS_URI); + + return $obj; + } + + /** + * @param \DOMElement $element + */ + public function testDocumentNodes($element = null) + { + if (!($this->wsdl instanceof Wsdl)) { + return; + } + + if (is_null($element)) { + $element = $this->wsdl->toDomDocument()->documentElement; + } + + /** @var $node \DOMElement */ + foreach ($element->childNodes as $node) { + if (in_array($node->nodeType, array(XML_ELEMENT_NODE))) { + $this->assertNotEmpty($node->namespaceURI, 'Document element: ' . $node->nodeName . ' has no valid namespace. Line: ' . $node->getLineNo()); + $this->testDocumentNodes($node); + } + } + } +} diff --git a/test/schemas/wsdl.xsd b/test/schemas/wsdl.xsd index da851ce0..4832b6f5 100644 --- a/test/schemas/wsdl.xsd +++ b/test/schemas/wsdl.xsd @@ -1,39 +1,39 @@ - - +--> - + @@ -61,7 +61,7 @@ No other rights are granted by implication, estoppel or otherwise. This type is extended by component types to allow attributes from other namespaces to be added. - + @@ -118,7 +118,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -149,7 +149,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -159,15 +159,15 @@ No other rights are granted by implication, estoppel or otherwise. - + - + - + - + - + @@ -175,22 +175,22 @@ No other rights are granted by implication, estoppel or otherwise. - + - + - + - + - + @@ -198,11 +198,11 @@ No other rights are granted by implication, estoppel or otherwise. - + - + - + @@ -214,10 +214,10 @@ No other rights are granted by implication, estoppel or otherwise. - + - + @@ -238,7 +238,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -257,7 +257,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -270,7 +270,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -279,7 +279,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -302,7 +302,7 @@ No other rights are granted by implication, estoppel or otherwise. - + @@ -314,7 +314,7 @@ No other rights are granted by implication, estoppel or otherwise. - +