CompositeStrategyTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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-2008 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. class Zend_Soap_Wsdl_CompositeStrategyTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function testCompositeApiAddingStragiesToTypes()
  37. {
  38. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence");
  39. $strategy->connectTypeToStrategy("Book", "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  40. $bookStrategy = $strategy->getStrategyOfType("Book");
  41. $cookieStrategy = $strategy->getStrategyOfType("Cookie");
  42. $this->assertTrue( $bookStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex );
  43. $this->assertTrue( $cookieStrategy instanceof Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence );
  44. }
  45. public function testConstructorTypeMapSyntax()
  46. {
  47. $typeMap = array("Book" => "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  48. $strategy = new Zend_Soap_Wsdl_Strategy_Composite($typeMap, "Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence");
  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 testCompositeThrowsExceptionOnInvalidType()
  55. {
  56. $strategy = new Zend_Soap_Wsdl_Strategy_Composite();
  57. try {
  58. $strategy->connectTypeToStrategy(array(), "strategy");
  59. $this->fail();
  60. } catch(Exception $e) {
  61. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  62. }
  63. }
  64. public function testCompositeThrowsExceptionOnInvalidStrategy()
  65. {
  66. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "invalid");
  67. $strategy->connectTypeToStrategy("Book", "strategy");
  68. try {
  69. $book = $strategy->getStrategyOfType("Book");
  70. $this->fail();
  71. } catch(Exception $e) {
  72. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  73. }
  74. try {
  75. $book = $strategy->getStrategyOfType("Anything");
  76. $this->fail();
  77. } catch(Exception $e) {
  78. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  79. }
  80. }
  81. public function testCompositeDelegatesAddingComplexTypesToSubStrategies()
  82. {
  83. $strategy = new Zend_Soap_Wsdl_Strategy_Composite(array(), "Zend_Soap_Wsdl_Strategy_AnyType");
  84. $strategy->connectTypeToStrategy("Zend_Soap_Wsdl_Book", "Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex");
  85. $strategy->connectTypeToStrategy("Zend_Soap_Wsdl_Cookie", "Zend_Soap_Wsdl_Strategy_DefaultComplexType");
  86. $wsdl = new Zend_Soap_Wsdl("SomeService", "http://example.com");
  87. $strategy->setContext($wsdl);
  88. $this->assertEquals("tns:Zend_Soap_Wsdl_Book", $strategy->addComplexType("Zend_Soap_Wsdl_Book"));
  89. $this->assertEquals("tns:Zend_Soap_Wsdl_Cookie", $strategy->addComplexType("Zend_Soap_Wsdl_Cookie"));
  90. $this->assertEquals("xsd:anyType", $strategy->addComplexType("Zend_Soap_Wsdl_Anything"));
  91. }
  92. public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrowsException()
  93. {
  94. $strategy = new Zend_Soap_Wsdl_Strategy_Composite();
  95. try {
  96. $strategy->addComplexType("Test");
  97. $this->fail();
  98. } catch(Exception $e) {
  99. $this->assertTrue($e instanceof Zend_Soap_Wsdl_Exception);
  100. }
  101. }
  102. }
  103. class Zend_Soap_Wsdl_Book
  104. {
  105. /**
  106. * @var int
  107. */
  108. public $somevar;
  109. }
  110. class Zend_Soap_Wsdl_Cookie
  111. {
  112. /**
  113. * @var int
  114. */
  115. public $othervar;
  116. }
  117. class Zend_Soap_Wsdl_Anything
  118. {
  119. }