TestCase.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /**
  3. * This file is part of the DigitalOcean library.
  4. *
  5. * (c) Antoine Corcy <contact@sbin.dk>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace DigitalOcean\Tests;
  11. /**
  12. * @author Antoine Corcy <contact@sbin.dk>
  13. */
  14. class TestCase extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @return HttpAdapterInterface
  18. */
  19. protected function getMockAdapter($expects = null)
  20. {
  21. if (null === $expects) {
  22. $expects = $this->once();
  23. }
  24. $mock = $this->getMock('\HttpAdapter\HttpAdapterInterface');
  25. $mock
  26. ->expects($expects)
  27. ->method('getContent')
  28. ->will($this->returnArgument(0));
  29. return $mock;
  30. }
  31. /**
  32. * @return HttpAdapterInterface
  33. */
  34. protected function getMockAdapterReturns($returnValue)
  35. {
  36. $mock = $this->getMock('\HttpAdapter\HttpAdapterInterface');
  37. $mock
  38. ->expects($this->once())
  39. ->method('getContent')
  40. ->will($this->returnValue($returnValue));
  41. return $mock;
  42. }
  43. /**
  44. * @return Crendentials
  45. */
  46. protected function getMockCredentials($expects = null)
  47. {
  48. if (null === $expects) {
  49. $expects = $this->atLeastOnce();
  50. }
  51. $mock = $this
  52. ->getMockBuilder('\DigitalOcean\Credentials')
  53. ->disableOriginalConstructor()
  54. ->getMock();
  55. $mock
  56. ->expects($expects)
  57. ->method('getClientId')
  58. ->will($this->returnValue('foo'));
  59. $mock
  60. ->expects($expects)
  61. ->method('getApiKey')
  62. ->will($this->returnValue('bar'));
  63. return $mock;
  64. }
  65. /**
  66. * @return DigitalOcean
  67. */
  68. protected function getMockDigitalOcean($method, $returnValue)
  69. {
  70. $mock = $this->getMockBuilder('\DigitalOcean\DigitalOcean')
  71. ->disableOriginalConstructor()
  72. ->getMock();
  73. $mock
  74. ->expects($this->any())
  75. ->method($method)
  76. ->will($this->returnValue($returnValue));
  77. return $mock;
  78. }
  79. /**
  80. * @return Droplets
  81. */
  82. protected function getMockDroplets($method, $returnValue)
  83. {
  84. $mock = $this->getMockBuilder('\DigitalOcean\Droplets\Droplets')
  85. ->disableOriginalConstructor()
  86. ->getMock();
  87. $mock
  88. ->expects($this->any())
  89. ->method($method)
  90. ->will($this->returnValue($returnValue));
  91. return $mock;
  92. }
  93. /**
  94. * @return Images
  95. */
  96. protected function getMockImages($method, $returnValue)
  97. {
  98. $mock = $this->getMockBuilder('\DigitalOcean\Images\Images')
  99. ->disableOriginalConstructor()
  100. ->getMock();
  101. $mock
  102. ->expects($this->any())
  103. ->method($method)
  104. ->will($this->returnValue($returnValue));
  105. return $mock;
  106. }
  107. /**
  108. * @return Regions
  109. */
  110. protected function getMockRegions($returnValue)
  111. {
  112. $mock = $this->getMockBuilder('\DigitalOcean\Regions\Regions')
  113. ->disableOriginalConstructor()
  114. ->getMock();
  115. $mock
  116. ->expects($this->once())
  117. ->method('getAll')
  118. ->will($this->returnValue($returnValue));
  119. return $mock;
  120. }
  121. /**
  122. * @return Sizes
  123. */
  124. protected function getMockSizes($returnValue)
  125. {
  126. $mock = $this->getMockBuilder('\DigitalOcean\Sizes\Sizes')
  127. ->disableOriginalConstructor()
  128. ->getMock();
  129. $mock
  130. ->expects($this->once())
  131. ->method('getAll')
  132. ->will($this->returnValue($returnValue));
  133. return $mock;
  134. }
  135. /**
  136. * @return SSHKeys
  137. */
  138. protected function getMockSSHKeys($method, $returnValue)
  139. {
  140. $mock = $this->getMockBuilder('\DigitalOcean\SSHKeys\SSHKeys')
  141. ->disableOriginalConstructor()
  142. ->getMock();
  143. $mock
  144. ->expects($this->any())
  145. ->method($method)
  146. ->will($this->returnValue($returnValue));
  147. return $mock;
  148. }
  149. /**
  150. * @return Domains
  151. */
  152. protected function getMockDomains($method, $returnValue)
  153. {
  154. $mock = $this->getMockBuilder('\DigitalOcean\Domains\Domains')
  155. ->disableOriginalConstructor()
  156. ->getMock();
  157. $mock
  158. ->expects($this->any())
  159. ->method($method)
  160. ->will($this->returnValue($returnValue));
  161. return $mock;
  162. }
  163. /**
  164. * @return DialogHelper
  165. */
  166. protected function getDialogAskConfirmation($returnValue)
  167. {
  168. $mock = $this->getMock('\Symfony\Component\Console\Helper\DialogHelper', array('askConfirmation'));
  169. $mock
  170. ->expects($this->at(0))
  171. ->method('askConfirmation')
  172. ->will($this->returnValue($returnValue));
  173. return $mock;
  174. }
  175. /**
  176. * @return DialogHelper
  177. */
  178. protected function getDialogAsk($returnValue)
  179. {
  180. $mock = $this->getMock('\Symfony\Component\Console\Helper\DialogHelper', array('ask'));
  181. $mock
  182. ->expects($this->once())
  183. ->method('ask')
  184. ->will($this->returnValue($returnValue));
  185. return $mock;
  186. }
  187. }