DropboxSpec.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. namespace spec\Gaufrette\Adapter;
  3. use Dropbox_API;
  4. use PhpSpec\ObjectBehavior;
  5. use Prophecy\Argument;
  6. class DropboxSpec extends ObjectBehavior
  7. {
  8. /**
  9. * @param \Dropbox_API $dropbox
  10. */
  11. function let(Dropbox_API $dropbox)
  12. {
  13. $this->beConstructedWith($dropbox);
  14. }
  15. function it_is_adapter()
  16. {
  17. $this->shouldHaveType('Gaufrette\Adapter');
  18. }
  19. /**
  20. * @param \Dropbox_API $dropbox
  21. */
  22. function it_reads_file(Dropbox_API $dropbox)
  23. {
  24. $dropbox->getFile('filename')->willReturn('some content');
  25. $this->read('filename')->shouldReturn('some content');
  26. }
  27. /**
  28. * @param \Dropbox_API $dropbox
  29. */
  30. function it_does_not_mask_exception_from_client_during_read(Dropbox_API $dropbox)
  31. {
  32. $dropbox->getFile('filename')->willThrow(new \RuntimeException('read'));
  33. $this->shouldThrow(new \RuntimeException('read'))->duringRead('filename');
  34. }
  35. /**
  36. * @param \Dropbox_API $dropbox
  37. */
  38. function it_does_not_read_file(Dropbox_API $dropbox)
  39. {
  40. $dropbox
  41. ->getFile('filename')
  42. ->willThrow(new \Dropbox_Exception_NotFound());
  43. $this->read('filename')->shouldReturn(false);
  44. }
  45. /**
  46. * @param \Dropbox_API $dropbox
  47. */
  48. function it_checks_if_file_exists(Dropbox_API $dropbox)
  49. {
  50. $dropbox
  51. ->getMetaData('filename', false)
  52. ->willReturn(array(
  53. "size" => "225.4KB",
  54. "rev" => "35e97029684fe",
  55. "thumb_exists" => false,
  56. "bytes" => 230783,
  57. "modified" => "Tue, 19 Jul 2011 21:55:38 +0000",
  58. "client_mtime" => "Mon, 18 Jul 2011 18:04:35 +0000",
  59. "path" => "/filename",
  60. "is_dir" => false,
  61. "icon" => "page_white_acrobat",
  62. "root" => "dropbox",
  63. "mime_type" => "application/pdf",
  64. "revision" => 220823
  65. ));
  66. $this->exists('filename')->shouldReturn(true);
  67. $dropbox
  68. ->getMetaData('filename', false)
  69. ->willThrow(new \Dropbox_Exception_NotFound);
  70. $this->exists('filename')->shouldReturn(false);
  71. $dropbox
  72. ->getMetaData('filename', false)
  73. ->willReturn(array("is_deleted" => true));
  74. $this->exists('filename')->shouldReturn(false);
  75. }
  76. /**
  77. * @param \Dropbox_API $dropbox
  78. */
  79. function it_does_not_mask_exception_from_client_during_check_if_exists(Dropbox_API $dropbox)
  80. {
  81. $dropbox
  82. ->getMetaData('filename', false)
  83. ->willThrow(new \RuntimeException('exists'));
  84. $this->shouldThrow(new \RuntimeException('exists'))->duringExists('filename');
  85. }
  86. /**
  87. * @param \Dropbox_API $dropbox
  88. */
  89. function it_gets_keys(Dropbox_API $dropbox)
  90. {
  91. $dropbox
  92. ->getMetaData('/', true)
  93. ->willReturn(array(
  94. 'contents' => array(
  95. array('path' => '/filename'),
  96. array('path' => '/aaa/filename')
  97. )
  98. ));
  99. $this->keys()->shouldReturn(array('aaa', 'aaa/filename', 'filename'));
  100. }
  101. /**
  102. * @param \Dropbox_API $dropbox
  103. */
  104. function it_does_not_mask_exception_from_client_during_getting_keys(Dropbox_API $dropbox)
  105. {
  106. $dropbox
  107. ->getMetaData('/', true)
  108. ->willThrow(new \RuntimeException('keys'))
  109. ;
  110. $this->shouldThrow(new \RuntimeException('keys'))->duringKeys();
  111. }
  112. /**
  113. * @param \Dropbox_API $dropbox
  114. */
  115. function it_checks_if_given_key_is_directory(Dropbox_API $dropbox)
  116. {
  117. $dropbox
  118. ->getMetaData('filename', false)
  119. ->willReturn(array(
  120. "is_dir" => true
  121. ))
  122. ;
  123. $this->isDirectory('filename')->shouldReturn(true);
  124. $dropbox
  125. ->getMetaData('filename', false)
  126. ->willReturn(array(
  127. "is_dir" => false
  128. ));
  129. $this->isDirectory('filename')->shouldReturn(false);
  130. }
  131. /**
  132. * @param \Dropbox_API $dropbox
  133. */
  134. function it_writes_file(Dropbox_API $dropbox)
  135. {
  136. $dropbox
  137. ->putFile('filename', Argument::any())
  138. ->shouldBeCalled()
  139. ;
  140. $this->write('filename', 'some content')->shouldReturn(12);
  141. }
  142. /**
  143. * @param \Dropbox_API $dropbox
  144. */
  145. function it_does_not_mask_exception_from_client_during_write(Dropbox_API $dropbox)
  146. {
  147. $dropbox
  148. ->putFile('filename', Argument::any())
  149. ->willThrow(new \RuntimeException('write'))
  150. ;
  151. $this->shouldThrow(new \RuntimeException('write'))->duringWrite('filename', 'some content');
  152. }
  153. /**
  154. * @param \Dropbox_API $dropbox
  155. */
  156. function it_deletes_file(Dropbox_API $dropbox)
  157. {
  158. $dropbox
  159. ->delete('filename')
  160. ->shouldBeCalled()
  161. ;
  162. $this->delete('filename')->shouldReturn(true);
  163. }
  164. /**
  165. * @param \Dropbox_API $dropbox
  166. */
  167. function it_does_not_delete_file(Dropbox_API $dropbox)
  168. {
  169. $dropbox
  170. ->delete('filename')
  171. ->willThrow(new \Dropbox_Exception_NotFound())
  172. ;
  173. $this->delete('filename')->shouldReturn(false);
  174. }
  175. /**
  176. * @param \Dropbox_API $dropbox
  177. */
  178. function it_renames_file(Dropbox_API $dropbox)
  179. {
  180. $dropbox
  181. ->move('filename', 'filename2')
  182. ->shouldBeCalled()
  183. ;
  184. $this->rename('filename', 'filename2')->shouldReturn(true);
  185. }
  186. /**
  187. * @param \Dropbox_API $dropbox
  188. */
  189. function it_does_not_rename_file(Dropbox_API $dropbox)
  190. {
  191. $dropbox
  192. ->move('filename', 'filename2')
  193. ->willThrow(new \Dropbox_Exception_NotFound())
  194. ;
  195. $this->rename('filename', 'filename2')->shouldReturn(false);
  196. }
  197. /**
  198. * @param \Dropbox_API $dropbox
  199. */
  200. function it_fetches_mtime(Dropbox_API $dropbox)
  201. {
  202. $dropbox
  203. ->getMetaData('filename', false)
  204. ->willReturn(array(
  205. "modified" => "Tue, 19 Jul 2011 21:55:38 +0000",
  206. ))
  207. ;
  208. $this->mtime('filename')->shouldReturn(1311112538);
  209. }
  210. /**
  211. * @param \Dropbox_API $dropbox
  212. */
  213. function it_does_not_fetch_mtime_when_file_not_found(Dropbox_API $dropbox)
  214. {
  215. $dropbox
  216. ->getMetaData('filename', false)
  217. ->willThrow(new \Dropbox_Exception_NotFound())
  218. ;
  219. $this->mtime('filename')->shouldReturn(false);
  220. }
  221. /**
  222. * @param \Dropbox_API $dropbox
  223. */
  224. function it_does_not_check_if_key_is_dir_when_file_not_found(Dropbox_API $dropbox)
  225. {
  226. $dropbox
  227. ->getMetaData('filename', false)
  228. ->willThrow(new \Dropbox_Exception_NotFound())
  229. ;
  230. $this->isDirectory('filename')->shouldReturn(false);
  231. }
  232. /**
  233. * @param \Dropbox_API $dropbox
  234. */
  235. function it_fails_checking_if_key_is_dir_when_dropbox_throws_exception(Dropbox_API $dropbox)
  236. {
  237. $dropbox
  238. ->getMetaData('filename', false)
  239. ->willThrow(new \RuntimeException('some exception'))
  240. ;
  241. $this->shouldThrow(new \RuntimeException('some exception'))->duringIsDirectory('filename');
  242. }
  243. }