123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace spec\Gaufrette\Adapter;
- if (!defined('NET_SFTP_TYPE_REGULAR')) {
- define('NET_SFTP_TYPE_REGULAR', 1);
- }
- if (!defined('NET_SFTP_TYPE_DIRECTORY')) {
- define('NET_SFTP_TYPE_DIRECTORY', 2);
- }
- use Gaufrette\Filesystem;
- use phpseclib\Net\SFTP as Base;
- use PhpSpec\ObjectBehavior;
- class SFTP extends Base
- {
- public function __construct()
- {
- }
- }
- class PhpseclibSftpSpec extends ObjectBehavior
- {
- /**
- * @param \spec\Gaufrette\Adapter\SFTP $sftp
- */
- function let(SFTP $sftp)
- {
- $this->beConstructedWith($sftp, '/home/l3l0', false, 'l3lo', 'password');
- }
- function it_is_adapter()
- {
- $this->shouldHaveType('Gaufrette\Adapter');
- }
- function it_is_file_factory()
- {
- $this->shouldHaveType('Gaufrette\Adapter\FileFactory');
- }
- function it_supports_native_list_keys()
- {
- $this->shouldHaveType('Gaufrette\Adapter\ListKeysAware');
- }
- /**
- * @param \spec\Gaufrette\Adapter\SFTP $sftp
- */
- function it_fetches_keys(SFTP $sftp)
- {
- $sftp
- ->file_exists('/home/l3l0/')
- ->willReturn(true);
- $sftp
- ->rawlist('/home/l3l0/')
- ->willReturn(array(
- 'filename' => array('type' => NET_SFTP_TYPE_REGULAR),
- 'filename1' => array('type' => NET_SFTP_TYPE_REGULAR),
- 'aaa' => array('type' => NET_SFTP_TYPE_DIRECTORY)
- ));
- $sftp
- ->file_exists('/home/l3l0/aaa')
- ->willReturn(true);
- $sftp
- ->rawlist('/home/l3l0/aaa')
- ->willReturn(array(
- 'filename' => array('type' => NET_SFTP_TYPE_REGULAR),
- ));
- $this->keys()->shouldReturn(array('filename', 'filename1', 'aaa', 'aaa/filename'));
- }
- /**
- * @param \spec\Gaufrette\Adapter\SFTP $sftp
- */
- function it_reads_file(SFTP $sftp)
- {
- $sftp->get('/home/l3l0/filename')->willReturn('some content');
- $this->read('filename')->shouldReturn('some content');
- }
- /**
- * @param \spec\Gaufrette\Adapter\SFTP $sftp
- */
- function it_creates_and_writes_file(SFTP $sftp)
- {
- $sftp->pwd()->willReturn('/home/l3l0');
- $sftp->chdir('/home/l3l0')->willReturn(true);
- $sftp->put('/home/l3l0/filename', 'some content')->willReturn(true);
- $sftp->size('/home/l3l0/filename')->willReturn(12);
- $this->write('filename', 'some content')->shouldReturn(12);
- }
- /**
- * @param \spec\Gaufrette\Adapter\SFTP $sftp
- */
- function it_renames_file(SFTP $sftp)
- {
- $sftp->pwd()->willReturn('/home/l3l0');
- $sftp->chdir('/home/l3l0')->willReturn(true);
- $sftp
- ->rename('/home/l3l0/filename', '/home/l3l0/filename1')
- ->willReturn(true)
- ;
- $this->rename('filename', 'filename1')->shouldReturn(true);
- }
- /**
- * @param \spec\Gaufrette\Adapter\SFTP $sftp
- */
- function it_should_check_if_file_exists(SFTP $sftp)
- {
- $sftp->pwd()->willReturn('/home/l3l0');
- $sftp->chdir('/home/l3l0')->willReturn(true);
- $sftp->stat('/home/l3l0/filename')->willReturn(array(
- 'name' => '/home/l3l0/filename'
- ));
- $sftp->stat('/home/l3l0/filename1')->willReturn(false);
- $this->exists('filename')->shouldReturn(true);
- $this->exists('filename1')->shouldReturn(false);
- }
- /**
- * @param \spec\Gaufrette\Adapter\SFTP $sftp
- */
- function it_should_check_is_directory(SFTP $sftp)
- {
- $sftp->pwd()->willReturn('/home/l3l0');
- $sftp->chdir('/home/l3l0')->willReturn(true);
- $sftp->chdir('/home/l3l0/aaa')->willReturn(true);
- $sftp->chdir('/home/l3l0/filename')->willReturn(false);
- $this->isDirectory('aaa')->shouldReturn(true);
- $this->isDirectory('filename')->shouldReturn(false);
- }
- /**
- * @param \spec\Gaufrette\Adapter\SFTP $sftp
- * @param \Gaufrette\Filesystem $filesystem
- */
- function it_should_create_file(SFTP $sftp, Filesystem $filesystem)
- {
- $sftp->stat('/home/l3l0/filename')->willReturn(array(
- 'name' => '/home/l3l0/filename',
- 'size' => '30',
- ));
- $this->createFile('filename', $filesystem)->beAnInstanceOf('Gaufrette\File');
- }
- }
|