CompositeStrategyTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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-2010 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. require_once dirname(__FILE__)."/../../../TestHelper.php";
  26. /** Zend_Soap_Wsdl */
  27. require_once 'Zend/Soap/Wsdl.php';
  28. require_once 'Zend/Soap/Wsdl/Strategy/AnyType.php';
  29. require_once 'Zend/Soap/Wsdl/Strategy/ArrayOfTypeSequence.php';
  30. require_once 'Zend/Soap/Wsdl/Strategy/ArrayOfTypeComplex.php';
  31. require_once 'Zend/Soap/Wsdl/Strategy/DefaultComplexType.php';
  32. require_once 'Zend/Soap/Wsdl/Strategy/DefaultComplexType.php';
  33. require_once 'Zend/Soap/Wsdl/Strategy/Composite.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Soap
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Soap
  41. * @group Zend_Soap_Wsdl
  42. */
  43. class Zend_Soap_Wsdl_CompositeStrategyTest extends PHPUnit_Framework_TestCase
  44. {
  45. public function testCompositeApiAddingStragiesToTypes()
  46. {
  47. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence");
  48. $strategy->connectTypeToStrategy("Book", "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  49. $bookStrategy = $strategy->getStrategyOfType("Book");
  50. $cookieStrategy = $strategy->getStrategyOfType("Cookie");
  51. $this->assertTrue( $bookStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex );
  52. $this->assertTrue( $cookieStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence );
  53. }
  54. public function testConstructorTypeMapSyntax()
  55. {
  56. $typeMap = array("Book" => "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  57. $strategy = new Zend_Soap_Wsdl_Strategy_Composite($typeMap, "Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence");
  58. $bookStrategy = $strategy->getStrategyOfType("Book");
  59. $cookieStrategy = $strategy->getStrategyOfType("Cookie");
  60. $this->assertTrue( $bookStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex );
  61. $this->assertTrue( $cookieStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence );
  62. }
  63. public function testCompositeThrowsExceptionOnInvalidType()
  64. {
  65. $strategy = new Zend_Soap_Wsdl_Strategy_Composite();
  66. try {
  67. $strategy->connectTypeToStrategy(array(), "strategy");
  68. $this->fail();
  69. } catch(Exception $e) {
  70. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  71. }
  72. }
  73. public function testCompositeThrowsExceptionOnInvalidStrategy()
  74. {
  75. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "invalid");
  76. $strategy->connectTypeToStrategy("Book", "strategy");
  77. try {
  78. $book = $strategy->getStrategyOfType("Book");
  79. $this->fail();
  80. } catch(Exception $e) {
  81. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  82. }
  83. try {
  84. $book = $strategy->getStrategyOfType("Anything");
  85. $this->fail();
  86. } catch(Exception $e) {
  87. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  88. }
  89. }
  90. public function testCompositeDelegatesAddingComplexTypesToSubStrategies()
  91. {
  92. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "Zend_Soap_Wsdl_Strategy_AnyType");
  93. $strategy->connectTypeToStrategy("Zend_Soap_Wsdl_Book", "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  94. $strategy->connectTypeToStrategy("Zend_Soap_Wsdl_Cookie", "Zend_Soap_Wsdl_Strategy_DefaultComplexType");
  95. $wsdl = new Zend_Soap_Wsdl("SomeService", "http://example.com");
  96. $strategy->setContext($wsdl);
  97. $this->assertEquals("tns:Zend_Soap_Wsdl_Book", $strategy->addComplexType("Zend_Soap_Wsdl_Book"));
  98. $this->assertEquals("tns:Zend_Soap_Wsdl_Cookie", $strategy->addComplexType("Zend_Soap_Wsdl_Cookie"));
  99. $this->assertEquals("xsd:anyType", $strategy->addComplexType("Zend_Soap_Wsdl_Anything"));
  100. }
  101. public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrowsException()
  102. {
  103. $strategy = new Zend_Soap_Wsdl_Strategy_Composite();
  104. try {
  105. $strategy->addComplexType("Test");
  106. $this->fail();
  107. } catch(Exception $e) {
  108. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  109. }
  110. }
  111. }
  112. class Zend_Soap_Wsdl_Book
  113. {
  114. /**
  115. * @var int
  116. */
  117. public $somevar;
  118. }
  119. class Zend_Soap_Wsdl_Cookie
  120. {
  121. /**
  122. * @var int
  123. */
  124. public $othervar;
  125. }
  126. class Zend_Soap_Wsdl_Anything
  127. {
  128. }