DropboxSpec.php 7.1 KB

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