FtpTest.php in Flysystem 3.0.x
File
tests/src/Unit/Flysystem/FtpTest.php
View source
<?php
namespace Drupal\Tests\flysystem\Unit\Flysystem;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Tests\UnitTestCase;
use Drupal\flysystem\Flysystem\Adapter\MissingAdapter;
use Drupal\flysystem\Flysystem\Ftp;
use League\Flysystem\Adapter\Ftp as LeagueFtp;
class FtpTest extends UnitTestCase {
public function setUp() {
parent::setUp();
if (!defined('FTP_BINARY')) {
$this
->markTestSkipped('The FTP_BINARY constant is not defined.');
}
}
public function testGetAdapterSuccess() {
$plugin = new Ftp([
'host' => 'success',
]);
$this
->assertInstanceOf(LeagueFtp::class, $plugin
->getAdapter());
}
public function testGetAdapterFails() {
$plugin = new Ftp([]);
$this
->assertInstanceOf(MissingAdapter::class, $plugin
->getAdapter());
}
public function testEnsureReturnsNoErrorsOnSuccess() {
$result = (new Ftp([
'host' => 'success',
]))
->ensure();
$this
->assertSame(1, count($result));
$this
->assertSame(RfcLogLevel::INFO, $result[0]['severity']);
}
public function testEnsureReturnsErrors() {
$plugin = new Ftp([]);
$result = $plugin
->ensure();
$this
->assertSame(1, count($result));
$this
->assertSame(21, $result[0]['context']['%port']);
}
}
namespace League\Flysystem\Adapter;
function ftp_chdir() {
return TRUE;
}
function ftp_close() {
}
function ftp_connect($host) {
return $host === 'success';
}
function ftp_login() {
return TRUE;
}
function ftp_pasv() {
return TRUE;
}
function ftp_pwd() {
return '';
}
function ftp_systype() {
return TRUE;
}
function ftp_raw() {
return [
'200',
];
}