ParserTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. require_once dirname(__FILE__)."/../../../TestHelper.php";
  3. require_once "Zend/Soap/Wsdl.php";
  4. require_once "Zend/Soap/Wsdl/Parser.php";
  5. require_once "Zend/Soap/Wsdl/Parser/Result.php";
  6. class Zend_Soap_Wsdl_ParserTest extends PHPUnit_Framework_TestCase
  7. {
  8. protected function getWsdlExampleDom()
  9. {
  10. $dom = new DOMDocument();
  11. $dom->loadXml(file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl"));
  12. return $dom;
  13. }
  14. public function testFactoryWithDomDocument()
  15. {
  16. $dom = $this->getWsdlExampleDom();
  17. $parser = Zend_Soap_Wsdl_Parser::factory($dom);
  18. $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
  19. }
  20. public function testFactoryWithString()
  21. {
  22. $xmlString = file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl");
  23. $parser = Zend_Soap_Wsdl_Parser::factory($xmlString);
  24. $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
  25. }
  26. public function testFactoryWithSimpleXml()
  27. {
  28. $xmlString = file_get_contents(dirname(__FILE__)."/../_files/wsdl_example.wsdl");
  29. $simpleXml = simplexml_load_string($xmlString);
  30. $parser = Zend_Soap_Wsdl_Parser::factory($simpleXml);
  31. $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
  32. }
  33. public function testFactoryWithZendSoapWsdl()
  34. {
  35. $wsdl = new Zend_Soap_Wsdl("name", "http://example.com");
  36. $parser = Zend_Soap_Wsdl_Parser::factory($wsdl);
  37. $this->assertTrue($parser instanceof Zend_Soap_Wsdl_Parser);
  38. }
  39. public function testFactoryWithInvalidParser()
  40. {
  41. $wsdl = new Zend_Soap_Wsdl("name", "http://example.com");
  42. try {
  43. $parser = Zend_Soap_Wsdl_Parser::factory($wsdl, "stdClass");
  44. $this->fail();
  45. } catch(Exception $e) {
  46. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Parser_Exception);
  47. }
  48. }
  49. public function testFactoryWithInvalidData()
  50. {
  51. try {
  52. $parser = Zend_Soap_Wsdl_Parser::factory(null);
  53. $this->fail();
  54. } catch(Zend_Soap_Wsdl_Exception $e) {
  55. }
  56. }
  57. public function testParserApiInterface()
  58. {
  59. // Constructor expects DOMDocument instance
  60. $dom = $this->getWsdlExampleDom();
  61. $parser = new Zend_Soap_Wsdl_Parser($dom);
  62. // SetWsdl is a fluent function
  63. $this->assertTrue( ($parser->setDomDocumentContainingWsdl($dom)) instanceof Zend_Soap_Wsdl_Parser );
  64. // Parse returns Result
  65. $result = $parser->parse();
  66. $this->assertTrue($result instanceof Zend_Soap_Wsdl_Parser_Result);
  67. }
  68. public function testParserResultApiInterface()
  69. {
  70. $result = new Zend_Soap_Wsdl_Parser_Result(
  71. "name",
  72. Zend_Soap_Wsdl_Parser::WSDL_11,
  73. new Zend_Soap_Wsdl_Element_Collection("Operation"),
  74. new Zend_Soap_Wsdl_Element_Collection("Port"),
  75. new Zend_Soap_Wsdl_Element_Collection("Binding"),
  76. new Zend_Soap_Wsdl_Element_Collection("Service"),
  77. new Zend_Soap_Wsdl_Element_Collection("Type"),
  78. array("docs")
  79. );
  80. $this->assertEquals("name", $result->getName());
  81. $this->assertEquals("Zend_Soap_Wsdl_Element_Operation", $result->operations->getType());
  82. $this->assertEquals("Zend_Soap_Wsdl_Element_Port", $result->ports->getType());
  83. $this->assertEquals("Zend_Soap_Wsdl_Element_Binding", $result->bindings->getType());
  84. $this->assertEquals("Zend_Soap_Wsdl_Element_Service", $result->services->getType());
  85. $this->assertEquals("Zend_Soap_Wsdl_Element_Type", $result->types->getType());
  86. $this->assertEquals(array("docs"), $result->documentation);
  87. try {
  88. $key = $result->invalidKeyThrowsException;
  89. $this->fail();
  90. } catch(Exception $e) {
  91. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Parser_Exception);
  92. }
  93. }
  94. public function testParseExampleWsdlAndCountResultElements()
  95. {
  96. // Constructor expects DOMDocument instance
  97. $dom = $this->getWsdlExampleDom();
  98. $parser = new Zend_Soap_Wsdl_Parser($dom);
  99. $result = $parser->parse();
  100. $this->assertEquals("Zend_Soap_Server_TestClass", $result->getName());
  101. $this->assertEquals(Zend_Soap_Wsdl_Parser::WSDL_11, $result->getVersion());
  102. $this->assertEquals(4, count($result->operations), "Number of operations does not match.");
  103. $this->assertEquals(1, count($result->bindings), "Number of bindings does not match.");
  104. $this->assertEquals(1, count($result->ports), "Number of ports does not match.");
  105. $this->assertEquals(1, count($result->services), "Number of services does not match.");
  106. $this->assertEquals(0, count($result->types), "Number of types does not match.");
  107. $this->assertEquals(4, count($result->bindings->current()->operations), "Number of operations in the bindings collection does not match.");
  108. $this->assertEquals(4, count($result->ports->current()->operations), "Number of operations in the ports collection does not match.");
  109. }
  110. public function testParseExampleWsdlAndCheckMatchingNames()
  111. {
  112. // Constructor expects DOMDocument instance
  113. $dom = $this->getWsdlExampleDom();
  114. $parser = new Zend_Soap_Wsdl_Parser($dom);
  115. $result = $parser->parse();
  116. foreach($result->operations AS $operation) {
  117. $this->assertContains($operation->getName(), array("testFunc1", "testFunc2", "testFunc3", "testFunc4"));
  118. }
  119. foreach($result->bindings AS $binding) {
  120. $this->assertEquals("Zend_Soap_Server_TestClassBinding", $binding->getName());
  121. }
  122. foreach($result->ports AS $port) {
  123. $this->assertEquals("Zend_Soap_Server_TestClassPort", $port->getName());
  124. }
  125. foreach($result->services AS $service) {
  126. $this->assertEquals("Zend_Soap_Server_TestClassService", $service->getName());
  127. }
  128. }
  129. public function testParseExampleWsdlWithDocumentationBlocks()
  130. {
  131. $dom = new DOMDocument();
  132. $dom->loadXml(file_get_contents(dirname(__FILE__)."/../_files/wsdl_documentation.wsdl"));
  133. $parser = new Zend_Soap_Wsdl_Parser($dom);
  134. $result = $parser->parse();
  135. }
  136. }