PhpseclibSftpSpec.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace spec\Gaufrette\Adapter;
  3. if (!defined('NET_SFTP_TYPE_REGULAR')) {
  4. define('NET_SFTP_TYPE_REGULAR', 1);
  5. }
  6. if (!defined('NET_SFTP_TYPE_DIRECTORY')) {
  7. define('NET_SFTP_TYPE_DIRECTORY', 2);
  8. }
  9. use PhpSpec\ObjectBehavior;
  10. class PhpseclibSftpSpec extends ObjectBehavior
  11. {
  12. /**
  13. * @param \spec\Gaufrette\Adapter\Net_SFTP $sftp
  14. */
  15. function let($sftp)
  16. {
  17. $this->beConstructedWith($sftp, '/home/l3l0');
  18. }
  19. function it_is_adapter()
  20. {
  21. $this->shouldHaveType('Gaufrette\Adapter');
  22. }
  23. function it_is_file_factory()
  24. {
  25. $this->shouldHaveType('Gaufrette\Adapter\FileFactory');
  26. }
  27. function it_supports_native_list_keys()
  28. {
  29. $this->shouldHaveType('Gaufrette\Adapter\ListKeysAware');
  30. }
  31. /**
  32. * @param \spec\Gaufrette\Adapter\Net_SFTP $sftp
  33. */
  34. function it_fetchs_keys($sftp)
  35. {
  36. $sftp
  37. ->rawlist('/home/l3l0/')
  38. ->willReturn(array(
  39. 'filename' => array('type' => NET_SFTP_TYPE_REGULAR),
  40. 'filename1' => array('type' => NET_SFTP_TYPE_REGULAR),
  41. 'aaa' => array('type' => NET_SFTP_TYPE_DIRECTORY)
  42. ));
  43. $sftp
  44. ->rawlist('/home/l3l0/aaa')
  45. ->willReturn(array(
  46. 'filename' => array('type' => NET_SFTP_TYPE_REGULAR),
  47. ));
  48. $this->keys()->shouldReturn(array('filename', 'filename1', 'aaa', 'aaa/filename'));
  49. }
  50. /**
  51. * @param \spec\Gaufrette\Adapter\Net_SFTP $sftp
  52. */
  53. function it_reads_file($sftp)
  54. {
  55. $sftp->get('/home/l3l0/filename')->willReturn('some content');
  56. $this->read('filename')->shouldReturn('some content');
  57. }
  58. /**
  59. * @param \spec\Gaufrette\Adapter\Net_SFTP $sftp
  60. */
  61. function it_creates_and_writes_file($sftp)
  62. {
  63. $sftp->pwd()->willReturn('/home/l3l0');
  64. $sftp->chdir('/home/l3l0')->willReturn(true);
  65. $sftp->put('/home/l3l0/filename', 'some content')->willReturn(true);
  66. $sftp->size('/home/l3l0/filename')->willReturn(12);
  67. $this->write('filename', 'some content')->shouldReturn(12);
  68. }
  69. /**
  70. * @param \spec\Gaufrette\Adapter\Net_SFTP $sftp
  71. */
  72. function it_renames_file($sftp)
  73. {
  74. $sftp->pwd()->willReturn('/home/l3l0');
  75. $sftp->chdir('/home/l3l0')->willReturn(true);
  76. $sftp
  77. ->rename('/home/l3l0/filename', '/home/l3l0/filename1')
  78. ->willReturn(true)
  79. ;
  80. $this->rename('filename', 'filename1')->shouldReturn(true);
  81. }
  82. /**
  83. * @param \spec\Gaufrette\Adapter\Net_SFTP $sftp
  84. */
  85. function it_should_check_if_file_exists($sftp)
  86. {
  87. $sftp->pwd()->willReturn('/home/l3l0');
  88. $sftp->chdir('/home/l3l0')->willReturn(true);
  89. $sftp->stat('/home/l3l0/filename')->willReturn(array(
  90. 'name' => '/home/l3l0/filename'
  91. ));
  92. $sftp->stat('/home/l3l0/filename1')->willReturn(false);
  93. $this->exists('filename')->shouldReturn(true);
  94. $this->exists('filename1')->shouldReturn(false);
  95. }
  96. /**
  97. * @param \spec\Gaufrette\Adapter\Net_SFTP $sftp
  98. */
  99. function it_should_check_is_directory($sftp)
  100. {
  101. $sftp->pwd()->willReturn('/home/l3l0');
  102. $sftp->chdir('/home/l3l0')->willReturn(true);
  103. $sftp->chdir('/home/l3l0/aaa')->willReturn(true);
  104. $sftp->chdir('/home/l3l0/filename')->willReturn(false);
  105. $this->isDirectory('aaa')->shouldReturn(true);
  106. $this->isDirectory('filename')->shouldReturn(false);
  107. }
  108. /**
  109. * @param \spec\Gaufrette\Adapter\Net_SFTP $sftp
  110. * @param \Gaufrette\Filesystem $filesystem
  111. */
  112. function it_should_create_file($sftp, $filesystem)
  113. {
  114. $sftp->stat('/home/l3l0/filename')->willReturn(array(
  115. 'name' => '/home/l3l0/filename',
  116. 'size' => '30',
  117. ));
  118. $this->createFile('filename', $filesystem)->beAnInstanceOf('Gaufrette\File');
  119. }
  120. }
  121. class Net_SFTP extends \Net_SFTP
  122. {
  123. public function __construct()
  124. {
  125. }
  126. }