CompositeStrategyTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Soap
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @package Zend_Soap
  23. * @subpackage UnitTests
  24. */
  25. /** Zend_Soap_Wsdl */
  26. require_once 'Zend/Soap/Wsdl.php';
  27. require_once 'Zend/Soap/Wsdl/Strategy/AnyType.php';
  28. require_once 'Zend/Soap/Wsdl/Strategy/ArrayOfTypeSequence.php';
  29. require_once 'Zend/Soap/Wsdl/Strategy/ArrayOfTypeComplex.php';
  30. require_once 'Zend/Soap/Wsdl/Strategy/DefaultComplexType.php';
  31. require_once 'Zend/Soap/Wsdl/Strategy/DefaultComplexType.php';
  32. require_once 'Zend/Soap/Wsdl/Strategy/Composite.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Soap
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. * @group Zend_Soap
  40. * @group Zend_Soap_Wsdl
  41. */
  42. class Zend_Soap_Wsdl_CompositeStrategyTest extends PHPUnit_Framework_TestCase
  43. {
  44. public function testCompositeApiAddingStragiesToTypes()
  45. {
  46. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence");
  47. $strategy->connectTypeToStrategy("Book", "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  48. $bookStrategy = $strategy->getStrategyOfType("Book");
  49. $cookieStrategy = $strategy->getStrategyOfType("Cookie");
  50. $this->assertTrue( $bookStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex );
  51. $this->assertTrue( $cookieStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence );
  52. }
  53. public function testConstructorTypeMapSyntax()
  54. {
  55. $typeMap = array("Book" => "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  56. $strategy = new Zend_Soap_Wsdl_Strategy_Composite($typeMap, "Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence");
  57. $bookStrategy = $strategy->getStrategyOfType("Book");
  58. $cookieStrategy = $strategy->getStrategyOfType("Cookie");
  59. $this->assertTrue( $bookStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex );
  60. $this->assertTrue( $cookieStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence );
  61. }
  62. public function testCompositeThrowsExceptionOnInvalidType()
  63. {
  64. $strategy = new Zend_Soap_Wsdl_Strategy_Composite();
  65. try {
  66. $strategy->connectTypeToStrategy(array(), "strategy");
  67. $this->fail();
  68. } catch(Exception $e) {
  69. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  70. }
  71. }
  72. public function testCompositeThrowsExceptionOnInvalidStrategy()
  73. {
  74. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "invalid");
  75. $strategy->connectTypeToStrategy("Book", "strategy");
  76. try {
  77. $book = $strategy->getStrategyOfType("Book");
  78. $this->fail();
  79. } catch(Exception $e) {
  80. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  81. }
  82. try {
  83. $book = $strategy->getStrategyOfType("Anything");
  84. $this->fail();
  85. } catch(Exception $e) {
  86. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  87. }
  88. }
  89. public function testCompositeDelegatesAddingComplexTypesToSubStrategies()
  90. {
  91. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "Zend_Soap_Wsdl_Strategy_AnyType");
  92. $strategy->connectTypeToStrategy("Zend_Soap_Wsdl_Book", "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  93. $strategy->connectTypeToStrategy("Zend_Soap_Wsdl_Cookie", "Zend_Soap_Wsdl_Strategy_DefaultComplexType");
  94. $wsdl = new Zend_Soap_Wsdl("SomeService", "http://example.com");
  95. $strategy->setContext($wsdl);
  96. $this->assertEquals("tns:Zend_Soap_Wsdl_Book", $strategy->addComplexType("Zend_Soap_Wsdl_Book"));
  97. $this->assertEquals("tns:Zend_Soap_Wsdl_Cookie", $strategy->addComplexType("Zend_Soap_Wsdl_Cookie"));
  98. $this->assertEquals("xsd:anyType", $strategy->addComplexType("Zend_Soap_Wsdl_Anything"));
  99. }
  100. public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrowsException()
  101. {
  102. $strategy = new Zend_Soap_Wsdl_Strategy_Composite();
  103. try {
  104. $strategy->addComplexType("Test");
  105. $this->fail();
  106. } catch(Exception $e) {
  107. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  108. }
  109. }
  110. }
  111. class Zend_Soap_Wsdl_Book
  112. {
  113. /**
  114. * @var int
  115. */
  116. public $somevar;
  117. }
  118. class Zend_Soap_Wsdl_Cookie
  119. {
  120. /**
  121. * @var int
  122. */
  123. public $othervar;
  124. }
  125. class Zend_Soap_Wsdl_Anything
  126. {
  127. }