test fixes

This commit is contained in:
Dennis Eichhorn 2022-12-26 16:10:12 +01:00
parent 4a3410d182
commit 6e52397ab4
7 changed files with 68 additions and 19 deletions

View File

@ -151,11 +151,11 @@ interface ContainerInterface
/** /**
* Get the owner id of the resource. * Get the owner id of the resource.
* *
* @return int * @return string
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getOwner() : int; public function getOwner() : string;
/** /**
* Get the permissions id of the resource. * Get the permissions id of the resource.

View File

@ -66,7 +66,10 @@ class Directory extends FileAbstract implements DirectoryInterface
return null; return null;
} }
\ftp_login($con, $http->user, $http->pass); $status = \ftp_login($con, $http->user, $http->pass);
if ($status === false) {
return null;
}
if ($http->getPath() !== '') { if ($http->getPath() !== '') {
@\ftp_chdir($con, $http->getPath()); @\ftp_chdir($con, $http->getPath());
@ -347,6 +350,16 @@ class Directory extends FileAbstract implements DirectoryInterface
return self::parseRawList($con, self::parent($path))[$path]['user']; return self::parseRawList($con, self::parent($path))[$path]['user'];
} }
/**
* {@inheritdoc}
*/
public function getOwner() : string
{
$this->owner = self::parseRawList($this->con, self::parent($this->path))[$this->path]['user'];
return $this->owner;
}
/** /**
* Get detailed file/dir list. * Get detailed file/dir list.
* *
@ -407,6 +420,16 @@ class Directory extends FileAbstract implements DirectoryInterface
return self::parseRawList($con, self::parent($path))[$path]['permission']; return self::parseRawList($con, self::parent($path))[$path]['permission'];
} }
/**
* {@inheritdoc}
*/
public function getPermission() : int
{
$this->permission = self::parseRawList($this->con, self::parent($this->path))[$this->path]['permission'];
return $this->permission;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -86,7 +86,10 @@ class File extends FileAbstract implements FileInterface
return null; return null;
} }
\ftp_login($con, $http->user, $http->pass); $status = \ftp_login($con, $http->user, $http->pass);
if ($status === false) {
return null;
}
if ($http->getPath() !== '') { if ($http->getPath() !== '') {
@\ftp_chdir($con, $http->getPath()); @\ftp_chdir($con, $http->getPath());
@ -294,6 +297,16 @@ class File extends FileAbstract implements FileInterface
return Directory::parseRawList($con, self::dirpath($path))[$path]['user']; return Directory::parseRawList($con, self::dirpath($path))[$path]['user'];
} }
/**
* {@inheritdoc}
*/
public function getOwner() : string
{
$this->owner = Directory::parseRawList($this->con, self::dirpath($this->path))[$this->path]['user'];
return $this->owner;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -306,6 +319,16 @@ class File extends FileAbstract implements FileInterface
return Directory::parseRawList($con, self::dirpath($path))[$path]['permission']; return Directory::parseRawList($con, self::dirpath($path))[$path]['permission'];
} }
/**
* {@inheritdoc}
*/
public function getPermission() : int
{
$this->permission = Directory::parseRawList($this->con, self::dirpath($this->path))[$this->path]['permission'];
return $this->permission;
}
/** /**
* Gets the directory name of a file. * Gets the directory name of a file.
* *

View File

@ -95,10 +95,10 @@ abstract class FileAbstract implements FtpContainerInterface
/** /**
* Owner. * Owner.
* *
* @var int * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected int $owner = 0; protected string $owner = '';
/** /**
* Permission. * Permission.
@ -191,7 +191,7 @@ abstract class FileAbstract implements FtpContainerInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getOwner() : int public function getOwner() : string
{ {
return $this->owner; return $this->owner;
} }
@ -219,7 +219,7 @@ abstract class FileAbstract implements FtpContainerInterface
$this->createdAt = (new \DateTimeImmutable())->setTimestamp($mtime === false ? 0 : $mtime); $this->createdAt = (new \DateTimeImmutable())->setTimestamp($mtime === false ? 0 : $mtime);
$this->changedAt->setTimestamp($ctime === false ? 0 : $ctime); $this->changedAt->setTimestamp($ctime === false ? 0 : $ctime);
$this->owner = 0; $this->owner = '';
$this->permission = 0; $this->permission = 0;
$this->isInitialized = true; $this->isInitialized = true;

View File

@ -79,10 +79,10 @@ abstract class FileAbstract implements LocalContainerInterface
/** /**
* Owner. * Owner.
* *
* @var int * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected int $owner = 0; protected string $owner = '';
/** /**
* Permission. * Permission.
@ -220,7 +220,7 @@ abstract class FileAbstract implements LocalContainerInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getOwner() : int public function getOwner() : string
{ {
return $this->owner; return $this->owner;
} }
@ -246,7 +246,7 @@ abstract class FileAbstract implements LocalContainerInterface
$owner = \fileowner($this->path); $owner = \fileowner($this->path);
$this->owner = $owner === false ? 0 : $owner; $this->owner = $owner === false ? '' : (string) $owner;
$this->permission = (int) \substr(\sprintf('%o', \fileperms($this->path)), -4); $this->permission = (int) \substr(\sprintf('%o', \fileperms($this->path)), -4);
$this->isInitialized = true; $this->isInitialized = true;

View File

@ -277,22 +277,25 @@ abstract class ViewAbstract implements RenderableInterface
*/ */
protected function renderTemplate(string $template, mixed ...$data) : string protected function renderTemplate(string $template, mixed ...$data) : string
{ {
$ob = ''; $obLevel = 0;
$ob = '';
try { try {
if ($this->isBuffered) {
\ob_start();
}
$path = $template; $path = $template;
if (!\is_file($path)) { if (!\is_file($path)) {
return ''; return '';
} }
if ($this->isBuffered) {
++$obLevel;
\ob_start();
}
/** @noinspection PhpIncludeInspection */ /** @noinspection PhpIncludeInspection */
$includeData = include $path; $includeData = include $path;
if ($this->isBuffered) { if ($this->isBuffered) {
--$obLevel;
$ob = (string) \ob_get_clean(); $ob = (string) \ob_get_clean();
} }
@ -300,7 +303,7 @@ abstract class ViewAbstract implements RenderableInterface
$ob = (string) \json_encode($includeData); $ob = (string) \json_encode($includeData);
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
if ($this->isBuffered) { if ($obLevel > 0 && $this->isBuffered) {
$ob .= (string) \ob_get_clean(); $ob .= (string) \ob_get_clean();
} }
} }

View File

@ -88,7 +88,7 @@ final class FileTest extends \PHPUnit\Framework\TestCase
*/ */
public function testInvalidConnection() : void public function testInvalidConnection() : void
{ {
self::assertFalse(File::ftpConnect(new HttpUri('ftp://karaka.app:21'))); self::assertEquals(null, File::ftpConnect(new HttpUri('ftp://karaka.app:21')));
} }
/** /**