ServerTest.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. <?php
  2. // Call Zend_Amf_ServerTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_Amf_ServerTest::main");
  5. }
  6. /**
  7. * Test helper
  8. */
  9. require_once dirname(__FILE__) . '/../../TestHelper.php';
  10. require_once 'Zend/Amf/Server.php';
  11. require_once 'Zend/Amf/Request.php';
  12. require_once 'Zend/Amf/Parse/TypeLoader.php';
  13. require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
  14. require_once 'ServiceA.php';
  15. require_once 'ServiceB.php';
  16. require_once 'Zend/Session.php';
  17. class Zend_Amf_ServerTest extends PHPUnit_Framework_TestCase
  18. {
  19. protected $_server;
  20. public static function main()
  21. {
  22. $suite = new PHPUnit_Framework_TestSuite("Zend_Amf_ServerTest");
  23. $result = PHPUnit_TextUI_TestRunner::run($suite);
  24. }
  25. public function setUp()
  26. {
  27. $this->_server = new Zend_Amf_Server();
  28. $this->_server->setProduction(false);
  29. Zend_Amf_Parse_TypeLoader::resetMap();
  30. }
  31. public function testDown()
  32. {
  33. unset($this->_server);
  34. //Zend_Amf_Parse_TypeLoader::resetMap();
  35. }
  36. /**
  37. * Call as method call
  38. *
  39. * Returns: void
  40. */
  41. public function test__construct()
  42. {
  43. $this->assertTrue($this->_server instanceof Zend_Amf_Server);
  44. }
  45. public function testIsProductionByDefault()
  46. {
  47. $this->_server = new Zend_Amf_Server;
  48. $this->assertTrue($this->_server->isProduction());
  49. }
  50. public function testProductionFlagShouldBeMutable()
  51. {
  52. $this->testIsProductionByDefault();
  53. $this->_server->setProduction(false);
  54. $this->assertFalse($this->_server->isProduction());
  55. $this->_server->setProduction(true);
  56. $this->assertTrue($this->_server->isProduction());
  57. }
  58. public function testSetClass()
  59. {
  60. $this->_server->setClass('Zend_Amf_testclass', 'test');
  61. $methods = $this->_server->listMethods();
  62. $this->assertTrue(in_array('test.test1', $methods));
  63. $this->assertTrue(in_array('test.test2', $methods));
  64. $this->assertFalse(in_array('test._test3', $methods));
  65. $this->assertFalse(in_array('test.__construct', $methods));
  66. }
  67. /**
  68. * @expectedException Zend_Amf_Server_Exception
  69. */
  70. public function testSetClassShouldRaiseExceptionOnInvalidClassname()
  71. {
  72. $this->_server->setClass('foobar');
  73. }
  74. /**
  75. * @expectedException Zend_Amf_Server_Exception
  76. */
  77. public function testSetClassShouldRaiseExceptionOnInvalidClasstype()
  78. {
  79. $this->_server->setClass(array('foobar'));
  80. }
  81. /**
  82. * @expectedException Zend_Amf_Server_Exception
  83. */
  84. public function testSetClassShouldRaiseExceptionOnDuplicateMethodName()
  85. {
  86. $this->_server->setClass('Zend_Amf_testclass', 'tc');
  87. $this->_server->setClass('Zend_Amf_testclassPrivate', 'tc');
  88. }
  89. /**
  90. * ZF-5393
  91. */
  92. public function testSetClassUsingObject()
  93. {
  94. $testClass = new Zend_Amf_testclass();
  95. $this->_server->setClass($testClass);
  96. $this->assertEquals(8, count($this->_server->getFunctions()));
  97. }
  98. /**
  99. * addFunction() test
  100. *
  101. * Call as method call
  102. *
  103. * Expects:
  104. * - function:
  105. * - namespace: Optional; has default;
  106. *
  107. * Returns: void
  108. */
  109. public function testAddFunction()
  110. {
  111. try {
  112. $this->_server->addFunction('Zend_Amf_Server_testFunction', 'test');
  113. } catch (Exception $e) {
  114. $this->fail('Attachment should have worked');
  115. }
  116. $methods = $this->_server->listMethods();
  117. $this->assertTrue(in_array('test.Zend_Amf_Server_testFunction', $methods), var_export($methods, 1));
  118. try {
  119. $this->_server->addFunction('nosuchfunction');
  120. $this->fail('nosuchfunction() should not exist and should throw an exception');
  121. } catch (Exception $e) {
  122. // do nothing
  123. }
  124. $server = new Zend_Amf_Server();
  125. try {
  126. $server->addFunction(
  127. array(
  128. 'Zend_Amf_Server_testFunction',
  129. 'Zend_Amf_Server_testFunction2',
  130. ),
  131. 'zsr'
  132. );
  133. } catch (Exception $e) {
  134. $this->fail('Error attaching array of functions: ' . $e->getMessage());
  135. }
  136. $methods = $server->listMethods();
  137. $this->assertTrue(in_array('zsr.Zend_Amf_Server_testFunction', $methods));
  138. $this->assertTrue(in_array('zsr.Zend_Amf_Server_testFunction2', $methods));
  139. }
  140. /**
  141. * @expectedException Zend_Amf_Server_Exception
  142. */
  143. public function testAddFunctionShouldRaiseExceptionForInvalidFunctionName()
  144. {
  145. $this->_server->addFunction(true);
  146. }
  147. /**
  148. * @expectedException Zend_Amf_Server_Exception
  149. */
  150. public function testAddFunctionShouldRaiseExceptionOnDuplicateMethodName()
  151. {
  152. $this->_server->addFunction('Zend_Amf_Server_testFunction', 'tc');
  153. $this->_server->addFunction('Zend_Amf_Server_testFunction', 'tc');
  154. }
  155. /**
  156. * Test sending data to the remote class and make sure we
  157. * recieve the proper response.
  158. *
  159. */
  160. public function testHandleLoadedClassAmf0()
  161. {
  162. // serialize the data to an AMF output stream
  163. $data[] = "12345";
  164. $this->_server->setClass('Zend_Amf_testclass');
  165. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_testclass.test1","/1",$data);
  166. $request = new Zend_Amf_Request();
  167. $request->addAmfBody($newBody);
  168. $request->setObjectEncoding(0x00);
  169. $result = $this->_server->handle($request);
  170. $response = $this->_server->getResponse();
  171. $responseBody = $response->getAmfBodies();
  172. // Now check if the return data was properly set.
  173. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  174. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  175. $this->assertEquals("String: 12345", $responseBody[0]->getData(), var_export($responseBody, 1));
  176. }
  177. public function testShouldAllowHandlingFunctionCallsViaAmf0()
  178. {
  179. // serialize the data to an AMF output stream
  180. $data = array('foo', 'bar');
  181. $this->_server->addFunction('Zend_Amf_Server_testFunction');
  182. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_Server_testFunction","/1",$data);
  183. $request = new Zend_Amf_Request();
  184. $request->addAmfBody($newBody);
  185. $request->setObjectEncoding(0x00);
  186. $result = $this->_server->handle($request);
  187. $response = $this->_server->getResponse();
  188. $responseBody = $response->getAmfBodies();
  189. // Now check if the return data was properly set.
  190. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  191. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  192. $this->assertEquals("bar: foo", $responseBody[0]->getData(), var_export($responseBody, 1));
  193. }
  194. /**
  195. * Test to make sure that AMF3 basic requests are handled for loading
  196. * a class.
  197. * This type of call is sent from NetConnection rather than RemoteObject
  198. *
  199. * @group ZF-4680
  200. */
  201. public function testHandleLoadedClassAmf3NetConnection()
  202. {
  203. // serialize the data to an AMF output stream
  204. $data[] = "12345";
  205. $this->_server->setClass('Zend_Amf_testclass');
  206. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_testclass.test1","/1",$data);
  207. $request = new Zend_Amf_Request();
  208. $request->addAmfBody($newBody);
  209. $request->setObjectEncoding(0x03);
  210. $result = $this->_server->handle($request);
  211. $response = $this->_server->getResponse();
  212. $responseBody = $response->getAmfBodies();
  213. // Now check if the return data was properly set.
  214. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  215. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  216. $this->assertEquals("String: 12345", $responseBody[0]->getData(), var_export($responseBody, 1));
  217. }
  218. /**
  219. * Test to make sure that AMF3 basic requests are handled for function calls.
  220. * This type of call is sent from net connection rather than RemoteObject
  221. *
  222. * @group ZF-4680
  223. */
  224. public function testShouldAllowHandlingFunctionCallsViaAmf3NetConnection()
  225. {
  226. // serialize the data to an AMF output stream
  227. $data = array('foo', 'bar');
  228. $this->_server->addFunction('Zend_Amf_Server_testFunction');
  229. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_Server_testFunction","/1",$data);
  230. $request = new Zend_Amf_Request();
  231. $request->addAmfBody($newBody);
  232. $request->setObjectEncoding(0x03);
  233. $result = $this->_server->handle($request);
  234. $response = $this->_server->getResponse();
  235. $responseBody = $response->getAmfBodies();
  236. // Now check if the return data was properly set.
  237. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  238. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  239. $this->assertEquals("bar: foo", $responseBody[0]->getData(), var_export($responseBody, 1));
  240. }
  241. /**
  242. * Test sending data to the remote class and make sure we
  243. * recieve the proper response.
  244. *
  245. */
  246. public function testHandleLoadedClassAmf3()
  247. {
  248. // serialize the data to an AMF output stream
  249. $data[] = "12345";
  250. $this->_server->setClass('Zend_Amf_testclass');
  251. // create a mock remoting message
  252. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  253. $message->operation = 'test1';
  254. $message->source = 'Zend_Amf_testclass';
  255. $message->body = $data;
  256. // create a mock message body to place th remoting message inside
  257. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  258. $request = new Zend_Amf_Request();
  259. // at the requested service to a request
  260. $request->addAmfBody($newBody);
  261. $request->setObjectEncoding(0x03);
  262. // let the server handle mock request
  263. $result = $this->_server->handle($request);
  264. $response = $this->_server->getResponse();
  265. $responseBody = $response->getAmfBodies();
  266. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  267. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  268. // Now check if the return data was properly set.
  269. $acknowledgeMessage = $responseBody[0]->getData();
  270. // check that we have a message beening returned
  271. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  272. // Check the message body is the expected data to be returned
  273. $this->assertEquals("String: 12345", $acknowledgeMessage->body);
  274. }
  275. /**
  276. * Test to make sure that you can have the same method name in two different classes.
  277. *
  278. * @group ZF-5040
  279. */
  280. public function testSameMethodNameInTwoServices()
  281. {
  282. $this->_server->setClass('ServiceA');
  283. $this->_server->setClass('ServiceB');
  284. // create a mock remoting message
  285. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  286. $message->operation = 'getMenu';
  287. $message->source = 'ServiceB';
  288. $message->body = array();
  289. // create a mock message body to place th remoting message inside
  290. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  291. $request = new Zend_Amf_Request();
  292. // at the requested service to a request
  293. $request->addAmfBody($newBody);
  294. $request->setObjectEncoding(0x03);
  295. // let the server handle mock request
  296. $result = $this->_server->handle($request);
  297. $response = $this->_server->getResponse();
  298. $responseBody = $response->getAmfBodies();
  299. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  300. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  301. // Now check if the return data was properly set.
  302. $acknowledgeMessage = $responseBody[0]->getData();
  303. // check that we have a message beening returned
  304. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  305. // Check the message body is the expected data to be returned
  306. $this->assertEquals("myMenuB", $acknowledgeMessage->body);
  307. }
  308. /**
  309. * test command message. THis is the first call the Flex
  310. * makes before any subsequent service calls.
  311. */
  312. public function testCommandMessagePingOperation()
  313. {
  314. $message = new Zend_Amf_Value_Messaging_CommandMessage();
  315. $message->operation = 5;
  316. $message->messageId = $message->generateId();
  317. // create a mock message body to place th remoting message inside
  318. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  319. $request = new Zend_Amf_Request();
  320. // at the requested service to a request
  321. $request->addAmfBody($newBody);
  322. $request->setObjectEncoding(0x03);
  323. // let the server handle mock request
  324. $result = $this->_server->handle($request);
  325. $response = $this->_server->getResponse();
  326. $responseBody = $response->getAmfBodies();
  327. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  328. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  329. // Now check if the return data was properly set.
  330. $acknowledgeMessage = $responseBody[0]->getData();
  331. // check that we have a message beening returned
  332. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  333. // Check that the MessageID was not corrupeted when set to the correlationId
  334. $this->assertEquals($acknowledgeMessage->correlationId, $message->messageId);
  335. }
  336. public function testInvalidAmf0MessageShouldResultInErrorMessage()
  337. {
  338. // serialize the data to an AMF output stream
  339. $data[] = "12345";
  340. $this->_server->setClass('Zend_Amf_testclass');
  341. $newBody = new Zend_Amf_Value_MessageBody("bogus","/1",$data);
  342. $request = new Zend_Amf_Request();
  343. $request->addAmfBody($newBody);
  344. $request->setObjectEncoding(0x00);
  345. $result = $this->_server->handle($request);
  346. $bodies = $result->getAmfBodies();
  347. $found = false;
  348. foreach ($bodies as $body) {
  349. $data = $body->getData();
  350. if (!is_array($data)) {
  351. continue;
  352. }
  353. if (!array_key_exists('description', $data)) {
  354. continue;
  355. }
  356. if (strstr($data['description'], 'does not exist')) {
  357. $found = true;
  358. break;
  359. }
  360. }
  361. $this->assertTrue($found, 'Invalid method did not raise error condition' . var_export($bodies, 1));
  362. }
  363. public function testInvalidCommandMessageShouldResultInErrorMessage()
  364. {
  365. $message = new Zend_Amf_Value_Messaging_CommandMessage();
  366. $message->operation = 'pong';
  367. $message->messageId = $message->generateId();
  368. // create a mock message body to place th remoting message inside
  369. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  370. $request = new Zend_Amf_Request();
  371. // at the requested service to a request
  372. $request->addAmfBody($newBody);
  373. $request->setObjectEncoding(0x03);
  374. // let the server handle mock request
  375. $result = $this->_server->handle($request);
  376. $response = $this->_server->getResponse();
  377. $responseBody = $response->getAmfBodies();
  378. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  379. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  380. // Now check if the return data was properly set.
  381. $message = $responseBody[0]->getData();
  382. // check that we have a message beening returned
  383. $this->assertTrue($message instanceof Zend_Amf_Value_Messaging_ErrorMessage);
  384. }
  385. /**
  386. * Add a class mapping and lookup the mapping to make sure
  387. * the mapping succeeds
  388. */
  389. public function testClassMap()
  390. {
  391. $this->_server->setClassMap('controller.test', 'Zend_Amf_testclass');
  392. $className = Zend_Amf_Parse_TypeLoader::getMappedClassName('Zend_Amf_testclass');
  393. $this->assertEquals('controller.test', $className);
  394. }
  395. public function testDispatchingMethodShouldReturnErrorMessageForInvalidMethod()
  396. {
  397. // serialize the data to an AMF output stream
  398. $data[] = "12345";
  399. $this->_server->setClass('Zend_Amf_testclass');
  400. // create a mock remoting message
  401. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  402. $message->operation = 'bogus'; // INVALID method!
  403. $message->body = $data;
  404. // create a mock message body to place th remoting message inside
  405. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  406. $request = new Zend_Amf_Request();
  407. // at the requested service to a request
  408. $request->addAmfBody($newBody);
  409. $request->setObjectEncoding(0x03);
  410. // let the server handle mock request
  411. $result = $this->_server->handle($request);
  412. $bodies = $result->getAmfBodies();
  413. $found = false;
  414. foreach ($bodies as $body) {
  415. $data = $body->getData();
  416. if ($data instanceof Zend_Amf_Value_Messaging_ErrorMessage) {
  417. if (strstr($data->faultString, 'does not exist')) {
  418. $found = true;
  419. break;
  420. }
  421. }
  422. }
  423. $this->assertTrue($found, 'Invalid method did not raise error condition: ' . var_export($bodies, 1));
  424. }
  425. public function testDispatchingMethodThatThrowsExceptionShouldReturnErrorMessageWhenProductionFlagOff()
  426. {
  427. // serialize the data to an AMF output stream
  428. $data = array();
  429. $this->_server->setClass('Zend_Amf_testclass');
  430. // create a mock remoting message
  431. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  432. $message->operation = 'throwException';
  433. $message->source = 'Zend_Amf_testclass';
  434. $message->body = $data;
  435. // create a mock message body to place th remoting message inside
  436. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  437. $request = new Zend_Amf_Request();
  438. // at the requested service to a request
  439. $request->addAmfBody($newBody);
  440. $request->setObjectEncoding(0x03);
  441. // let the server handle mock request
  442. $result = $this->_server->handle($request);
  443. $bodies = $result->getAmfBodies();
  444. $found = false;
  445. foreach ($bodies as $body) {
  446. $data = $body->getData();
  447. if ($data instanceof Zend_Amf_Value_Messaging_ErrorMessage) {
  448. if (strstr($data->faultString, 'should not be displayed')) {
  449. $found = true;
  450. break;
  451. }
  452. }
  453. }
  454. $this->assertTrue($found, 'Method raising exception should display error message when not in production');
  455. }
  456. public function testDispatchingMethodThatThrowsExceptionShouldNotReturnErrorMessageWhenProductionFlagOn()
  457. {
  458. // serialize the data to an AMF output stream
  459. $data = array();
  460. $this->_server->setClass('Zend_Amf_testclass')
  461. ->setProduction(true);
  462. // create a mock remoting message
  463. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  464. $message->operation = 'throwException';
  465. $message->source = 'Zend_Amf_testclass';
  466. $message->body = $data;
  467. // create a mock message body to place th remoting message inside
  468. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  469. $request = new Zend_Amf_Request();
  470. // at the requested service to a request
  471. $request->addAmfBody($newBody);
  472. $request->setObjectEncoding(0x03);
  473. // let the server handle mock request
  474. $result = $this->_server->handle($request);
  475. $bodies = $result->getAmfBodies();
  476. $found = false;
  477. foreach ($bodies as $body) {
  478. $data = $body->getData();
  479. if ($data instanceof Zend_Amf_Value_Messaging_ErrorMessage) {
  480. if (strstr($data->faultString, 'should not be displayed')) {
  481. $found = true;
  482. break;
  483. }
  484. }
  485. }
  486. $this->assertFalse($found, 'Method raising exception should not display error message when in production');
  487. }
  488. public function testDispatchingMethodShouldPassInvocationArgumentsToMethod()
  489. {
  490. // serialize the data to an AMF output stream
  491. $data[] = "baz";
  492. $this->_server->setClass('Zend_Amf_testclass', '', 'foo', 'bar');
  493. // create a mock remoting message
  494. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  495. $message->operation = 'checkArgv';
  496. $message->source = 'Zend_Amf_testclass';
  497. $message->body = $data;
  498. // create a mock message body to place th remoting message inside
  499. $newBody = new Zend_Amf_Value_MessageBody(null, "/1" ,$message);
  500. $request = new Zend_Amf_Request();
  501. // at the requested service to a request
  502. $request->addAmfBody($newBody);
  503. $request->setObjectEncoding(0x03);
  504. // let the server handle mock request
  505. $result = $this->_server->handle($request);
  506. $bodies = $result->getAmfBodies();
  507. $found = false;
  508. foreach ($bodies as $body) {
  509. $data = $body->getData();
  510. if ('Zend_Amf_Value_Messaging_AcknowledgeMessage' == get_class($data)) {
  511. if ('baz:foo:bar' == $data->body) {
  512. $found = true;
  513. break;
  514. }
  515. }
  516. }
  517. $this->assertTrue($found, 'Valid response not found');
  518. }
  519. public function testServerShouldSeamlesslyInvokeStaticMethods()
  520. {
  521. // serialize the data to an AMF output stream
  522. $data[] = "testing";
  523. $this->_server->setClass('Zend_Amf_testclass');
  524. // create a mock remoting message
  525. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  526. $message->operation = 'checkStaticUsage';
  527. $message->source = 'Zend_Amf_testclass';
  528. $message->body = $data;
  529. // create a mock message body to place th remoting message inside
  530. $newBody = new Zend_Amf_Value_MessageBody(null, "/1" ,$message);
  531. $request = new Zend_Amf_Request();
  532. // at the requested service to a request
  533. $request->addAmfBody($newBody);
  534. $request->setObjectEncoding(0x03);
  535. // let the server handle mock request
  536. $result = $this->_server->handle($request);
  537. $bodies = $result->getAmfBodies();
  538. $found = false;
  539. foreach ($bodies as $body) {
  540. $data = $body->getData();
  541. if ('Zend_Amf_Value_Messaging_AcknowledgeMessage' == get_class($data)) {
  542. if ('testing' == $data->body) {
  543. $found = true;
  544. break;
  545. }
  546. }
  547. }
  548. $this->assertTrue($found, 'Valid response not found');
  549. }
  550. public function testServerShouldSeamlesslyInvokeFunctions()
  551. {
  552. // serialize the data to an AMF output stream
  553. $data[] = 'foo';
  554. $data[] = 'bar';
  555. $this->_server->addFunction('Zend_Amf_Server_testFunction');
  556. // create a mock remoting message
  557. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  558. $message->operation = 'Zend_Amf_Server_testFunction';
  559. $message->source = null;
  560. $message->body = $data;
  561. // create a mock message body to place th remoting message inside
  562. $newBody = new Zend_Amf_Value_MessageBody(null, "/1" ,$message);
  563. $request = new Zend_Amf_Request();
  564. // at the requested service to a request
  565. $request->addAmfBody($newBody);
  566. $request->setObjectEncoding(0x03);
  567. // let the server handle mock request
  568. $result = $this->_server->handle($request);
  569. $bodies = $result->getAmfBodies();
  570. $found = false;
  571. foreach ($bodies as $body) {
  572. $data = $body->getData();
  573. if ('Zend_Amf_Value_Messaging_AcknowledgeMessage' == get_class($data)) {
  574. if ('bar: foo' == $data->body) {
  575. $found = true;
  576. break;
  577. }
  578. }
  579. }
  580. $this->assertTrue($found, 'Valid response not found');
  581. }
  582. public function testDispatchingMethodCorrespondingToClassWithPrivateConstructorShouldReturnErrorMessage()
  583. {
  584. // serialize the data to an AMF output stream
  585. $data[] = "baz";
  586. $this->_server->setClass('Zend_Amf_testclassPrivate');
  587. // create a mock remoting message
  588. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  589. $message->operation = 'test1';
  590. $message->source = 'Zend_Amf_testclassPrivate';
  591. $message->body = $data;
  592. // create a mock message body to place th remoting message inside
  593. $newBody = new Zend_Amf_Value_MessageBody(null, "/1" ,$message);
  594. $request = new Zend_Amf_Request();
  595. // at the requested service to a request
  596. $request->addAmfBody($newBody);
  597. $request->setObjectEncoding(0x03);
  598. // let the server handle mock request
  599. $result = $this->_server->handle($request);
  600. $bodies = $result->getAmfBodies();
  601. $found = false;
  602. foreach ($bodies as $body) {
  603. $data = $body->getData();
  604. if ('Zend_Amf_Value_Messaging_ErrorMessage' == get_class($data)) {
  605. if (strstr($data->faultString, 'Error instantiating class')) {
  606. $found = true;
  607. break;
  608. }
  609. }
  610. }
  611. $this->assertTrue($found, 'Method succeeded?');
  612. }
  613. public function testNotPassingRequestToHandleShouldResultInServerCreatingRequest()
  614. {
  615. $this->_server->setClass('Zend_Amf_testclass');
  616. ob_start();
  617. $result = $this->_server->handle();
  618. $content = ob_get_clean();
  619. $request = $this->_server->getRequest();
  620. $this->assertTrue($request instanceof Zend_Amf_Request_Http);
  621. $bodies = $request->getAmfBodies();
  622. $this->assertEquals(0, count($bodies));
  623. $this->assertContains('Endpoint', $content);
  624. }
  625. public function testSetRequestShouldAllowValidStringClassNames()
  626. {
  627. $this->_server->setRequest('Zend_Amf_Request');
  628. $request = $this->_server->getRequest();
  629. $this->assertTrue($request instanceof Zend_Amf_Request);
  630. $this->assertFalse($request instanceof Zend_Amf_Request_Http);
  631. }
  632. /**
  633. * @expectedException Zend_Amf_Server_Exception
  634. */
  635. public function testSetRequestShouldRaiseExceptionOnInvalidStringClassName()
  636. {
  637. $this->_server->setRequest('Zend_Amf_ServerTest_BogusRequest');
  638. }
  639. public function testSetRequestShouldAllowValidRequestObjects()
  640. {
  641. $request = new Zend_Amf_Request;
  642. $this->_server->setRequest($request);
  643. $this->assertSame($request, $this->_server->getRequest());
  644. }
  645. /**
  646. * @expectedException Zend_Amf_Server_Exception
  647. */
  648. public function testSetRequestShouldRaiseExceptionOnInvalidRequestObjects()
  649. {
  650. require_once 'Zend/XmlRpc/Request.php';
  651. $request = new Zend_XmlRpc_Request;
  652. $this->_server->setRequest($request);
  653. }
  654. public function testSetResponseShouldAllowValidStringClassNames()
  655. {
  656. $this->_server->setResponse('Zend_Amf_Response');
  657. $response = $this->_server->getResponse();
  658. $this->assertTrue($response instanceof Zend_Amf_Response);
  659. $this->assertFalse($response instanceof Zend_Amf_Response_Http);
  660. }
  661. /**
  662. * @expectedException Zend_Amf_Server_Exception
  663. */
  664. public function testSetResponseShouldRaiseExceptionOnInvalidStringClassName()
  665. {
  666. $this->_server->setResponse('Zend_Amf_ServerTest_BogusResponse');
  667. }
  668. public function testSetResponseShouldAllowValidResponseObjects()
  669. {
  670. $response = new Zend_Amf_Response;
  671. $this->_server->setResponse($response);
  672. $this->assertSame($response, $this->_server->getResponse());
  673. }
  674. /**
  675. * @expectedException Zend_Amf_Server_Exception
  676. */
  677. public function testSetResponseShouldRaiseExceptionOnInvalidResponseObjects()
  678. {
  679. require_once 'Zend/XmlRpc/Response.php';
  680. $response = new Zend_XmlRpc_Response;
  681. $this->_server->setResponse($response);
  682. }
  683. public function testGetFunctionsShouldReturnArrayOfDispatchables()
  684. {
  685. $this->_server->addFunction('Zend_Amf_Server_testFunction', 'tf')
  686. ->setClass('Zend_Amf_testclass', 'tc')
  687. ->setClass('Zend_Amf_testclassPrivate', 'tcp');
  688. $functions = $this->_server->getFunctions();
  689. $this->assertTrue(is_array($functions));
  690. $this->assertTrue(0 < count($functions));
  691. $namespaces = array('tf', 'tc', 'tcp');
  692. foreach ($functions as $key => $value) {
  693. $this->assertTrue(strstr($key, '.') ? true : false, $key);
  694. $ns = substr($key, 0, strpos($key, '.'));
  695. $this->assertContains($ns, $namespaces, $key);
  696. $this->assertTrue($value instanceof Zend_Server_Reflection_Function_Abstract);
  697. }
  698. }
  699. public function testFaultShouldBeUnimplemented()
  700. {
  701. $this->assertNull($this->_server->fault());
  702. }
  703. public function testPersistenceShouldBeUnimplemented()
  704. {
  705. $this->assertNull($this->_server->setPersistence(true));
  706. }
  707. public function testLoadFunctionsShouldBeUnimplemented()
  708. {
  709. $this->assertNull($this->_server->loadFunctions(true));
  710. }
  711. /**
  712. * @group ZF-5388
  713. * Issue if only one parameter of type array is passed it is nested into another array.
  714. */
  715. public function testSingleArrayParamaterAMF3()
  716. {
  717. // serialize the data to an AMF output stream
  718. $data[] = array('item1', 'item2');
  719. $this->_server->setClass('Zend_Amf_testclass');
  720. // create a mock remoting message
  721. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  722. $message->operation = 'testSingleArrayParamater';
  723. $message->source = 'Zend_Amf_testclass';
  724. $message->body = $data;
  725. // create a mock message body to place th remoting message inside
  726. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  727. $request = new Zend_Amf_Request();
  728. // at the requested service to a request
  729. $request->addAmfBody($newBody);
  730. $request->setObjectEncoding(0x03);
  731. // let the server handle mock request
  732. $result = $this->_server->handle($request);
  733. $response = $this->_server->getResponse();
  734. $responseBody = $response->getAmfBodies();
  735. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  736. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  737. // Now check if the return data was properly set.
  738. $acknowledgeMessage = $responseBody[0]->getData();
  739. // check that we have a message beening returned
  740. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  741. // Check the message body is the expected data to be returned
  742. $this->assertTrue($acknowledgeMessage->body);
  743. }
  744. /**
  745. * @group ZF-5388
  746. * Issue if only one parameter of type array is passed it is nested into another array.
  747. */
  748. public function testSingleArrayParamaterAMF0()
  749. {
  750. $data[] = array('item1', 'item2');
  751. $this->_server->setClass('Zend_Amf_testclass');
  752. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_testclass.testSingleArrayParamater","/1",$data);
  753. $request = new Zend_Amf_Request();
  754. $request->addAmfBody($newBody);
  755. $request->setObjectEncoding(0x00);
  756. $result = $this->_server->handle($request);
  757. $response = $this->_server->getResponse();
  758. $responseBody = $response->getAmfBodies();
  759. // Now check if the return data was properly set.
  760. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  761. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  762. $this->assertTrue($responseBody[0]->getData(), var_export($responseBody, 1));
  763. }
  764. /**
  765. * @group ZF-5388
  766. * Issue if only one parameter of type array is passed it is nested into another array.
  767. */
  768. public function testMutiArrayParamaterAMF3()
  769. {
  770. // serialize the data to an AMF output stream
  771. $data[] = array('item1', 'item2');
  772. $data[] = array('item3', 'item4');
  773. $this->_server->setClass('Zend_Amf_testclass');
  774. // create a mock remoting message
  775. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  776. $message->operation = 'testMultiArrayParamater';
  777. $message->source = 'Zend_Amf_testclass';
  778. $message->body = $data;
  779. // create a mock message body to place th remoting message inside
  780. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  781. $request = new Zend_Amf_Request();
  782. // at the requested service to a request
  783. $request->addAmfBody($newBody);
  784. $request->setObjectEncoding(0x03);
  785. // let the server handle mock request
  786. $result = $this->_server->handle($request);
  787. $response = $this->_server->getResponse();
  788. $responseBody = $response->getAmfBodies();
  789. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  790. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  791. // Now check if the return data was properly set.
  792. $acknowledgeMessage = $responseBody[0]->getData();
  793. // check that we have a message beening returned
  794. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  795. // Check the message body is the expected data to be returned
  796. $this->assertEquals(4, count($acknowledgeMessage->body));
  797. }
  798. /**
  799. * @group ZF-5388
  800. * Issue if multipol parameters are sent and one is of type array is passed.
  801. */
  802. public function testMutiArrayParamaterAMF0()
  803. {
  804. $data[] = array('item1', 'item2');
  805. $data[] = array('item3', 'item4');
  806. $this->_server->setClass('Zend_Amf_testclass');
  807. $newBody = new Zend_Amf_Value_MessageBody("Zend_Amf_testclass.testMultiArrayParamater","/1",$data);
  808. $request = new Zend_Amf_Request();
  809. $request->addAmfBody($newBody);
  810. $request->setObjectEncoding(0x00);
  811. $result = $this->_server->handle($request);
  812. $response = $this->_server->getResponse();
  813. $responseBody = $response->getAmfBodies();
  814. // Now check if the return data was properly set.
  815. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  816. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  817. $this->assertEquals(4, count($responseBody[0]->getData()), var_export($responseBody, 1));
  818. }
  819. /**
  820. * @group ZF-5346
  821. */
  822. public function testSingleObjectParamaterAMF3()
  823. {
  824. // serialize the data to an AMF output stream
  825. $data[] = array('item1', 'item2');
  826. $data[] = array('item3', 'item4');
  827. $this->_server->setClass('Zend_Amf_testclass');
  828. // create a mock remoting message
  829. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  830. $message->operation = 'testMultiArrayParamater';
  831. $message->source = 'Zend_Amf_testclass';
  832. $message->body = $data;
  833. // create a mock message body to place th remoting message inside
  834. $newBody = new Zend_Amf_Value_MessageBody(null,"/1",$message);
  835. $request = new Zend_Amf_Request();
  836. // at the requested service to a request
  837. $request->addAmfBody($newBody);
  838. $request->setObjectEncoding(0x03);
  839. // let the server handle mock request
  840. $result = $this->_server->handle($request);
  841. $response = $this->_server->getResponse();
  842. $responseBody = $response->getAmfBodies();
  843. $this->assertTrue(0 < count($responseBody), var_export($responseBody, 1));
  844. $this->assertTrue(array_key_exists(0, $responseBody), var_export($responseBody, 1));
  845. // Now check if the return data was properly set.
  846. $acknowledgeMessage = $responseBody[0]->getData();
  847. // check that we have a message beening returned
  848. $this->assertTrue($acknowledgeMessage instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  849. // Check the message body is the expected data to be returned
  850. $this->assertEquals(4, count($acknowledgeMessage->body));
  851. }
  852. /**
  853. * Check that when using server->setSession you get an amf header that has an append to gateway sessionID
  854. * @group ZF-5381
  855. */
  856. public function testSessionAmf3()
  857. {
  858. Zend_Session::start();
  859. $this->_server->setClass('Zend_Amf_testSession');
  860. $this->_server->setSession();
  861. // create a mock remoting message
  862. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  863. $message->operation = 'getCount';
  864. $message->source = 'Zend_Amf_testSession';
  865. $message->body = array();
  866. // create a mock message body to place th remoting message inside
  867. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  868. $request = new Zend_Amf_Request();
  869. // at the requested service to a request
  870. $request->addAmfBody($newBody);
  871. $request->setObjectEncoding(0x03);
  872. // let the server handle mock request
  873. $result = $this->_server->handle($request);
  874. $response = $this->_server->getResponse();
  875. $responseBody = $response->getAmfBodies();
  876. // Now check if the return data was properly set.
  877. $acknowledgeMessage = $responseBody[0]->getData();
  878. // check that we have a message beening returned
  879. $this->assertEquals(1, $acknowledgeMessage->body);
  880. // check that a header is being returned for the session id
  881. $headerBody = $response->getAmfHeaders();
  882. $this->assertEquals('AppendToGatewayUrl',$headerBody[0]->name);
  883. // Do not stop session since it still can be used by other tests
  884. // Zend_Session::stop();
  885. }
  886. public function testAddDirectory()
  887. {
  888. $this->_server->addDirectory(dirname(__FILE__)."/_files/services");
  889. $this->_server->addDirectory(dirname(__FILE__)."/_files/");
  890. $dirs = $this->_server->getDirectory();
  891. $this->assertContains(dirname(__FILE__)."/_files/services/", $dirs);
  892. $this->assertContains(dirname(__FILE__)."/_files/", $dirs);
  893. }
  894. public function testAddDirectoryService()
  895. {
  896. $this->_server->addDirectory(dirname(__FILE__)."/_files/services");
  897. // should take it from the path above, not include path
  898. set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__));
  899. // create a mock remoting message
  900. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  901. $message->operation = 'getMenu';
  902. $message->source = 'ServiceC';
  903. $message->body = array();
  904. // create a mock message body to place th remoting message inside
  905. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  906. $request = new Zend_Amf_Request();
  907. // at the requested service to a request
  908. $request->addAmfBody($newBody);
  909. $request->setObjectEncoding(0x03);
  910. // let the server handle mock request
  911. $this->_server->handle($request);
  912. $response = $this->_server->getResponse()->getAMFBodies();
  913. $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  914. $this->assertEquals("Service: MenuC", $response[0]->getData()->body);
  915. }
  916. public function testAddDirectoryService2()
  917. {
  918. $this->_server->addDirectory(dirname(__FILE__)."/_files/services");
  919. // create a mock remoting message
  920. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  921. $message->operation = 'getMenu';
  922. $message->source = 'My.ServiceA';
  923. $message->body = array();
  924. // create a mock message body to place th remoting message inside
  925. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  926. $request = new Zend_Amf_Request();
  927. // at the requested service to a request
  928. $request->addAmfBody($newBody);
  929. $request->setObjectEncoding(0x03);
  930. // let the server handle mock request
  931. $this->_server->handle($request);
  932. $response = $this->_server->getResponse()->getAMFBodies();
  933. $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
  934. $this->assertEquals("Service: myMenuA", $response[0]->getData()->body);
  935. }
  936. /*
  937. * See ZF-6625
  938. */
  939. public function testAddDirectoryServiceNotFound()
  940. {
  941. $this->_server->addDirectory(dirname(__FILE__)."/_files/services");
  942. // create a mock remoting message
  943. $message = new Zend_Amf_Value_Messaging_RemotingMessage();
  944. $message->operation = 'encode';
  945. $message->source = 'Zend_Json';
  946. $message->body = array("123");
  947. // create a mock message body to place th remoting message inside
  948. $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
  949. $request = new Zend_Amf_Request();
  950. // at the requested service to a request
  951. $request->addAmfBody($newBody);
  952. $request->setObjectEncoding(0x03);
  953. // let the server handle mock request
  954. $this->_server->handle($request);
  955. $response = $this->_server->getResponse()->getAMFBodies();
  956. $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_ErrorMessage);
  957. }
  958. }
  959. if (PHPUnit_MAIN_METHOD == "Zend_Amf_ServerTest::main") {
  960. Zend_Amf_ServerTest::main();
  961. }
  962. /**
  963. * Zend_Amf_Server_testFunction
  964. *
  965. * Function for use with Amf server unit tests
  966. *
  967. * @param array $var1
  968. * @param string $var2
  969. * @return string
  970. */
  971. function Zend_Amf_Server_testFunction($var1, $var2 = 'optional')
  972. {
  973. return $var2 . ': ' . implode(',', (array) $var1);
  974. }
  975. /**
  976. * Zend_Amf_Server_testFunction2
  977. *
  978. * Function for use with Amf server unit tests
  979. *
  980. * @return string
  981. */
  982. function Zend_Amf_Server_testFunction2()
  983. {
  984. return 'function2';
  985. }
  986. /**
  987. * Class to used with Zend_Amf_Server unit tests.
  988. *
  989. */
  990. class Zend_Amf_testclass
  991. {
  992. public function __construct()
  993. {
  994. }
  995. /**
  996. * Concatinate a string
  997. *
  998. * @param string
  999. * @return string
  1000. */
  1001. public function test1($string = '')
  1002. {
  1003. return 'String: '. (string) $string;
  1004. }
  1005. /**
  1006. * Test2
  1007. *
  1008. * Returns imploded array
  1009. *
  1010. * @param array $array
  1011. * @return string
  1012. */
  1013. public static function test2($array)
  1014. {
  1015. return implode('; ', (array) $array);
  1016. }
  1017. /**
  1018. * Test3
  1019. *
  1020. * Should not be available...
  1021. *
  1022. * @return void
  1023. */
  1024. protected function _test3()
  1025. {
  1026. }
  1027. /**
  1028. * Test base64 encoding in request and response
  1029. *
  1030. * @param base64 $data
  1031. * @return base64
  1032. */
  1033. public function base64($data)
  1034. {
  1035. return $data;
  1036. }
  1037. /**
  1038. * Test that invoke arguments are passed
  1039. *
  1040. * @param string $message message argument for comparisons
  1041. * @return string
  1042. */
  1043. public function checkArgv($message)
  1044. {
  1045. $argv = func_get_args();
  1046. return implode(':', $argv);
  1047. }
  1048. /**
  1049. * Test static usage
  1050. *
  1051. * @param string $message
  1052. * @return string
  1053. */
  1054. public static function checkStaticUsage($message)
  1055. {
  1056. return $message;
  1057. }
  1058. /**
  1059. * Test throwing exceptions
  1060. *
  1061. * @return void
  1062. */
  1063. public function throwException()
  1064. {
  1065. throw new Exception('This exception should not be displayed');
  1066. }
  1067. /**
  1068. * test if we can send an array as a paramater without it getting nested two
  1069. * Used to test ZF-5388
  1070. */
  1071. public function testSingleArrayParamater($inputArray){
  1072. if( $inputArray[0] == 'item1' ){
  1073. return true;
  1074. }
  1075. return false;
  1076. }
  1077. /**
  1078. * This will crash if two arrays are not passed into the function.
  1079. * Used to test ZF-5388
  1080. */
  1081. public function testMultiArrayParamater($arrayOne, $arrayTwo)
  1082. {
  1083. return array_merge($arrayOne, $arrayTwo);
  1084. }
  1085. }
  1086. /**
  1087. * Class with private constructor
  1088. */
  1089. class Zend_Amf_testclassPrivate
  1090. {
  1091. private function __construct()
  1092. {
  1093. }
  1094. /**
  1095. * Test1
  1096. *
  1097. * Returns 'String: ' . $string
  1098. *
  1099. * @param string $string
  1100. * @return string
  1101. */
  1102. public function test1($string = '')
  1103. {
  1104. return 'String: '. (string) $string;
  1105. }
  1106. }
  1107. /**
  1108. * Example class for sending a session back to ActionScript.
  1109. */
  1110. class Zend_Amf_testSession
  1111. {
  1112. /** Check if the session is available or create it. */
  1113. public function __construct() {
  1114. if (!isset($_SESSION['count'])) {
  1115. $_SESSION['count'] = 0;
  1116. }
  1117. }
  1118. /** increment the current count session variable and return it's value */
  1119. public function getCount()
  1120. {
  1121. $_SESSION['count']++;
  1122. return $_SESSION['count'];
  1123. }
  1124. }