SftpSpec.php 2.9 KB

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