/tests/ZendTest/Soap/TestAsset/commontypes.php

https://github.com/christeredvartsen/zf2 · PHP · 636 lines · 466 code · 28 blank · 142 comment · 0 complexity · fe1f35c47dc9dfdcace1023e200f9e7c MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_Soap
  9. */
  10. namespace ZendTest\Soap\TestAsset;
  11. /* Test Functions */
  12. /**
  13. * Test Function
  14. *
  15. * @param string $arg
  16. * @return string
  17. */
  18. function TestFunc($who)
  19. {
  20. return "Hello $who";
  21. }
  22. /**
  23. * Test Function 2
  24. */
  25. function TestFunc2()
  26. {
  27. return "Hello World";
  28. }
  29. /**
  30. * Return false
  31. *
  32. * @return bool
  33. */
  34. function TestFunc3()
  35. {
  36. return false;
  37. }
  38. /**
  39. * Return true
  40. *
  41. * @return bool
  42. */
  43. function TestFunc4()
  44. {
  45. return true;
  46. }
  47. /**
  48. * Return integer
  49. *
  50. * @return int
  51. */
  52. function TestFunc5()
  53. {
  54. return 123;
  55. }
  56. /**
  57. * Return string
  58. *
  59. * @return string
  60. */
  61. function TestFunc6()
  62. {
  63. return "string";
  64. }
  65. /**
  66. * Return array
  67. *
  68. * @return array
  69. */
  70. function TestFunc7()
  71. {
  72. return array('foo' => 'bar', 'baz' => true, 1 => false, 'bat' => 123);
  73. }
  74. /**
  75. * Return Object
  76. *
  77. * @return StdClass
  78. */
  79. function TestFunc8()
  80. {
  81. $return = (object) array('foo' => 'bar', 'baz' => true, 'bat' => 123, 'qux' => false);
  82. return $return;
  83. }
  84. /**
  85. * Multiple Args
  86. *
  87. * @param string $foo
  88. * @param string $bar
  89. * @return string
  90. */
  91. function TestFunc9($foo, $bar)
  92. {
  93. return "$foo $bar";
  94. }
  95. /**
  96. * @category Zend
  97. * @package Zend_Soap
  98. * @subpackage UnitTests
  99. */
  100. class TestFixingMultiplePrototypes
  101. {
  102. /**
  103. * Test function
  104. *
  105. * @param integer $a
  106. * @param integer $b
  107. * @param integer $d
  108. * @return integer
  109. */
  110. public function testFunc($a=100, $b=200, $d=300)
  111. {
  112. }
  113. }
  114. /**
  115. * @category Zend
  116. * @package Zend_Soap
  117. * @subpackage UnitTests
  118. */
  119. class Test
  120. {
  121. /**
  122. * Test Function 1
  123. *
  124. * @return string
  125. */
  126. public function testFunc1()
  127. {
  128. return "Hello World";
  129. }
  130. /**
  131. * Test Function 2
  132. *
  133. * @param string $who Some Arg
  134. * @return string
  135. */
  136. public function testFunc2($who)
  137. {
  138. return "Hello $who!";
  139. }
  140. /**
  141. * Test Function 3
  142. *
  143. * @param string $who Some Arg
  144. * @param int $when Some
  145. * @return string
  146. */
  147. public function testFunc3($who, $when)
  148. {
  149. return "Hello $who, How are you $when";
  150. }
  151. /**
  152. * Test Function 4
  153. *
  154. * @return string
  155. */
  156. public static function testFunc4()
  157. {
  158. return "I'm Static!";
  159. }
  160. }
  161. class AutoDiscoverTestClass1
  162. {
  163. /**
  164. * @var integer $var
  165. */
  166. public $var = 1;
  167. /**
  168. * @var string $param
  169. */
  170. public $param = "hello";
  171. }
  172. /**
  173. * @category Zend
  174. * @package Zend_Soap
  175. * @subpackage UnitTests
  176. */
  177. class AutoDiscoverTestClass2
  178. {
  179. /**
  180. *
  181. * @param \ZendTest\Soap\TestAsset\AutoDiscoverTestClass1 $test
  182. * @return bool
  183. */
  184. public function add(AutoDiscoverTestClass1 $test)
  185. {
  186. return true;
  187. }
  188. /**
  189. * @return \ZendTest\Soap\TestAsset\AutoDiscoverTestClass1[]
  190. */
  191. public function fetchAll()
  192. {
  193. return array(
  194. new AutoDiscoverTestClass1(),
  195. new AutoDiscoverTestClass1(),
  196. );
  197. }
  198. /**
  199. * @param \ZendTest\Soap\TestAsset\AutoDiscoverTestClass1[]
  200. */
  201. public function addMultiple($test)
  202. {
  203. }
  204. }
  205. /**
  206. * @category Zend
  207. * @package Zend_Soap
  208. * @subpackage UnitTests
  209. */
  210. class ComplexTypeB
  211. {
  212. /**
  213. * @var string
  214. */
  215. public $bar;
  216. /**
  217. * @var string
  218. */
  219. public $foo;
  220. }
  221. /**
  222. * @category Zend
  223. * @package Zend_Soap
  224. * @subpackage UnitTests
  225. */
  226. class ComplexTypeA
  227. {
  228. /**
  229. * @var \ZendTest\Soap\TestAsset\ComplexTypeB[]
  230. */
  231. public $baz = array();
  232. }
  233. /**
  234. * @category Zend
  235. * @package Zend_Soap
  236. * @subpackage UnitTests
  237. */
  238. class ComplexTest
  239. {
  240. /**
  241. * @var int
  242. */
  243. public $var = 5;
  244. }
  245. /**
  246. * @category Zend
  247. * @package Zend_Soap
  248. * @subpackage UnitTests
  249. */
  250. class ComplexObjectStructure
  251. {
  252. /**
  253. * @var bool
  254. */
  255. public $boolean = true;
  256. /**
  257. * @var string
  258. */
  259. public $string = "Hello World";
  260. /**
  261. * @var int
  262. */
  263. public $int = 10;
  264. /**
  265. * @var array
  266. */
  267. public $array = array(1, 2, 3);
  268. }
  269. /**
  270. * @category Zend
  271. * @package Zend_Soap
  272. * @subpackage UnitTests
  273. */
  274. class ComplexObjectWithObjectStructure
  275. {
  276. /**
  277. * @var \ZendTest\Soap\TestAsset\ComplexTest
  278. */
  279. public $object;
  280. }
  281. /**
  282. * @category Zend
  283. * @package Zend_Soap
  284. * @subpackage UnitTests
  285. */
  286. class MyService
  287. {
  288. /**
  289. * @param string $foo
  290. * @return \ZendTest\Soap\TestAsset\MyResponse[]
  291. */
  292. public function foo($foo)
  293. {
  294. }
  295. /**
  296. * @param string $bar
  297. * @return \ZendTest\Soap\TestAsset\MyResponse[]
  298. */
  299. public function bar($bar)
  300. {
  301. }
  302. /**
  303. * @param string $baz
  304. * @return \ZendTest\Soap\TestAsset\MyResponse[]
  305. */
  306. public function baz($baz)
  307. {
  308. }
  309. }
  310. /**
  311. * @category Zend
  312. * @package Zend_Soap
  313. * @subpackage UnitTests
  314. */
  315. class MyServiceSequence
  316. {
  317. /**
  318. * @param string $foo
  319. * @return string[]
  320. */
  321. public function foo($foo)
  322. {
  323. }
  324. /**
  325. * @param string $bar
  326. * @return string[]
  327. */
  328. public function bar($bar)
  329. {
  330. }
  331. /**
  332. * @param string $baz
  333. * @return string[]
  334. */
  335. public function baz($baz)
  336. {
  337. }
  338. /**
  339. * @param string $baz
  340. * @return string[][][]
  341. */
  342. public function bazNested($baz)
  343. {
  344. }
  345. }
  346. /**
  347. * @category Zend
  348. * @package Zend_Soap
  349. * @subpackage UnitTests
  350. */
  351. class MyResponse
  352. {
  353. /**
  354. * @var string
  355. */
  356. public $p1;
  357. }
  358. /**
  359. * @category Zend
  360. * @package Zend_Soap
  361. * @subpackage UnitTests
  362. */
  363. class Recursion
  364. {
  365. /**
  366. * @var \ZendTest\Soap\TestAsset\Recursion
  367. */
  368. public $recursion;
  369. /**
  370. * @return \ZendTest\Soap\TestAsset\Recursion
  371. */
  372. public function create() {}
  373. }
  374. /**
  375. * @param string $message
  376. */
  377. function OneWay($message)
  378. {
  379. }
  380. /**
  381. * @category Zend
  382. * @package Zend_Soap
  383. * @subpackage UnitTests
  384. */
  385. class NoReturnType
  386. {
  387. /**
  388. *
  389. * @param string $message
  390. */
  391. public function pushOneWay($message)
  392. {
  393. }
  394. }
  395. /* Client test classes */
  396. /** Test Class */
  397. class TestClass
  398. {
  399. /**
  400. * Test Function 1
  401. *
  402. * @return string
  403. */
  404. public function testFunc1()
  405. {
  406. return "Hello World";
  407. }
  408. /**
  409. * Test Function 2
  410. *
  411. * @param string $who Some Arg
  412. * @return string
  413. */
  414. public function testFunc2($who)
  415. {
  416. return "Hello $who!";
  417. }
  418. /**
  419. * Test Function 3
  420. *
  421. * @param string $who Some Arg
  422. * @param int $when Some
  423. * @return string
  424. */
  425. public function testFunc3($who, $when)
  426. {
  427. return "Hello $who, How are you $when";
  428. }
  429. /**
  430. * Test Function 4
  431. *
  432. * @return string
  433. */
  434. public static function testFunc4()
  435. {
  436. return "I'm Static!";
  437. }
  438. }
  439. /** Test class 2 */
  440. class TestData1
  441. {
  442. /**
  443. * Property1
  444. *
  445. * @var string
  446. */
  447. public $property1;
  448. /**
  449. * Property2
  450. *
  451. * @var float
  452. */
  453. public $property2;
  454. }
  455. /** Test class 2 */
  456. class TestData2
  457. {
  458. /**
  459. * Property1
  460. *
  461. * @var integer
  462. */
  463. public $property1;
  464. /**
  465. * Property1
  466. *
  467. * @var float
  468. */
  469. public $property2;
  470. }
  471. class MockSoapServer
  472. {
  473. public $handle = null;
  474. public function handle()
  475. {
  476. $this->handle = func_get_args();
  477. }
  478. public function __call($name, $args) {}
  479. }
  480. class MockServer extends \Zend\Soap\Server
  481. {
  482. public $mockSoapServer = null;
  483. protected function _getSoap()
  484. {
  485. $this->mockSoapServer = new MockSoapServer();
  486. return $this->mockSoapServer;
  487. }
  488. }
  489. /** Server test classes */
  490. class ServerTestClass
  491. {
  492. /**
  493. * Test Function 1
  494. *
  495. * @return string
  496. */
  497. public function testFunc1()
  498. {
  499. return "Hello World";
  500. }
  501. /**
  502. * Test Function 2
  503. *
  504. * @param string $who Some Arg
  505. * @return string
  506. */
  507. public function testFunc2($who)
  508. {
  509. return "Hello $who!";
  510. }
  511. /**
  512. * Test Function 3
  513. *
  514. * @param string $who Some Arg
  515. * @param int $when Some
  516. * @return string
  517. */
  518. public function testFunc3($who, $when)
  519. {
  520. return "Hello $who, How are you $when";
  521. }
  522. /**
  523. * Test Function 4
  524. *
  525. * @return string
  526. */
  527. public static function testFunc4()
  528. {
  529. return "I'm Static!";
  530. }
  531. /**
  532. * Test Function 5 raises a user error
  533. *
  534. * @return void
  535. */
  536. public function testFunc5()
  537. {
  538. trigger_error("Test Message", E_USER_ERROR);
  539. }
  540. }
  541. if (extension_loaded('soap')) {
  542. /** Local SOAP client */
  543. class TestLocalSoapClient extends \SoapClient
  544. {
  545. /**
  546. * Server object
  547. *
  548. * @var Zend_Soap_Server
  549. */
  550. public $server;
  551. /**
  552. * Local client constructor
  553. *
  554. * @param Zend_Soap_Server $server
  555. * @param string $wsdl
  556. * @param array $options
  557. */
  558. public function __construct(\Zend\Soap\Server $server, $wsdl, $options)
  559. {
  560. $this->server = $server;
  561. parent::__construct($wsdl, $options);
  562. }
  563. public function __doRequest($request, $location, $action, $version, $one_way = 0)
  564. {
  565. ob_start();
  566. $this->server->handle($request);
  567. $response = ob_get_clean();
  568. return $response;
  569. }
  570. }
  571. }