RackspaceCloudfilesSpec.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. namespace spec\Gaufrette\Adapter;
  3. use PhpSpec\ObjectBehavior;
  4. class RackspaceCloudfilesSpec extends ObjectBehavior
  5. {
  6. /**
  7. * @param \CF_Container $container
  8. */
  9. function let($container)
  10. {
  11. $this->beConstructedWith($container);
  12. }
  13. function it_is_adapter()
  14. {
  15. $this->shouldHaveType('Gaufrette\Adapter');
  16. }
  17. function it_is_checksum_calculator()
  18. {
  19. $this->shouldHaveType('Gaufrette\Adapter\ChecksumCalculator');
  20. }
  21. /**
  22. * @param \CF_Container $container
  23. * @param \CF_Object $object
  24. */
  25. function it_reads_file($container, $object)
  26. {
  27. $object->read()->willReturn('some content');
  28. $container->get_object('filename')->willReturn($object);
  29. $this->read('filename')->shouldReturn('some content');
  30. }
  31. /**
  32. * @param \CF_Container $container
  33. * @param \CF_Object $object
  34. */
  35. function it_does_not_mask_exception_when_read($container, $object)
  36. {
  37. $object->read()->willThrow(new \RuntimeException('read'));
  38. $container->get_object('filename')->willReturn($object);
  39. $this->shouldThrow(new \RuntimeException('read'))->duringRead('filename');
  40. }
  41. /**
  42. * @param \CF_Container $container
  43. * @param \CF_Object $object
  44. */
  45. function it_does_check_if_file_exists($container, $object)
  46. {
  47. $container
  48. ->get_object('filename')
  49. ->willReturn($object)
  50. ;
  51. $container
  52. ->get_object('filename2')
  53. ->willReturn(false)
  54. ;
  55. $container
  56. ->get_object('filename3')
  57. ->willThrow(new \NoSuchObjectException)
  58. ;
  59. $this->exists('filename')->shouldReturn(true);
  60. $this->exists('filename2')->shouldReturn(false);
  61. $this->exists('filename3')->shouldReturn(false);
  62. }
  63. /**
  64. * @param \CF_Container $container
  65. * @param \CF_Object $object
  66. */
  67. function it_does_not_mask_exception_when_check_if_exists($container, $object)
  68. {
  69. $container->get_object('filename')->willThrow(new \RuntimeException('exists'));
  70. $this->shouldThrow(new \RuntimeException('exists'))->duringRead('filename');
  71. }
  72. /**
  73. * @param \CF_Container $container
  74. * @param \CF_Object $object
  75. */
  76. function it_should_write_file($container, $object)
  77. {
  78. $object
  79. ->write('some content')
  80. ->shouldBeCalled()
  81. ->willReturn(true)
  82. ;
  83. $container
  84. ->get_object('filename')
  85. ->shouldBeCalled()
  86. ->willReturn($object)
  87. ;
  88. $this->write('filename', 'some content')->shouldReturn(12);
  89. }
  90. /**
  91. * @param \CF_Container $container
  92. * @param \CF_Object $object
  93. */
  94. function it_does_not_write_file($container, $object)
  95. {
  96. $object
  97. ->write('some content')
  98. ->shouldBeCalled()
  99. ->willReturn(false)
  100. ;
  101. $container
  102. ->get_object('filename')
  103. ->shouldBeCalled()
  104. ->willReturn($object)
  105. ;
  106. $this->write('filename', 'some content')->shouldReturn(false);
  107. }
  108. /**
  109. * @param \CF_Container $container
  110. */
  111. function it_does_not_mask_exception_when_write($container)
  112. {
  113. $container->get_object('filename')->willThrow(new \RuntimeException('write'));
  114. $this->shouldThrow(new \RuntimeException('write'))->duringWrite('filename', 'some content');
  115. }
  116. /**
  117. * @param \CF_Container $container
  118. * @param \CF_Object $object
  119. */
  120. function it_creates_object_when_write($container, $object)
  121. {
  122. $object
  123. ->write('some content')
  124. ->shouldBeCalled()
  125. ->willReturn(true)
  126. ;
  127. $container
  128. ->get_object('filename')
  129. ->shouldBeCalled()
  130. ->willReturn(false)
  131. ;
  132. $container
  133. ->create_object('filename')
  134. ->shouldBeCalled()
  135. ->willReturn($object)
  136. ;
  137. $this->write('filename', 'some content')->shouldReturn(12);
  138. }
  139. /**
  140. * @param \CF_Container $container
  141. * @param \CF_Object $fromObject
  142. * @param \CF_Object $toObject
  143. */
  144. function it_renames_file($container, $fromObject, $toObject)
  145. {
  146. $fromObject
  147. ->read()
  148. ->willReturn('some content')
  149. ;
  150. $toObject
  151. ->write('some content')
  152. ->willReturn(true)
  153. ;
  154. $container
  155. ->delete_object('filename')
  156. ->shouldBeCalled()
  157. ;
  158. $container
  159. ->get_object('filename')
  160. ->willReturn($fromObject)
  161. ;
  162. $container
  163. ->get_object('filename1')
  164. ->willReturn($toObject)
  165. ;
  166. $this->rename('filename', 'filename1')->shouldReturn(true);
  167. }
  168. /**
  169. * @param \CF_Container $container
  170. */
  171. function it_does_not_mask_exception_when_rename($container)
  172. {
  173. $container->get_object('filename')->willThrow(new \RuntimeException('rename'));
  174. $this->shouldThrow(new \RuntimeException('rename'))->duringRename('filename', 'fromFilename');
  175. }
  176. /**
  177. * @param \CF_Container $container
  178. */
  179. function it_fetches_keys($container)
  180. {
  181. $container->list_objects(0, null, null)->willReturn(array('filename2', 'filename1'));
  182. $this->keys()->shouldReturn(array('filename1', 'filename2'));
  183. }
  184. /**
  185. * @param \CF_Container $container
  186. */
  187. function it_does_not_mask_exception_when_get_keys($container)
  188. {
  189. $container->list_objects(0, null, null)->willThrow(new \RuntimeException('keys'));
  190. $this->shouldThrow(new \RuntimeException('keys'))->duringKeys();
  191. }
  192. function it_does_not_support_mtime()
  193. {
  194. $this->mtime('filename')->shouldBe(false);
  195. $this->mtime('filename2')->shouldBe(false);
  196. }
  197. /**
  198. * @param \CF_Container $container
  199. * @param \CF_Object $object
  200. */
  201. function it_calculates_checksum($container, $object)
  202. {
  203. $object->getETag()->willReturn('123m5');
  204. $container->get_object('filename')->willReturn($object);
  205. $this->checksum('filename')->shouldReturn('123m5');
  206. }
  207. /**
  208. * @param \CF_Container $container
  209. */
  210. function it_does_not_mask_exception_when_calculate_checksum($container)
  211. {
  212. $container->get_object('filename')->willThrow(new \RuntimeException('checksum'));
  213. $this->shouldThrow(new \RuntimeException('checksum'))->duringChecksum('filename');
  214. }
  215. /**
  216. * @param \CF_Container $container
  217. */
  218. function it_deletes_file($container)
  219. {
  220. $container->delete_object('filename')->shouldBeCalled();
  221. $this->delete('filename')->shouldReturn(true);
  222. }
  223. /**
  224. * @param \CF_Container $container
  225. */
  226. function it_does_not_delete_file_if_not_found($container)
  227. {
  228. $container->delete_object('filename')->willThrow(new \NoSuchObjectException);
  229. $this->delete('filename')->shouldReturn(false);
  230. }
  231. /**
  232. * @param \CF_Container $container
  233. */
  234. function it_does_not_mask_exception_when_delete($container)
  235. {
  236. $container->delete_object('filename')->willThrow(new \RuntimeException('delete'));
  237. $this->shouldThrow(new \RuntimeException('delete'))->duringDelete('filename');
  238. }
  239. function it_does_not_support_directory()
  240. {
  241. $this->isDirectory('filename')->shouldReturn(false);
  242. }
  243. }