OfflineProxy.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_Service_Simpy
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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. require_once 'BaseProxy.php';
  23. /**
  24. * @see Zend_Http_Client_Adapter_Test
  25. */
  26. require_once 'Zend/Http/Client/Adapter/Test.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_Service_Simpy
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Service_Simpy_OfflineProxy extends Zend_Service_Simpy_BaseProxy
  35. {
  36. /**
  37. * Test adapter, stored because Zend_Http_Client provides no accessor
  38. * method or public property for it
  39. *
  40. * @var Zend_Http_Client_Adapter
  41. */
  42. protected $_adapter;
  43. /**
  44. * Initialize the HTTP client test adapter.
  45. *
  46. * @return void
  47. */
  48. public function init()
  49. {
  50. $this->_adapter = new Zend_Http_Client_Adapter_Test;
  51. $this->_simpy->getHttpClient()->setAdapter($this->_adapter);
  52. }
  53. /**
  54. * Proxy all method calls to the service consumer object using a test
  55. * HTTP client adapter and reading responses from local files.
  56. *
  57. * @param string $name Name of the method called
  58. * @param array $args Arguments passed in the method call
  59. * @return mixed Return value of the called method
  60. */
  61. public function __call($name, array $args)
  62. {
  63. $file = $this->_getFilePath($name);
  64. $body = file_get_contents($file);
  65. $this->_adapter->setResponse(
  66. 'HTTP/1.1 200 OK' . "\r\n" .
  67. 'Content-Type: text/xml' . "\r\n" .
  68. "\r\n" .
  69. $body
  70. );
  71. $return = call_user_func_array(
  72. array($this->_simpy, $name),
  73. $args
  74. );
  75. return $return;
  76. }
  77. }