2
0

BaseProxy.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /**
  23. * @see Zend_Service_Simpy
  24. */
  25. require_once 'Zend/Service/Simpy.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service_Simpy
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. abstract class Zend_Service_Simpy_BaseProxy
  34. {
  35. /**
  36. * Simpy service consumer
  37. *
  38. * @var Zend_Service_Simpy
  39. */
  40. protected $_simpy;
  41. /**
  42. * Name of the current test case being executed
  43. *
  44. * @var string
  45. */
  46. protected $_test;
  47. /**
  48. * Mapping of methods to the number of calls made per method for the
  49. * current test case being executed
  50. *
  51. * @var array
  52. */
  53. protected $_calls;
  54. /**
  55. * Constructor to initialize the service consumer.
  56. *
  57. * @param string $test Name of the test case currently being executed
  58. * @return void
  59. */
  60. public final function __construct($test)
  61. {
  62. $this->_test = $test;
  63. $this->_calls = array();
  64. if (defined('TESTS_ZEND_SERVICE_SIMPY_USERNAME')) {
  65. $username = TESTS_ZEND_SERVICE_SIMPY_USERNAME;
  66. $password = TESTS_ZEND_SERVICE_SIMPY_PASSWORD;
  67. } else {
  68. $username = null;
  69. $password = null;
  70. }
  71. $this->_simpy = new Zend_Service_Simpy($username, $password);
  72. $this->init();
  73. }
  74. /**
  75. * Initialize method to be overridden in subclasses if needed.
  76. *
  77. * @return void
  78. */
  79. public function init()
  80. {
  81. }
  82. /**
  83. * Returns the path to the file intended to contain the service consumer
  84. * response for the current method call.
  85. *
  86. * @param string $name Name of the method being called
  87. * @return string File path
  88. */
  89. protected function _getFilePath($name)
  90. {
  91. if (!isset($this->_calls[$name])) {
  92. $this->_calls[$name] = 0;
  93. }
  94. $this->_calls[$name]++;
  95. $dir = dirname(__FILE__) . '/_files/';
  96. $file = $this->_test . '_' . $name . '_' . $this->_calls[$name];
  97. return $dir . $file;
  98. }
  99. }