示例#1
0
 /**
  * Test output WSDL with complex type added.
  */
 public function test_add_complex_type()
 {
     $this->resetAfterTest();
     $classname = 'testcomplextype';
     $classattrs = array('doubleparam' => array('type' => 'double', 'nillable' => true), 'stringparam' => array('type' => 'string', 'nillable' => true), 'intparam' => array('type' => 'int', 'nillable' => true), 'boolparam' => array('type' => 'int', 'nillable' => true), 'classparam' => array('type' => 'teststruct'), 'arrayparam' => array('type' => 'array', 'nillable' => true));
     $serviceclass = 'testserviceclass';
     $namespace = 'testnamespace';
     $wsdl = new wsdl($serviceclass, $namespace);
     $wsdl->add_complex_type($classname, $classattrs);
     $definitions = new \SimpleXMLElement($wsdl->to_xml());
     // Test types node and attributes.
     $this->assertNotNull($definitions->types);
     $this->assertEquals($namespace, $definitions->types->children('xsd', true)->schema->attributes()->targetNamespace);
     $complextype = $definitions->types->children('xsd', true)->schema->children('xsd', true);
     $this->assertNotEmpty($complextype);
     // Test the complex type's attributes.
     foreach ($complextype->children('xsd', true)->all->children('xsd', true) as $element) {
         foreach ($classattrs as $name => $options) {
             if (strcmp($name, $element->attributes()->name) != 0) {
                 continue;
             }
             switch ($options['type']) {
                 case 'double':
                 case 'int':
                 case 'string':
                     $this->assertEquals('xsd:' . $options['type'], $element->attributes()->type);
                     break;
                 case 'array':
                     $this->assertEquals('soap-enc:' . ucfirst($options['type']), $element->attributes()->type);
                     break;
                 default:
                     $this->assertEquals('tns:' . $options['type'], $element->attributes()->type);
                     break;
             }
             if (!empty($options['nillable'])) {
                 $this->assertEquals('true', $element->attributes()->nillable);
             }
             break;
         }
     }
 }