fix ftp upload

This commit is contained in:
Dennis Eichhorn 2021-10-26 14:42:54 +02:00
parent 5e63303b67
commit 12b8eea76c
4 changed files with 87 additions and 54 deletions

View File

@ -125,6 +125,7 @@ class File extends FileAbstract implements FileInterface
{
$exists = self::exists($con, $path);
// @todo: consider to use the php://memory way, used in the seUpBeforeClass in the test
if ((ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists)
|| (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists)
|| (ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE) && $exists)

View File

@ -31,6 +31,34 @@ final class DirectoryTest extends \PHPUnit\Framework\TestCase
public static function setUpBeforeClass() : void
{
self::$con = Directory::ftpConnect(new HttpUri(self::BASE));
if (self::$con === false) {
self::$con = null;
return;
}
try {
$mkdir = \ftp_mkdir(self::$con, '0xFF');
\ftp_rmdir(self::$con, '0xFF');
$f = \fopen('php://memory', 'r+');
\fwrite($f, '0x00');
\rewind($f);
$put = \ftp_fput(self::$con, '0x00', $f);
\fclose($f);
\ftp_delete(self::$con, '0x00');
if (!$mkdir || !$put) {
throw new \Exception();
}
} catch (\Throwable $t) {
self::$con = null;
var_dump($t->getMessage());
}
}
/**
@ -38,26 +66,10 @@ final class DirectoryTest extends \PHPUnit\Framework\TestCase
*/
protected function setUp() : void
{
if (self::$con === false) {
if (self::$con === null) {
$this->markTestSkipped(
'The ftp connection is not available.'
);
} else {
try {
$mkdir = \ftp_mkdir(self::$con, '0xFF');
\ftp_rmdir(self::$con, '0xFF');
$put = \ftp_put(self::$con, '0x00');
\ftp_delete(self::$con, '0x00');
if (!$mkdir || !$put) {
throw new \Exception();
}
} catch (\Throwable $t) {
$this->markTestSkipped(
'No write permissions on ftp server.'
);
}
}
}
@ -894,7 +906,7 @@ final class DirectoryTest extends \PHPUnit\Framework\TestCase
public function testNodeInvalid() : void
{
$dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con);
$dir->next()->next()->next()->next()->next()->next()->next();
$dir?->next()?->next()?->next()?->next()?->next()?->next()?->next();
self::assertFalse($dir->valid());
}

View File

@ -33,6 +33,32 @@ final class FileTest extends \PHPUnit\Framework\TestCase
public static function setUpBeforeClass() : void
{
self::$con = File::ftpConnect(new HttpUri(self::BASE));
if (self::$con === false) {
self::$con = null;
return;
}
try {
$mkdir = \ftp_mkdir(self::$con, '0xFF');
\ftp_rmdir(self::$con, '0xFF');
$f = \fopen('php://memory', 'r+');
\fwrite($f, '0x00');
\rewind($f);
$put = \ftp_fput(self::$con, '0x00', $f);
\fclose($f);
\ftp_delete(self::$con, '0x00');
if (!$mkdir || !$put) {
throw new \Exception();
}
} catch (\Throwable $t) {
self::$con = null;
}
}
/**
@ -40,26 +66,10 @@ final class FileTest extends \PHPUnit\Framework\TestCase
*/
protected function setUp() : void
{
if (self::$con === false) {
if (self::$con === null) {
$this->markTestSkipped(
'The ftp connection is not available.'
);
} else {
try {
$mkdir = \ftp_mkdir(self::$con, '0xFF');
\ftp_rmdir(self::$con, '0xFF');
$put = \ftp_put(self::$con, '0x00');
\ftp_delete(self::$con, '0x00');
if (!$mkdir || !$put) {
throw new \Exception();
}
} catch (\Throwable $t) {
$this->markTestSkipped(
'No write permissions on ftp server.'
);
}
}
}

View File

@ -34,6 +34,34 @@ final class FtpStorageTest extends \PHPUnit\Framework\TestCase
public static function setUpBeforeClass() : void
{
self::$con = Directory::ftpConnect(new HttpUri(self::BASE));
if (self::$con === false) {
self::$con = null;
return;
}
try {
$mkdir = \ftp_mkdir(self::$con, '0xFF');
\ftp_rmdir(self::$con, '0xFF');
$f = \fopen('php://memory', 'r+');
\fwrite($f, '0x00');
\rewind($f);
$put = \ftp_fput(self::$con, '0x00', $f);
\fclose($f);
\ftp_delete(self::$con, '0x00');
if (!$mkdir || !$put) {
throw new \Exception();
}
} catch (\Throwable $t) {
self::$con = null;
}
FtpStorage::with(self::$con);
}
/**
@ -41,29 +69,11 @@ final class FtpStorageTest extends \PHPUnit\Framework\TestCase
*/
protected function setUp() : void
{
if (self::$con === false) {
if (self::$con === null) {
$this->markTestSkipped(
'The ftp connection is not available.'
);
} else {
try {
$mkdir = \ftp_mkdir(self::$con, '0xFF');
\ftp_rmdir(self::$con, '0xFF');
$put = \ftp_put(self::$con, '0x00');
\ftp_delete(self::$con, '0x00');
if (!$mkdir || !$put) {
throw new \Exception();
}
} catch (\Throwable $t) {
$this->markTestSkipped(
'No write permissions on ftp server.'
);
}
}
FtpStorage::with(self::$con);
}
/**