ClientTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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_XmlRpc
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_XmlRpc_ClientTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_XmlRpc_ClientTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../TestHelper.php';
  27. require_once 'Zend/XmlRpc/Client.php';
  28. require_once 'Zend/XmlRpc/Response.php';
  29. require_once 'Zend/Http/Client/Adapter/Test.php';
  30. /**
  31. * Test case for Zend_XmlRpc_Value
  32. *
  33. * @category Zend
  34. * @package Zend_XmlRpc
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @group Zend_XmlRpc
  39. */
  40. class Zend_XmlRpc_ClientTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * @var Zend_Http_Client_Adapter_Abstract
  44. */
  45. protected $httpAdapter;
  46. /**
  47. * @var Zend_Http_Client
  48. */
  49. protected $httpClient;
  50. /**
  51. * @var Zend_XmlRpc_Client
  52. */
  53. protected $xmlrpcClient;
  54. /**
  55. * Runs the test methods of this class.
  56. *
  57. * @return void
  58. */
  59. public static function main()
  60. {
  61. $suite = new PHPUnit_Framework_TestSuite("Zend_XmlRpc_ClientTest");
  62. $result = PHPUnit_TextUI_TestRunner::run($suite);
  63. }
  64. public function setUp()
  65. {
  66. $this->httpAdapter = new Zend_Http_Client_Adapter_Test();
  67. $this->httpClient = new Zend_Http_Client('http://foo',
  68. array('adapter' => $this->httpAdapter));
  69. $this->xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
  70. $this->xmlrpcClient->setHttpClient($this->httpClient);
  71. }
  72. // HTTP Client
  73. public function testGettingDefaultHttpClient()
  74. {
  75. $xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
  76. $httpClient = $xmlrpcClient->getHttpClient();
  77. $this->assertType('Zend_Http_Client', $httpClient);
  78. $this->assertSame($httpClient, $xmlrpcClient->getHttpClient());
  79. }
  80. public function testSettingAndGettingHttpClient()
  81. {
  82. $xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
  83. $httpClient = new Zend_Http_Client('http://foo');
  84. $this->assertNotSame($httpClient, $xmlrpcClient->getHttpClient());
  85. $xmlrpcClient->setHttpClient($httpClient);
  86. $this->assertSame($httpClient, $xmlrpcClient->getHttpClient());
  87. }
  88. public function testSettingHttpClientViaContructor()
  89. {
  90. $xmlrpcClient = new Zend_XmlRpc_Client('http://foo', $this->httpClient);
  91. $httpClient = $xmlrpcClient->getHttpClient();
  92. $this->assertSame($this->httpClient, $httpClient);
  93. }
  94. // Request & Response
  95. public function testLastRequestAndResponseAreInitiallyNull()
  96. {
  97. $this->assertNull($this->xmlrpcClient->getLastRequest());
  98. $this->assertNull($this->xmlrpcClient->getLastResponse());
  99. }
  100. public function testLastRequestAndResponseAreSetAfterRpcMethodCall()
  101. {
  102. $this->setServerResponseTo(true);
  103. $this->xmlrpcClient->call('foo');
  104. $this->assertType('Zend_XmlRpc_Request', $this->xmlrpcClient->getLastRequest());
  105. $this->assertType('Zend_XmlRpc_Response', $this->xmlrpcClient->getLastResponse());
  106. }
  107. public function testSuccessfulRpcMethodCallWithNoParameters()
  108. {
  109. $expectedMethod = 'foo.bar';
  110. $expectedReturn = 7;
  111. $this->setServerResponseTo($expectedReturn);
  112. $this->assertSame($expectedReturn, $this->xmlrpcClient->call($expectedMethod));
  113. $request = $this->xmlrpcClient->getLastRequest();
  114. $response = $this->xmlrpcClient->getLastResponse();
  115. $this->assertSame($expectedMethod, $request->getMethod());
  116. $this->assertSame(array(), $request->getParams());
  117. $this->assertSame($expectedReturn, $response->getReturnValue());
  118. $this->assertFalse($response->isFault());
  119. }
  120. public function testSuccessfulRpcMethodCallWithParameters()
  121. {
  122. $expectedMethod = 'foo.bar';
  123. $expectedParams = array(1, 'foo' => 'bar', 1.1, true);
  124. $expectedReturn = array(7, false, 'foo' => 'bar');
  125. $this->setServerResponseTo($expectedReturn);
  126. $actualReturn = $this->xmlrpcClient->call($expectedMethod, $expectedParams);
  127. $this->assertSame($expectedReturn, $actualReturn);
  128. $request = $this->xmlrpcClient->getLastRequest();
  129. $response = $this->xmlrpcClient->getLastResponse();
  130. $this->assertSame($expectedMethod, $request->getMethod());
  131. $this->assertSame($expectedParams, $request->getParams());
  132. $this->assertSame($expectedReturn, $response->getReturnValue());
  133. $this->assertFalse($response->isFault());
  134. }
  135. /**
  136. * @see ZF-2090
  137. */
  138. public function testSuccessfullyDetectsEmptyArrayParameterAsArray()
  139. {
  140. $expectedMethod = 'foo.bar';
  141. $expectedParams = array(array());
  142. $expectedReturn = array(true);
  143. $this->setServerResponseTo($expectedReturn);
  144. $actualReturn = $this->xmlrpcClient->call($expectedMethod, $expectedParams);
  145. $this->assertSame($expectedReturn, $actualReturn);
  146. $request = $this->xmlrpcClient->getLastRequest();
  147. $this->assertSame($expectedParams, $request->getParams());
  148. }
  149. /**
  150. * Test for ZF-1412
  151. *
  152. * @return void
  153. */
  154. public function testSuccessfulRpcMethodCallWithMixedDateParameters()
  155. {
  156. $time = time();
  157. $expectedMethod = 'foo.bar';
  158. $expectedParams = array(
  159. 'username',
  160. new Zend_XmlRpc_Value_DateTime($time)
  161. );
  162. $expectedReturn = array('username', $time);
  163. $this->setServerResponseTo($expectedReturn);
  164. $actualReturn = $this->xmlrpcClient->call($expectedMethod, $expectedParams);
  165. $this->assertSame($expectedReturn, $actualReturn);
  166. $request = $this->xmlrpcClient->getLastRequest();
  167. $response = $this->xmlrpcClient->getLastResponse();
  168. $this->assertSame($expectedMethod, $request->getMethod());
  169. $this->assertSame($expectedParams, $request->getParams());
  170. $this->assertSame($expectedReturn, $response->getReturnValue());
  171. $this->assertFalse($response->isFault());
  172. }
  173. /**
  174. * @see ZF-1797
  175. */
  176. public function testSuccesfulRpcMethodCallWithXmlRpcValueParameters()
  177. {
  178. $time = time();
  179. $params = array(
  180. new Zend_XmlRpc_Value_Boolean(true),
  181. new Zend_XmlRpc_Value_Integer(4),
  182. new Zend_XmlRpc_Value_String('foo')
  183. );
  184. $expect = array(true, 4, 'foo');
  185. $this->setServerResponseTo($expect);
  186. $result = $this->xmlrpcClient->call('foo.bar', $params);
  187. $this->assertSame($expect, $result);
  188. $request = $this->xmlrpcClient->getLastRequest();
  189. $response = $this->xmlrpcClient->getLastResponse();
  190. $this->assertSame('foo.bar', $request->getMethod());
  191. $this->assertSame($params, $request->getParams());
  192. $this->assertSame($expect, $response->getReturnValue());
  193. $this->assertFalse($response->isFault());
  194. }
  195. /**#@+
  196. * @see ZF-2978
  197. */
  198. public function testSkippingSystemCallDisabledByDefault()
  199. {
  200. $this->assertFalse($this->xmlrpcClient->skipSystemLookup());
  201. }
  202. public function testAllowsSkippingSystemCallForArrayStructLookup()
  203. {
  204. $this->xmlrpcClient->setSkipSystemLookup(true);
  205. $this->assertTrue($this->xmlrpcClient->skipSystemLookup());
  206. }
  207. public function testSkipsSystemCallWhenDirected()
  208. {
  209. $this->markTestIncomplete('Cannot complete this test until we add logging of requests sent to HTTP test client');
  210. }
  211. /**#@-*/
  212. // Faults
  213. public function testRpcMethodCallThrowsOnHttpFailure()
  214. {
  215. $status = 404;
  216. $message = 'Not Found';
  217. $body = 'oops';
  218. $response = $this->makeHttpResponseFrom($body, $status, $message);
  219. $this->httpAdapter->setResponse($response);
  220. try {
  221. $this->xmlrpcClient->call('foo');
  222. $this->fail();
  223. } catch (Exception $e) {
  224. $this->assertType('Zend_XmlRpc_Client_HttpException', $e);
  225. $this->assertEquals($message, $e->getMessage());
  226. $this->assertEquals($status, $e->getCode());
  227. }
  228. }
  229. public function testRpcMethodCallThrowsOnXmlRpcFault()
  230. {
  231. $code = 9;
  232. $message = 'foo';
  233. $fault = new Zend_XmlRpc_Fault($code, $message);
  234. $xml = $fault->saveXML();
  235. $response = $this->makeHttpResponseFrom($xml);
  236. $this->httpAdapter->setResponse($response);
  237. try {
  238. $this->xmlrpcClient->call('foo');
  239. $this->fail();
  240. } catch (Exception $e) {
  241. $this->assertType('Zend_XmlRpc_Client_FaultException', $e);
  242. $this->assertEquals($message, $e->getMessage());
  243. $this->assertEquals($code, $e->getCode());
  244. }
  245. }
  246. // Server Proxy
  247. public function testGetProxyReturnsServerProxy()
  248. {
  249. $class = 'Zend_XmlRpc_Client_ServerProxy';
  250. $this->assertType($class, $this->xmlrpcClient->getProxy());
  251. }
  252. public function testRpcMethodCallsThroughServerProxy()
  253. {
  254. $expectedReturn = array(7, false, 'foo' => 'bar');
  255. $this->setServerResponseTo($expectedReturn);
  256. $server = $this->xmlrpcClient->getProxy();
  257. $this->assertSame($expectedReturn, $server->listMethods());
  258. $request = $this->xmlrpcClient->getLastRequest();
  259. $this->assertEquals('listMethods', $request->getMethod());
  260. }
  261. public function testRpcMethodCallsThroughNestedServerProxies()
  262. {
  263. $expectedReturn = array(7, false, 'foo' => 'bar');
  264. $this->setServerResponseTo($expectedReturn);
  265. $server = $this->xmlrpcClient->getProxy('foo');
  266. $this->assertSame($expectedReturn, $server->bar->baz->boo());
  267. $request = $this->xmlrpcClient->getLastRequest();
  268. $this->assertEquals('foo.bar.baz.boo', $request->getMethod());
  269. }
  270. public function testClientCachesServerProxies()
  271. {
  272. $proxy = $this->xmlrpcClient->getProxy();
  273. $this->assertSame($proxy, $this->xmlrpcClient->getProxy());
  274. $proxy = $this->xmlrpcClient->getProxy('foo');
  275. $this->assertSame($proxy, $this->xmlrpcClient->getProxy('foo'));
  276. }
  277. public function testServerProxyCachesNestedProxies()
  278. {
  279. $proxy = $this->xmlrpcClient->getProxy();
  280. $foo = $proxy->foo;
  281. $this->assertSame($foo, $proxy->foo);
  282. $bar = $proxy->foo->bar;
  283. $this->assertSame($bar, $proxy->foo->bar);
  284. }
  285. // Introspection
  286. public function testGettingDefaultIntrospector()
  287. {
  288. $xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
  289. $introspector = $xmlrpcClient->getIntrospector();
  290. $this->assertType('Zend_XmlRpc_Client_ServerIntrospection', $introspector);
  291. $this->assertSame($introspector, $xmlrpcClient->getIntrospector());
  292. }
  293. public function testSettingAndGettingIntrospector()
  294. {
  295. $xmlrpcClient = new Zend_XmlRpc_Client('http://foo');
  296. $introspector = new Zend_XmlRpc_Client_ServerIntrospection($xmlrpcClient);
  297. $this->assertNotSame($introspector, $xmlrpcClient->getIntrospector());
  298. $xmlrpcClient->setIntrospector($introspector);
  299. $this->assertSame($introspector, $xmlrpcClient->getIntrospector());
  300. }
  301. public function testGettingMethodSignature()
  302. {
  303. $method = 'foo';
  304. $signatures = array(array('int', 'int', 'int'));
  305. $this->setServerResponseTo($signatures);
  306. $i = $this->xmlrpcClient->getIntrospector();
  307. $this->assertEquals($signatures, $i->getMethodSignature($method));
  308. $request = $this->xmlrpcClient->getLastRequest();
  309. $this->assertEquals('system.methodSignature', $request->getMethod());
  310. $this->assertEquals(array($method), $request->getParams());
  311. }
  312. public function testListingMethods()
  313. {
  314. $methods = array('foo', 'bar', 'baz');
  315. $this->setServerResponseTo($methods);
  316. $i = $this->xmlrpcClient->getIntrospector();
  317. $this->assertEquals($methods, $i->listMethods());
  318. $request = $this->xmlrpcClient->getLastRequest();
  319. $this->assertEquals('system.listMethods', $request->getMethod());
  320. $this->assertEquals(array(), $request->getParams());
  321. }
  322. public function testGettingAllMethodSignaturesByLooping()
  323. {
  324. // system.listMethods() will return ['foo', 'bar']
  325. $methods = array('foo', 'bar');
  326. $response = $this->getServerResponseFor($methods);
  327. $this->httpAdapter->setResponse($response);
  328. // system.methodSignature('foo') will return [['int'], ['int', 'string']]
  329. $fooSignatures = array(array('int'), array('int', 'string'));
  330. $response = $this->getServerResponseFor($fooSignatures);
  331. $this->httpAdapter->addResponse($response);
  332. // system.methodSignature('bar') will return [['boolean']]
  333. $barSignatures = array(array('boolean'));
  334. $response = $this->getServerResponseFor($barSignatures);
  335. $this->httpAdapter->addResponse($response);
  336. $expected = array('foo' => $fooSignatures,
  337. 'bar' => $barSignatures);
  338. $i = $this->xmlrpcClient->getIntrospector();
  339. $this->assertEquals($expected, $i->getSignatureForEachMethodByLooping());
  340. $request = $this->xmlrpcClient->getLastRequest();
  341. $this->assertEquals('system.methodSignature', $request->getMethod());
  342. $this->assertEquals(array('bar'), $request->getParams());
  343. }
  344. public function testGettingAllMethodSignaturesByMulticall()
  345. {
  346. // system.listMethods() will return ['foo', 'bar']
  347. $whatListMethodsReturns = array('foo', 'bar');
  348. $response = $this->getServerResponseFor($whatListMethodsReturns);
  349. $this->httpAdapter->setResponse($response);
  350. // after system.listMethods(), these system.multicall() params are expected
  351. $multicallParams = array(array('methodName' => 'system.methodSignature',
  352. 'params' => array('foo')),
  353. array('methodName' => 'system.methodSignature',
  354. 'params' => array('bar')));
  355. // system.multicall() will then return [fooSignatures, barSignatures]
  356. $fooSignatures = array(array('int'), array('int', 'string'));
  357. $barSignatures = array(array('boolean'));
  358. $whatMulticallReturns = array($fooSignatures, $barSignatures);
  359. $response = $this->getServerResponseFor($whatMulticallReturns);
  360. $this->httpAdapter->addResponse($response);
  361. $i = $this->xmlrpcClient->getIntrospector();
  362. $expected = array('foo' => $fooSignatures,
  363. 'bar' => $barSignatures);
  364. $this->assertEquals($expected, $i->getSignatureForEachMethodByMulticall());
  365. $request = $this->xmlrpcClient->getLastRequest();
  366. $this->assertEquals('system.multicall', $request->getMethod());
  367. $this->assertEquals(array($multicallParams), $request->getParams());
  368. }
  369. public function testGettingAllMethodSignaturesByMulticallThrowsOnBadCount()
  370. {
  371. // system.listMethods() will return ['foo', 'bar']
  372. $whatListMethodsReturns = array('foo', 'bar');
  373. $response = $this->getServerResponseFor($whatListMethodsReturns);
  374. $this->httpAdapter->setResponse($response);
  375. // system.multicall() will then return only [fooSignatures]
  376. $fooSignatures = array(array('int'), array('int', 'string'));
  377. $whatMulticallReturns = array($fooSignatures); // error! no bar signatures!
  378. $response = $this->getServerResponseFor($whatMulticallReturns);
  379. $this->httpAdapter->addResponse($response);
  380. $i = $this->xmlrpcClient->getIntrospector();
  381. try {
  382. $i->getSignatureForEachMethodByMulticall();
  383. } catch (Zend_XmlRpc_Client_IntrospectException $e) {
  384. $this->assertRegexp('/bad number/i', $e->getMessage());
  385. }
  386. }
  387. public function testGettingAllMethodSignaturesByMulticallThrowsOnBadType()
  388. {
  389. // system.listMethods() will return ['foo', 'bar']
  390. $whatListMethodsReturns = array('foo', 'bar');
  391. $response = $this->getServerResponseFor($whatListMethodsReturns);
  392. $this->httpAdapter->setResponse($response);
  393. // system.multicall() will then return only an int
  394. $whatMulticallReturns = 1; // error! no signatures?
  395. $response = $this->getServerResponseFor($whatMulticallReturns);
  396. $this->httpAdapter->addResponse($response);
  397. $i = $this->xmlrpcClient->getIntrospector();
  398. try {
  399. $i->getSignatureForEachMethodByMulticall();
  400. } catch (Zend_XmlRpc_Client_IntrospectException $e) {
  401. $this->assertRegexp('/got integer/i', $e->getMessage());
  402. }
  403. }
  404. public function testGettingAllMethodSignaturesDefaultsToMulticall()
  405. {
  406. // system.listMethods() will return ['foo', 'bar']
  407. $whatListMethodsReturns = array('foo', 'bar');
  408. $response = $this->getServerResponseFor($whatListMethodsReturns);
  409. $this->httpAdapter->setResponse($response);
  410. // system.multicall() will then return [fooSignatures, barSignatures]
  411. $fooSignatures = array(array('int'), array('int', 'string'));
  412. $barSignatures = array(array('boolean'));
  413. $whatMulticallReturns = array($fooSignatures, $barSignatures);
  414. $response = $this->getServerResponseFor($whatMulticallReturns);
  415. $this->httpAdapter->addResponse($response);
  416. $i = $this->xmlrpcClient->getIntrospector();
  417. $expected = array('foo' => $fooSignatures,
  418. 'bar' => $barSignatures);
  419. $this->assertEquals($expected, $i->getSignatureForEachMethod());
  420. $request = $this->xmlrpcClient->getLastRequest();
  421. $this->assertEquals('system.multicall', $request->getMethod());
  422. }
  423. public function testGettingAllMethodSignaturesDegradesToLooping()
  424. {
  425. // system.listMethods() will return ['foo', 'bar']
  426. $whatListMethodsReturns = array('foo', 'bar');
  427. $response = $this->getServerResponseFor($whatListMethodsReturns);
  428. $this->httpAdapter->setResponse($response);
  429. // system.multicall() will return a fault
  430. $fault = new Zend_XmlRpc_Fault(7, 'bad method');
  431. $xml = $fault->saveXML();
  432. $response = $this->makeHttpResponseFrom($xml);
  433. $this->httpAdapter->addResponse($response);
  434. // system.methodSignature('foo') will return [['int'], ['int', 'string']]
  435. $fooSignatures = array(array('int'), array('int', 'string'));
  436. $response = $this->getServerResponseFor($fooSignatures);
  437. $this->httpAdapter->addResponse($response);
  438. // system.methodSignature('bar') will return [['boolean']]
  439. $barSignatures = array(array('boolean'));
  440. $response = $this->getServerResponseFor($barSignatures);
  441. $this->httpAdapter->addResponse($response);
  442. $i = $this->xmlrpcClient->getIntrospector();
  443. $expected = array('foo' => $fooSignatures,
  444. 'bar' => $barSignatures);
  445. $this->assertEquals($expected, $i->getSignatureForEachMethod());
  446. $request = $this->xmlrpcClient->getLastRequest();
  447. $this->assertEquals('system.methodSignature', $request->getMethod());
  448. }
  449. /**
  450. * @group ZF-4372
  451. */
  452. public function testSettingUriOnHttpClientIsNotOverwrittenByXmlRpcClient()
  453. {
  454. $changedUri = "http://bar:80";
  455. // Overwrite: http://foo:80
  456. $this->setServerResponseTo(array());
  457. $this->xmlrpcClient->getHttpClient()->setUri($changedUri);
  458. $this->xmlrpcClient->call("foo");
  459. $uri = $this->xmlrpcClient->getHttpClient()->getUri(true);
  460. $this->assertEquals($changedUri, $uri);
  461. }
  462. /**
  463. * @group ZF-4372
  464. */
  465. public function testSettingNoHttpClientUriForcesClientToSetUri()
  466. {
  467. $baseUri = "http://foo:80";
  468. $this->httpAdapter = new Zend_Http_Client_Adapter_Test();
  469. $this->httpClient = new Zend_Http_Client(null, array('adapter' => $this->httpAdapter));
  470. $this->xmlrpcClient = new Zend_XmlRpc_Client($baseUri);
  471. $this->xmlrpcClient->setHttpClient($this->httpClient);
  472. $this->setServerResponseTo(array());
  473. $this->assertNull($this->xmlrpcClient->getHttpClient()->getUri());
  474. $this->xmlrpcClient->call("foo");
  475. $uri = $this->xmlrpcClient->getHttpClient()->getUri(true);
  476. $this->assertEquals($baseUri, $uri);
  477. }
  478. // Helpers
  479. public function setServerResponseTo($nativeVars)
  480. {
  481. $response = $this->getServerResponseFor($nativeVars);
  482. $this->httpAdapter->setResponse($response);
  483. }
  484. public function getServerResponseFor($nativeVars)
  485. {
  486. $response = new Zend_XmlRpc_Response();
  487. $response->setReturnValue($nativeVars);
  488. $xml = $response->saveXML();
  489. $response = $this->makeHttpResponseFrom($xml);
  490. return $response;
  491. }
  492. public function makeHttpResponseFrom($data, $status=200, $message='OK')
  493. {
  494. $headers = array("HTTP/1.1 $status $message",
  495. "Status: $status",
  496. 'Content_Type: text/xml; charset=utf-8',
  497. 'Content-Length: ' . strlen($data)
  498. );
  499. return implode("\r\n", $headers) . "\r\n\r\n$data\r\n\r\n";
  500. }
  501. }
  502. // Call Zend_XmlRpc_ClientTest::main() if this source file is executed directly.
  503. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_ClientTest::main") {
  504. Zend_XmlRpc_ClientTest::main();
  505. }