SftpSpec.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace spec\Gaufrette\Adapter;
  3. //hack - mock php built-in functions
  4. require_once 'functions.php';
  5. use PhpSpec\ObjectBehavior;
  6. class SftpSpec extends ObjectBehavior
  7. {
  8. /**
  9. * @param \Ssh\Sftp $sftp
  10. */
  11. function let($sftp)
  12. {
  13. $this->beConstructedWith($sftp, '/home/l3l0');
  14. }
  15. function it_is_adapter()
  16. {
  17. $this->shouldHaveType('Gaufrette\Adapter');
  18. }
  19. function it_is_checksum_calculator()
  20. {
  21. $this->shouldHaveType('Gaufrette\Adapter\ChecksumCalculator');
  22. }
  23. /**
  24. * @param \Ssh\Sftp $sftp
  25. */
  26. function it_fetches_keys($sftp)
  27. {
  28. $sftp
  29. ->getUrl('/home/l3l0')
  30. ->willReturn('ssh+ssl://localhost/home/l3l0')
  31. ;
  32. $sftp
  33. ->listDirectory('/home/l3l0', true)
  34. ->willReturn(array('files' => array('/home/l3l0/filename', '/home/l3l0/filename1', '/home/l3l0/aaa/filename')))
  35. ;
  36. $this->keys()->shouldReturn(array('aaa', 'aaa/filename', 'filename', 'filename1'));
  37. }
  38. /**
  39. * @param \Ssh\Sftp $sftp
  40. */
  41. function it_reads_file($sftp)
  42. {
  43. $sftp
  44. ->getUrl('/home/l3l0')
  45. ->willReturn('ssh+ssl://localhost/home/l3l0')
  46. ;
  47. $sftp
  48. ->read('/home/l3l0/filename')
  49. ->shouldBeCalled()
  50. ->willReturn('some content')
  51. ;
  52. $this->read('filename')->shouldReturn('some content');
  53. }
  54. /**
  55. * @param \Ssh\Sftp $sftp
  56. */
  57. function it_writes_file($sftp)
  58. {
  59. $sftp
  60. ->getUrl('/home/l3l0')
  61. ->willReturn('ssh+ssl://localhost/home/l3l0')
  62. ;
  63. $sftp
  64. ->write('/home/l3l0/filename', 'some content')
  65. ->shouldBeCalled()
  66. ->willReturn(12)
  67. ;
  68. $this->write('filename', 'some content')->shouldReturn(12);
  69. }
  70. /**
  71. * @param \Ssh\Sftp $sftp
  72. */
  73. function it_renames_file($sftp)
  74. {
  75. $sftp
  76. ->getUrl('/home/l3l0')
  77. ->willReturn('ssh+ssl://localhost/home/l3l0')
  78. ;
  79. $sftp
  80. ->rename('/home/l3l0/filename', '/home/l3l0/filename1')
  81. ->shouldBeCalled()
  82. ->willReturn(true)
  83. ;
  84. $this->rename('filename', 'filename1')->shouldReturn(true);
  85. }
  86. /**
  87. * @param \Ssh\Sftp $sftp
  88. */
  89. function it_checks_if_file_exists($sftp)
  90. {
  91. $sftp
  92. ->getUrl('/home/l3l0')
  93. ->willReturn('ssh+ssl://localhost/home/l3l0')
  94. ;
  95. $sftp
  96. ->getUrl('/home/l3l0/filename')
  97. ->shouldBeCalled()
  98. ->willReturn('ssh+ssl://localhost/home/l3l0/filename')
  99. ;
  100. $sftp
  101. ->getUrl('/home/l3l0/filename1')
  102. ->shouldBeCalled()
  103. ->willReturn('ssh+ssl://localhost/home/l3l0/filename1')
  104. ;
  105. $this->exists('filename')->shouldReturn(true);
  106. $this->exists('filename1')->shouldReturn(false);
  107. }
  108. }