1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SF2Helpers\SFTPBundle\Tests\SFTP; |
4
|
|
|
|
5
|
|
|
use SF2Helpers\SFTPBundle\SFTP\SFTP; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
7
|
|
|
|
8
|
|
|
class SFTPTest extends WebTestCase |
9
|
|
|
{ |
10
|
|
|
// test credentials took from here - http://www.sftp.net/public-online-sftp-servers |
11
|
|
|
private $hostname = 'demo.wftpserver.com'; |
12
|
|
|
private $port = '2222'; |
13
|
|
|
private $login = 'demo-user'; |
14
|
|
|
private $password = 'demo-user'; |
15
|
|
|
|
16
|
|
|
/** @var SFTP $sftpService */ |
17
|
|
|
private $sftpService; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test getRemoteFilesList() |
21
|
|
|
*/ |
22
|
|
|
public function testGetRemoteFilesList() |
23
|
|
|
{ |
24
|
|
|
$filesList = $this->sftpService->getRemoteFilesList('/download'); |
25
|
|
|
|
26
|
|
|
$this->assertTrue(is_array($filesList)); |
27
|
|
|
$this->assertTrue(count($filesList) > 0); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Test sendTo() |
32
|
|
|
*/ |
33
|
|
|
public function testSendTo() |
34
|
|
|
{ |
35
|
|
|
$this->sftpService->sendTo(dirname(__FILE__).'/../fixtures/b629855d08.png', '/upload/b629855d08.png'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test sendTo() |
40
|
|
|
*/ |
41
|
|
|
public function testFetchFrom() |
42
|
|
|
{ |
43
|
|
|
$this->sftpService->fetchFrom('/download/manual_en.pdf', dirname(__FILE__).'/../fixtures/manual_en.pdf'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Set up fixtures for testing |
48
|
|
|
*/ |
49
|
|
|
public function setUp() |
50
|
|
|
{ |
51
|
|
|
require_once __DIR__.'/../AppKernel.php'; |
52
|
|
|
$kernel = new \AppKernel('test', true); |
53
|
|
|
$kernel->boot(); |
54
|
|
|
$container = $kernel->getContainer(); |
55
|
|
|
$this->sftpService = $container->get('sf2h.sftp'); |
56
|
|
|
|
57
|
|
|
$this->sftpService->connect($this->hostname, $this->port); |
58
|
|
|
$this->sftpService->login($this->login, $this->password); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Shut down test suite |
63
|
|
|
*/ |
64
|
|
|
public function tearDown() |
65
|
|
|
{ |
66
|
|
|
$this->sftpService->disconnect(); |
67
|
|
|
unset($this->sftpService); |
68
|
|
|
if (file_exists(dirname(__FILE__).'/../fixtures/manual_en.pdf')) { |
69
|
|
|
unlink(dirname(__FILE__).'/../fixtures/manual_en.pdf'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|