FlysystemSpec.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace spec\Gaufrette\Adapter;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. use League\Flysystem\AdapterInterface;
  6. use League\Flysystem\Config;
  7. class FlysystemSpec extends ObjectBehavior
  8. {
  9. function let(AdapterInterface $adapter, Config $config)
  10. {
  11. $this->beConstructedWith($adapter, $config);
  12. }
  13. function it_is_adapter()
  14. {
  15. $this->shouldImplement('Gaufrette\Adapter');
  16. }
  17. function it_is_list_keys_aware()
  18. {
  19. $this->shouldImplement('Gaufrette\Adapter\ListKeysAware');
  20. }
  21. function it_reads_file(AdapterInterface $adapter)
  22. {
  23. $adapter->read('filename')->willReturn(['contents' => 'Hello.']);
  24. $this->read('filename')->shouldReturn('Hello.');
  25. }
  26. function it_writes_file(AdapterInterface $adapter, Config $config)
  27. {
  28. $adapter->write('filename', 'Hello.', $config)->willReturn(array());
  29. $this->write('filename', 'Hello.')->shouldReturn(array());
  30. }
  31. function it_checks_if_file_exists(AdapterInterface $adapter)
  32. {
  33. $adapter->has('filename')->willReturn(true);
  34. $this->exists('filename')->shouldReturn(true);
  35. }
  36. function it_checks_if_file_exists_when_flysystem_returns_array(AdapterInterface $adapter)
  37. {
  38. $adapter->has('filename')->willReturn(['type' => 'file']);
  39. $this->exists('filename')->shouldReturn(true);
  40. }
  41. function it_fetches_keys(AdapterInterface $adapter)
  42. {
  43. $adapter->listContents()->willReturn([[
  44. 'path' => 'folder',
  45. 'timestamp' => 1457104978,
  46. 'size' => 22,
  47. 'type' => 'dir',
  48. ]]);
  49. $this->keys()->shouldReturn(['folder']);
  50. }
  51. function it_lists_keys(AdapterInterface $adapter)
  52. {
  53. $adapter->listContents()->willReturn([[
  54. 'path' => 'folder',
  55. 'timestamp' => 1457104978,
  56. 'size' => 22,
  57. 'type' => 'dir',
  58. ]]);
  59. $this->listKeys()->shouldReturn([
  60. 'keys' => [],
  61. 'dirs' => ['folder'],
  62. ]);
  63. }
  64. function it_fetches_mtime(AdapterInterface $adapter)
  65. {
  66. $adapter->getTimestamp('filename')->willReturn(1457104978);
  67. $this->mtime('filename')->shouldReturn(1457104978);
  68. }
  69. function it_deletes_file(AdapterInterface $adapter)
  70. {
  71. $adapter->delete('filename')->willReturn(true);
  72. $this->delete('filename')->shouldReturn(true);
  73. }
  74. function it_renames_file(AdapterInterface $adapter)
  75. {
  76. $adapter->rename('oldfilename', 'newfilename')->willReturn(true);
  77. $this->rename('oldfilename', 'newfilename')->shouldReturn(true);
  78. }
  79. function it_does_not_support_is_directory(AdapterInterface $adapter)
  80. {
  81. $this->shouldThrow('Gaufrette\Exception\UnsupportedAdapterMethodException')->duringisDirectory('folder');
  82. }
  83. }