diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 55ce42ac3..7115f636d 100644 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -20,6 +20,7 @@ use phpOMS\System\File\FileUtils; use phpOMS\System\File\Local\Directory as LocalDirectory; use phpOMS\System\File\PathException; use phpOMS\Uri\HttpUri; +use phpOMS\Utils\StringUtils; /** * Filesystem class. @@ -33,14 +34,6 @@ use phpOMS\Uri\HttpUri; */ class Directory extends FileAbstract implements DirectoryInterface, FtpContainerInterface { - /** - * Ftp connection - * - * @var resource - * @since 1.0.0 - */ - private $con; - /** * Directory nodes (files and directories). * @@ -78,35 +71,65 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer /** * Constructor. * - * @param HttpUri $uri Uri - * @param string $filter Filter + * @param HttpUri $uri Uri + * @param string $filter Filter + * @param bool $initialize Should get initialized during construction + * @param null|resource $con Connection * * @since 1.0.0 */ - public function __construct(HttpUri $uri, string $filter = '*', bool $initialize = true) + public function __construct(HttpUri $uri, string $filter = '*', bool $initialize = true, $con = null) { - $this->con = self::ftpConnect($uri); + $this->uri = $uri; + $this->con = $con ?? self::ftpConnect($uri); $this->filter = \ltrim($filter, '\\/'); parent::__construct($uri->getPath()); - if ($initialize && \file_exists($this->path)) { + if ($initialize && self::exists($this->con, $this->path)) { $this->index(); } } + /** + * {@inheritdoc} + */ + public function index() : void + { + if ($this->isInitialized) { + return; + } + + $this->isInitialized = true; + parent::index(); + + $list = self::list($this->con, $this->path); + + foreach ($list as $filename) { + if (!StringUtils::endsWith(\trim($filename), '.')) { + $uri = clone $this->uri; + $uri->setPath($filename); + + $file = \ftp_size($this->con, $filename) === -1 ? new self($uri, '*', false, $this->con) : new File($uri, $this->con); + + $this->addNode($file); + } + } + } + /** * List all files in directory. * * @param resource $con FTP connection * @param string $path Path * @param string $filter Filter + * @param bool $recursive Recursive list * * @return string[] * * @since 1.0.0 */ - public static function list($con, string $path, string $filter = '*') : array + public static function list($con, string $path, string $filter = '*', bool $recursive = false) : array { if (!self::exists($con, $path)) { return []; @@ -117,15 +140,15 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer $detailed = self::parseRawList($con, $path); foreach ($detailed as $key => $item) { - if ($filter !== '*' && \preg_match($filter, $key) === 1) { + if ($item['type'] === 'dir' && $recursive) { + $list = \array_merge($list, self::list($con, $key, $filter, $recursive)); + } + + if ($filter !== '*' && \preg_match($filter, $key) !== 1) { continue; } $list[] = $key; - - if ($item['type'] === 'dir') { - $list = \array_merge($list, self::list($con, $key)); - } } /** @var string[] $list */ @@ -485,28 +508,33 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer */ public static function move($con, string $from, string $to, bool $overwrite = false) : bool { - if (!self::exists($con, $from)) { + if (!self::exists($con, $from) + || (!$overwrite && self::exists($con, $to)) + ) { return false; } if ($overwrite && self::exists($con, $to)) { self::delete($con, $to); - } elseif (self::exists($con, $to)) { - return false; } $copy = self::copy($con, $from, $to); + + if (!$copy) { + return false; + } + self::delete($con, $from); - return $copy; + return true; } /** * {@inheritdoc} */ - public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string + public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;:\[\]\(\]\/]/') : string { - return LocalDirectory::sanitize($path, $replace, $invalid); + return \preg_replace($invalid, $replace, $path) ?? ''; } /** @@ -514,7 +542,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer */ public static function dirname(string $path) : string { - return LocalDirectory::dirname($path); + return \basename($path); } /** @@ -522,7 +550,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer */ public static function dirpath(string $path) : string { - return LocalDirectory::dirpath($path); + return $path; } /** @@ -530,7 +558,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer */ public static function name(string $path) : string { - return LocalDirectory::name($path); + return \basename($path); } /** @@ -538,7 +566,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer */ public static function basename(string $path) : string { - return LocalDirectory::basename($path); + return \basename($path); } /** @@ -582,7 +610,13 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer */ public function getParent() : ContainerInterface { - return new self(self::parent($this->path)); + $uri = clone $this->uri; + $uri->setPath(self::parent($this->path)); + + return new self( + $uri, + '*', true, $this->con + ); } /** @@ -756,12 +790,13 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer * @param string $path Path * @param string $extension Extension * @param string $exclude Pattern to exclude + * @param bool $recursive Recursive * * @return array * * @since 1.0.0 */ - public static function listByExtension($con, string $path, string $extension = '', string $exclude = '') : array + public static function listByExtension($con, string $path, string $extension = '', string $exclude = '', bool $recursive = false) : array { $list = []; $path = \rtrim($path, '\\/'); @@ -770,7 +805,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer return $list; } - $files = self::list($con, $path, empty($extension) ? '*' : '/*.\.' . $extension . '$/'); + $files = self::list($con, $path, empty($extension) ? '*' : '/.*\.' . $extension . '$/', $recursive); foreach ($files as $file) { if (!empty($exclude) && \preg_match('/' . $exclude . '/', $file) === 1) { diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php index 7aa4963d5..298e01f04 100644 --- a/System/File/Ftp/File.php +++ b/System/File/Ftp/File.php @@ -36,33 +36,20 @@ use phpOMS\Uri\HttpUri; */ class File extends FileAbstract implements FileInterface { - /** - * Ftp connection - * - * @var resource - * @since 1.0.0 - */ - private $con; - - /** - * Ftp connection uri. - * - * @var HttpUri - * @since 1.0.0 - */ - private HttpUri $uri; - /** * Create ftp connection * - * @param string $path Ftp path including username and password + * @param string $path Ftp path including username and password + * @param null|resource $con Connection * * @since 1.0.0 */ - public function __construct(string $path) + public function __construct(HttpUri $uri, $con = null) { - $this->uri = new HttpUri($path); - $this->con = self::ftpConnect($this->uri); + $this->uri = $uri; + $this->con = $con ?? self::ftpConnect($this->uri); + + parent::__construct($uri->getPath()); } /** @@ -108,7 +95,7 @@ class File extends FileAbstract implements FileInterface } $pathName = LocalDirectory::name($path); - foreach ($list as $key => $item) { + foreach ($list as $item) { if ($pathName === LocalDirectory::name($item)) { return true; } @@ -314,11 +301,9 @@ class File extends FileAbstract implements FileInterface */ public static function copy($con, string $from, string $to, bool $overwrite = false) : bool { - if (!self::exists($con, $from)) { - return false; - } - - if (!$overwrite && self::exists($con, $to)) { + if (!self::exists($con, $from) + || (!$overwrite && self::exists($con, $to)) + ) { return false; } @@ -337,20 +322,15 @@ class File extends FileAbstract implements FileInterface */ public static function move($con, string $from, string $to, bool $overwrite = false) : bool { - if (!self::exists($con, $from)) { + $result = self::copy($con, $from, $to, $overwrite); + + if (!$result) { return false; } - if ($overwrite && self::exists($con, $to)) { - self::delete($con, $to); - } elseif (self::exists($con, $to)) { - return false; - } - - $copy = self::copy($con, $from, $to); self::delete($con, $from); - return $copy; + return true; } /** @@ -586,19 +566,20 @@ class File extends FileAbstract implements FileInterface } /** - * Get file extension. - * - * @return string - * - * @since 1.0.0 + * {@inheritdoc} + */ + public function getName() : string + { + return \explode('.', $this->name)[0]; + } + + /** + * {@inheritdoc} */ public function getExtension() : string { - /** - * @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium] - * Implement getExtension() - */ + $extension = \explode('.', $this->name); - return ''; + return $extension[1] ?? ''; } } diff --git a/System/File/Ftp/FileAbstract.php b/System/File/Ftp/FileAbstract.php index 58dddb6f8..b1e3784f6 100644 --- a/System/File/Ftp/FileAbstract.php +++ b/System/File/Ftp/FileAbstract.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace phpOMS\System\File\Ftp; use phpOMS\System\File\ContainerInterface; +use phpOMS\Uri\HttpUri; /** * Filesystem class. @@ -28,6 +29,22 @@ use phpOMS\System\File\ContainerInterface; */ abstract class FileAbstract implements ContainerInterface { + /** + * Ftp connection + * + * @var resource + * @since 1.0.0 + */ + protected $con; + + /** + * Ftp uri + * + * @var resource + * @since 1.0.0 + */ + protected HttpUri $uri; + /** * Path. * @@ -92,6 +109,14 @@ abstract class FileAbstract implements ContainerInterface */ protected int $permission = 0755; + /** + * Is directory initialized + * + * @var bool + * @since 1.0.0 + */ + protected bool $isInitialized = false; + /** * Constructor. * @@ -153,7 +178,10 @@ abstract class FileAbstract implements ContainerInterface */ public function parentNode() : Directory { - return new Directory(Directory::parent($this->path)); + $uri = clone $this->uri; + $uri->setPath(Directory::parent($this->path)); + + return new Directory($uri, '*', true, $this->con); } /** @@ -193,8 +221,8 @@ abstract class FileAbstract implements ContainerInterface */ public function index() : void { - $mtime = \filemtime($this->path); - $ctime = \filectime($this->path); + $mtime = \ftp_mdtm($this->con, $this->path); + $ctime = \ftp_mdtm($this->con, $this->path); $this->createdAt->setTimestamp($mtime === false ? 0 : $mtime); $this->changedAt->setTimestamp($ctime === false ? 0 : $ctime); @@ -203,5 +231,7 @@ abstract class FileAbstract implements ContainerInterface $this->owner = $owner === false ? 0 : $owner; $this->permission = (int) \substr(\sprintf('%o', \fileperms($this->path)), -4); + + $this->isInitialized = true; } } diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index 9ef573a37..07632842b 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -47,19 +47,12 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC */ private array $nodes = []; - /** - * Is directory initialized - * - * @var bool - * @since 1.0.0 - */ - private bool $isInitialized = false; - /** * Constructor. * - * @param string $path Path - * @param string $filter Filter + * @param string $path Path + * @param string $filter Filter + * @param bool $initialize Should get initialized during construction * * @since 1.0.0 */ @@ -76,31 +69,38 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC /** * List all files in directory recursively. * - * @param string $path Path - * @param string $filter Filter + * @param string $path Path + * @param string $filter Filter + * @param bool $recursive Recursive list * * @return string[] Array of files and directory with relative path to $path * * @since 1.0.0 */ - public static function list(string $path, string $filter = '*') : array + public static function list(string $path, string $filter = '*', bool $recursive = false) : array { if (!\file_exists($path)) { return []; } - $list = []; - $path = \rtrim($path, '\\/'); - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), - \RecursiveIteratorIterator::SELF_FIRST - ); + $list = []; + $path = \rtrim($path, '\\/'); + + $iterator = $recursive + ? new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), + \RecursiveIteratorIterator::SELF_FIRST) + : new \DirectoryIterator($path); if ($filter !== '*') { $iterator = new \RegexIterator($iterator, '/' . $filter . '/i', \RecursiveRegexIterator::GET_MATCH); } foreach ($iterator as $item) { + if ($item->isDot()) { + continue; + } + $list[] = \str_replace('\\', '/', $iterator->getSubPathname()); } @@ -114,12 +114,13 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC * @param string $path Path * @param string $extension Extension * @param string $exclude Pattern to exclude + * @param bool $recursive Recursive * * @return array * * @since 1.0.0 */ - public static function listByExtension(string $path, string $extension = '', string $exclude = '') : array + public static function listByExtension(string $path, string $extension = '', string $exclude = '', bool $recursive = true) : array { $list = []; $path = \rtrim($path, '\\/'); @@ -128,10 +129,17 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC return $list; } - foreach ($iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), - \RecursiveIteratorIterator::SELF_FIRST) as $item - ) { + $iterator = $recursive + ? new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), + \RecursiveIteratorIterator::SELF_FIRST) + : new \DirectoryIterator($path); + + foreach ($iterator as $item) { + if ($item->isDot()) { + continue; + } + if ((empty($extension) || $item->getExtension() === $extension) && (empty($exclude) || (!(bool) \preg_match('/' . $exclude . '/', $iterator->getSubPathname()))) ) { @@ -151,7 +159,6 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC return; } - $this->isInitialized = true; parent::index(); foreach (\glob($this->path . \DIRECTORY_SEPARATOR . $this->filter) as $filename) { @@ -406,13 +413,13 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC */ public static function move(string $from, string $to, bool $overwrite = false) : bool { - if (!\is_dir($from)) { + if (!\is_dir($from) + || (!$overwrite && \file_exists($to)) + ) { return false; } - if (!$overwrite && \file_exists($to)) { - return false; - } elseif ($overwrite && \file_exists($to)) { + if ($overwrite && \file_exists($to)) { self::delete($to); } diff --git a/System/File/Local/File.php b/System/File/Local/File.php index badc077dc..17465bd5d 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -340,25 +340,23 @@ final class File extends FileAbstract implements FileInterface, LocalContainerIn */ public static function copy(string $from, string $to, bool $overwrite = false) : bool { - if (!\is_file($from)) { + if (!\is_file($from) + || (!$overwrite && \file_exists($to)) + ) { return false; } - if ($overwrite || !\file_exists($to)) { - if (!Directory::exists(\dirname($to))) { - Directory::create(\dirname($to), 0755, true); - } - - if ($overwrite && \file_exists($to)) { - \unlink($to); - } - - \copy($from, $to); - - return true; + if (!Directory::exists(\dirname($to))) { + Directory::create(\dirname($to), 0755, true); } - return false; + if ($overwrite && \file_exists($to)) { + \unlink($to); + } + + \copy($from, $to); + + return true; } /** @@ -372,7 +370,9 @@ final class File extends FileAbstract implements FileInterface, LocalContainerIn return false; } - return self::delete($from); + self::delete($from); + + return true; } /** diff --git a/System/File/Local/FileAbstract.php b/System/File/Local/FileAbstract.php index 170cda776..3d8de10c2 100644 --- a/System/File/Local/FileAbstract.php +++ b/System/File/Local/FileAbstract.php @@ -92,6 +92,14 @@ abstract class FileAbstract implements ContainerInterface */ protected int $permission = 0755; + /** + * Is directory initialized + * + * @var bool + * @since 1.0.0 + */ + protected bool $isInitialized = false; + /** * Constructor. * @@ -203,5 +211,7 @@ abstract class FileAbstract implements ContainerInterface $this->owner = $owner === false ? 0 : $owner; $this->permission = (int) \substr(\sprintf('%o', \fileperms($this->path)), -4); + + $this->isInitialized = true; } } diff --git a/Uri/Argument.php b/Uri/Argument.php index 376bfaa0b..0c4aef228 100644 --- a/Uri/Argument.php +++ b/Uri/Argument.php @@ -161,9 +161,9 @@ final class Argument implements UriInterface { $this->uri = $uri; - $this->setPath($uri); + $this->setInternalPath($uri); $this->setQuery($uri); - $this->setFragment($uri); + $this->setInternalFragment($uri); } /** @@ -175,7 +175,7 @@ final class Argument implements UriInterface * * @since 1.0.0 */ - private function setPath(string $uri) : void + private function setInternalPath(string $uri) : void { $start = \stripos($uri, ':'); @@ -239,7 +239,7 @@ final class Argument implements UriInterface * * @since 1.0.0 */ - private function setFragment(string $uri) : void + private function setInternalFragment(string $uri) : void { $result = \preg_match('/#([a-zA-Z0-9]*)/', $uri, $matches); @@ -288,6 +288,14 @@ final class Argument implements UriInterface return $this->scheme; } + /** + * {@inheritdoc} + */ + public function setScheme(string $scheme) : void + { + $this->scheme = $scheme; + } + /** * {@inheritdoc} */ @@ -296,6 +304,14 @@ final class Argument implements UriInterface return $this->host; } + /** + * {@inheritdoc} + */ + public function setHost(string $host) : void + { + $this->host = $host; + } + /** * {@inheritdoc} */ @@ -304,6 +320,14 @@ final class Argument implements UriInterface return $this->port; } + /** + * {@inheritdoc} + */ + public function setPort(int $port) : void + { + $this->port = $port; + } + /** * {@inheritdoc} */ @@ -312,6 +336,14 @@ final class Argument implements UriInterface return $this->pass; } + /** + * {@inheritdoc} + */ + public function setPass(string $pass) : void + { + $this->pass = $pass; + } + /** * {@inheritdoc} */ @@ -320,6 +352,15 @@ final class Argument implements UriInterface return $this->path; } + /** + * {@inheritdoc} + */ + public function setPath(string $path) : void + { + $this->path = $path; + $this->pathElements = \explode('/', \ltrim($this->path, '/')); + } + /** * Get path offset. * @@ -387,6 +428,14 @@ final class Argument implements UriInterface return $this->fragment; } + /** + * {@inheritdoc} + */ + public function setFragment(string $fragment) : void + { + $this->fragment = $fragment; + } + /** * {@inheritdoc} */ @@ -419,6 +468,14 @@ final class Argument implements UriInterface return $this->user; } + /** + * {@inheritdoc} + */ + public function setUser(string $user) : void + { + $this->user = $user; + } + /** * {@inheritdoc} */ diff --git a/Uri/HttpUri.php b/Uri/HttpUri.php index 2491a735e..7f23e1300 100644 --- a/Uri/HttpUri.php +++ b/Uri/HttpUri.php @@ -277,6 +277,14 @@ final class HttpUri implements UriInterface return $this->scheme; } + /** + * {@inheritdoc} + */ + public function setScheme(string $scheme) : void + { + $this->scheme = $scheme; + } + /** * {@inheritdoc} */ @@ -285,6 +293,14 @@ final class HttpUri implements UriInterface return $this->host; } + /** + * {@inheritdoc} + */ + public function setHost(string $host) : void + { + $this->host = $host; + } + /** * Return the subdomain of a host * @@ -312,6 +328,14 @@ final class HttpUri implements UriInterface return $this->port; } + /** + * {@inheritdoc} + */ + public function setPort(int $port) : void + { + $this->port = $port; + } + /** * {@inheritdoc} */ @@ -320,6 +344,14 @@ final class HttpUri implements UriInterface return $this->pass; } + /** + * {@inheritdoc} + */ + public function setPass(string $pass) : void + { + $this->pass = $pass; + } + /** * {@inheritdoc} */ @@ -328,6 +360,15 @@ final class HttpUri implements UriInterface return $this->path; } + /** + * {@inheritdoc} + */ + public function setPath(string $path) : void + { + $this->path = $path; + $this->pathElements = \explode('/', \ltrim($this->path, '/')); + } + /** * Get path offset. * @@ -395,6 +436,14 @@ final class HttpUri implements UriInterface return $this->fragment; } + /** + * {@inheritdoc} + */ + public function setFragment(string $fragment) : void + { + $this->fragment = $fragment; + } + /** * {@inheritdoc} */ @@ -428,6 +477,14 @@ final class HttpUri implements UriInterface return $this->user; } + /** + * {@inheritdoc} + */ + public function setUser(string $user) : void + { + $this->user = $user; + } + /** * {@inheritdoc} */ diff --git a/Uri/UriInterface.php b/Uri/UriInterface.php index 5e51878a1..2b5fef13b 100644 --- a/Uri/UriInterface.php +++ b/Uri/UriInterface.php @@ -44,6 +44,17 @@ interface UriInterface */ public function getScheme() : string; + /** + * Set scheme. + * + * @param string $scheme Path + * + * @return void + * + * @since 1.0.0 + */ + public function setScheme(string $scheme) : void; + /** * Get authority. * @@ -71,6 +82,17 @@ interface UriInterface */ public function getHost() : string; + /** + * Set host. + * + * @param string $host Host + * + * @return void + * + * @since 1.0.0 + */ + public function setHost(string $host) : void; + /** * Get port. * @@ -80,6 +102,17 @@ interface UriInterface */ public function getPort() : int; + /** + * Set port. + * + * @param int $port Port + * + * @return void + * + * @since 1.0.0 + */ + public function setPort(int $port) : void; + /** * Get path. * @@ -89,6 +122,17 @@ interface UriInterface */ public function getPath() : string; + /** + * Set path. + * + * @param string $path Path + * + * @return void + * + * @since 1.0.0 + */ + public function setPath(string $path) : void; + /** * Get user. * @@ -98,6 +142,17 @@ interface UriInterface */ public function getUser() : string; + /** + * Set user. + * + * @param string $user User + * + * @return void + * + * @since 1.0.0 + */ + public function setUser(string $user) : void; + /** * Get password. * @@ -107,6 +162,17 @@ interface UriInterface */ public function getPass() : string; + /** + * Set pass. + * + * @param string $pass Pass + * + * @return void + * + * @since 1.0.0 + */ + public function setPass(string $pass) : void; + /** * Get root path. * @@ -149,7 +215,7 @@ interface UriInterface * * @since 1.0.0 */ - public function getPathElement(int $pos) : string; + public function getPathElement(int $pos = 0) : string; /** * Get path elements. @@ -189,6 +255,17 @@ interface UriInterface */ public function getFragment() : string; + /** + * Set fragment. + * + * @param string $fragment Fragment + * + * @return void + * + * @since 1.0.0 + */ + public function setFragment(string $fragment) : void; + /** * Get uri. * diff --git a/tests/System/File/Ftp/DirectoryTest.php b/tests/System/File/Ftp/DirectoryTest.php index 306fbe321..98f119edc 100644 --- a/tests/System/File/Ftp/DirectoryTest.php +++ b/tests/System/File/Ftp/DirectoryTest.php @@ -26,17 +26,16 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase { const BASE = 'ftp://test:123456@127.0.0.1:20'; - private $con = null; + private static $con = null; - private $dir = null; + public static function setUpBeforeClass() : void + { + self::$con = Directory::ftpConnect(new HttpUri(self::BASE)); + } protected function setUp() : void { - if ($this->con === null) { - $this->con = Directory::ftpConnect(new HttpUri(self::BASE)); - } - - if ($this->con === false) { + if (self::$con === false) { $this->markTestSkipped( 'The ftp connection is not available.' ); @@ -61,7 +60,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticCreate() : void { $dirPath = __DIR__ . '/test'; - self::assertTrue(Directory::create($this->con, $dirPath)); + self::assertTrue(Directory::create(self::$con, $dirPath)); self::assertTrue(\is_dir($dirPath)); \rmdir($dirPath); @@ -74,8 +73,8 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase */ public function testStaticExists() : void { - self::assertTrue(Directory::exists($this->con, __DIR__)); - self::assertFalse(Directory::exists($this->con, __DIR__ . '/invalid/path/here')); + self::assertTrue(Directory::exists(self::$con, __DIR__)); + self::assertFalse(Directory::exists(self::$con, __DIR__ . '/invalid/path/here')); } /** @@ -86,8 +85,8 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticOverwrite() : void { $dirPath = __DIR__ . '/test'; - self::assertTrue(Directory::create($this->con, $dirPath)); - self::assertFalse(Directory::create($this->con, $dirPath)); + self::assertTrue(Directory::create(self::$con, $dirPath)); + self::assertFalse(Directory::create(self::$con, $dirPath)); \rmdir($dirPath); } @@ -100,12 +99,12 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticSubdir() : void { $dirPath = __DIR__ . '/test/sub/path'; - self::assertTrue(Directory::create($this->con, $dirPath, 0755, true)); - self::assertTrue(Directory::exists($this->con, $dirPath)); + self::assertTrue(Directory::create(self::$con, $dirPath, 0755, true)); + self::assertTrue(Directory::exists(self::$con, $dirPath)); - Directory::delete($this->con, __DIR__ . '/test/sub/path'); - Directory::delete($this->con, __DIR__ . '/test/sub'); - Directory::delete($this->con, __DIR__ . '/test'); + Directory::delete(self::$con, __DIR__ . '/test/sub/path'); + Directory::delete(self::$con, __DIR__ . '/test/sub'); + Directory::delete(self::$con, __DIR__ . '/test'); } /** @@ -115,7 +114,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase */ public function testInvalidStaticSubdir() : void { - self::assertFalse(Directory::create($this->con, __DIR__ . '/invalid/path/here')); + self::assertFalse(Directory::create(self::$con, __DIR__ . '/invalid/path/here')); } /** @@ -188,10 +187,10 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase self::markTestSkipped(); $dirPath = __DIR__ . '/test'; - self::assertTrue(Directory::create($this->con, $dirPath)); + self::assertTrue(Directory::create(self::$con, $dirPath)); $now = new \DateTime('now'); - self::assertEquals($now->format('Y-m-d'), Directory::created($this->con, $dirPath)->format('Y-m-d')); + self::assertEquals($now->format('Y-m-d'), Directory::created(self::$con, $dirPath)->format('Y-m-d')); \rmdir($dirPath); } @@ -207,10 +206,10 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase $dirPath = __DIR__ . '/test'; - self::assertTrue(Directory::create($this->con, $dirPath)); + self::assertTrue(Directory::create(self::$con, $dirPath)); $now = new \DateTime('now'); - self::assertEquals($now->format('Y-m-d'), Directory::changed($this->con, $dirPath)->format('Y-m-d')); + self::assertEquals($now->format('Y-m-d'), Directory::changed(self::$con, $dirPath)->format('Y-m-d')); \rmdir($dirPath); } @@ -224,9 +223,9 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase { $dirPath = __DIR__ . '/test'; - self::assertTrue(Directory::create($this->con, $dirPath)); - self::assertTrue(Directory::delete($this->con, $dirPath)); - self::assertFalse(Directory::exists($this->con, $dirPath)); + self::assertTrue(Directory::create(self::$con, $dirPath)); + self::assertTrue(Directory::delete(self::$con, $dirPath)); + self::assertFalse(Directory::exists(self::$con, $dirPath)); } /** @@ -238,7 +237,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase { $dirPath = __DIR__ . '/test'; - self::assertFalse(Directory::delete($this->con, $dirPath)); + self::assertFalse(Directory::delete(self::$con, $dirPath)); } /** @@ -249,7 +248,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticSizeRecursive() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertGreaterThan(0, Directory::size($this->con, $dirTestPath)); + self::assertGreaterThan(0, Directory::size(self::$con, $dirTestPath)); } /** @@ -260,7 +259,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticSizeRecursive() : void { $dirTestPath = __DIR__ . '/invalid/test/here'; - self::assertEquals(-1, Directory::size($this->con, $dirTestPath)); + self::assertEquals(-1, Directory::size(self::$con, $dirTestPath)); } /** @@ -271,7 +270,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticSize() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertGreaterThan(Directory::size($this->con, $dirTestPath, false), Directory::size($this->con, $dirTestPath)); + self::assertGreaterThan(Directory::size(self::$con, $dirTestPath, false), Directory::size(self::$con, $dirTestPath)); } /** @@ -282,7 +281,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticPermission() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertGreaterThan(0, Directory::permission($this->con, $dirTestPath)); + self::assertGreaterThan(0, Directory::permission(self::$con, $dirTestPath)); } /** @@ -293,7 +292,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticPermission() : void { $dirTestPath = __DIR__ . '/invalid/test/here'; - self::assertEquals(-1, Directory::permission($this->con, $dirTestPath)); + self::assertEquals(-1, Directory::permission(self::$con, $dirTestPath)); } /** @@ -304,30 +303,30 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticCopy() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertTrue(Directory::copy($this->con, $dirTestPath, __DIR__ . '/newdirtest')); + self::assertTrue(Directory::copy(self::$con, $dirTestPath, __DIR__ . '/newdirtest')); self::assertFileExists(__DIR__ . '/newdirtest/sub/path/test3.txt'); - Directory::delete($this->con, __DIR__ . '/newdirtest'); + Directory::delete(self::$con, __DIR__ . '/newdirtest'); } public function testStaticCopyOverwrite() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertTrue(Directory::copy($this->con, $dirTestPath, __DIR__ . '/newdirtest')); - self::assertFalse(Directory::copy($this->con, $dirTestPath, __DIR__ . '/newdirtest', false)); - self::assertTrue(Directory::copy($this->con, $dirTestPath, __DIR__ . '/newdirtest', true)); + self::assertTrue(Directory::copy(self::$con, $dirTestPath, __DIR__ . '/newdirtest')); + self::assertFalse(Directory::copy(self::$con, $dirTestPath, __DIR__ . '/newdirtest', false)); + self::assertTrue(Directory::copy(self::$con, $dirTestPath, __DIR__ . '/newdirtest', true)); self::assertFileExists(__DIR__ . '/newdirtest/sub/path/test3.txt'); - Directory::delete($this->con, __DIR__ . '/newdirtest'); + Directory::delete(self::$con, __DIR__ . '/newdirtest'); } public function testStaticInvalidCopyOverwrite() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertTrue(Directory::copy($this->con, $dirTestPath, __DIR__ . '/newdirtest')); - self::assertFalse(Directory::copy($this->con, $dirTestPath, __DIR__ . '/newdirtest', false)); + self::assertTrue(Directory::copy(self::$con, $dirTestPath, __DIR__ . '/newdirtest')); + self::assertFalse(Directory::copy(self::$con, $dirTestPath, __DIR__ . '/newdirtest', false)); - Directory::delete($this->con, __DIR__ . '/newdirtest'); + Directory::delete(self::$con, __DIR__ . '/newdirtest'); } /** @@ -339,33 +338,33 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase { $dirTestPath = __DIR__ . '/dirtest'; - self::assertTrue(Directory::move($this->con, $dirTestPath, __DIR__ . '/newdirtest')); + self::assertTrue(Directory::move(self::$con, $dirTestPath, __DIR__ . '/newdirtest')); self::assertFileExists(__DIR__ . '/newdirtest/sub/path/test3.txt'); - Directory::move($this->con, __DIR__ . '/newdirtest', $dirTestPath); + Directory::move(self::$con, __DIR__ . '/newdirtest', $dirTestPath); } public function testStaticInvalidMoveOverwrite() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertTrue(Directory::move($this->con, $dirTestPath, __DIR__ . '/newdirtest')); - self::assertFalse(Directory::move($this->con, __DIR__ . '/newdirtest', __DIR__ . '/newdirtest', false)); + self::assertTrue(Directory::move(self::$con, $dirTestPath, __DIR__ . '/newdirtest')); + self::assertFalse(Directory::move(self::$con, __DIR__ . '/newdirtest', __DIR__ . '/newdirtest', false)); - Directory::move($this->con, __DIR__ . '/newdirtest', $dirTestPath); + Directory::move(self::$con, __DIR__ . '/newdirtest', $dirTestPath); } public function testStaticMoveOverwrite() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertTrue(Directory::move($this->con, $dirTestPath, __DIR__ . '/newdirtest')); + self::assertTrue(Directory::move(self::$con, $dirTestPath, __DIR__ . '/newdirtest')); - self::assertTrue(Directory::copy($this->con, __DIR__ . '/newdirtest', $dirTestPath)); - self::assertFalse(Directory::move($this->con, $dirTestPath, __DIR__ . '/newdirtest', false)); - self::assertTrue(Directory::move($this->con, $dirTestPath, __DIR__ . '/newdirtest', true)); + self::assertTrue(Directory::copy(self::$con, __DIR__ . '/newdirtest', $dirTestPath)); + self::assertFalse(Directory::move(self::$con, $dirTestPath, __DIR__ . '/newdirtest', false)); + self::assertTrue(Directory::move(self::$con, $dirTestPath, __DIR__ . '/newdirtest', true)); - Directory::move($this->con, __DIR__ . '/newdirtest', $dirTestPath); + Directory::move(self::$con, __DIR__ . '/newdirtest', $dirTestPath); } /** @@ -376,7 +375,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticCountRecursive() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertEquals(4, Directory::count($this->con, $dirTestPath)); + self::assertEquals(4, Directory::count(self::$con, $dirTestPath)); } /** @@ -387,7 +386,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticCount() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertEquals(1, Directory::count($this->con, $dirTestPath, false)); + self::assertEquals(1, Directory::count(self::$con, $dirTestPath, false)); } /** @@ -398,7 +397,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticCount() : void { $dirTestPath = __DIR__ . '/invalid/path/here'; - self::assertEquals(-1, Directory::count($this->con, $dirTestPath, false)); + self::assertEquals(-1, Directory::count(self::$con, $dirTestPath, false)); } /** @@ -409,19 +408,19 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticListFiles() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertCount(6, Directory::list($this->con, $dirTestPath)); + self::assertCount(6, Directory::list(self::$con, $dirTestPath, '*', true)); } public function testStaticListFilesByExtension() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertCount(3, Directory::listByExtension($this->con, $dirTestPath, 'txt')); + self::assertCount(3, Directory::listByExtension(self::$con, $dirTestPath, 'txt', '', true)); } public function testStaticOwner() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertNotEmpty(Directory::owner($this->con, $dirTestPath)); + self::assertNotEmpty(Directory::owner(self::$con, $dirTestPath)); } public function testDirectoryNameSanitizing() : void @@ -436,12 +435,12 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase */ public function testInvalidListPath() : void { - self::assertEquals([], Directory::list($this->con, __DIR__ . '/invalid.txt')); + self::assertEquals([], Directory::list(self::$con, __DIR__ . '/invalid.txt')); } public function testInvalidListFilesByExtension() : void { - self::assertEquals([], Directory::listByExtension($this->con, __DIR__ . '/invalid/path/here', 'txt')); + self::assertEquals([], Directory::listByExtension(self::$con, __DIR__ . '/invalid/path/here', 'txt')); } /** @@ -451,7 +450,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase */ public function testInvalidCopyPath() : void { - self::assertFalse(Directory::copy($this->con, __DIR__ . '/invalid', __DIR__ . '/invalid2')); + self::assertFalse(Directory::copy(self::$con, __DIR__ . '/invalid', __DIR__ . '/invalid2')); } /** @@ -461,7 +460,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase */ public function testInvalidMovePath() : void { - self::assertFalse(Directory::move($this->con, __DIR__ . '/invalid', __DIR__ . '/invalid2')); + self::assertFalse(Directory::move(self::$con, __DIR__ . '/invalid', __DIR__ . '/invalid2')); } /** @@ -473,7 +472,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase { $this->expectException(\phpOMS\System\File\PathException::class); - Directory::created($this->con, __DIR__ . '/invalid'); + Directory::created(self::$con, __DIR__ . '/invalid'); } /** @@ -485,7 +484,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase { $this->expectException(\phpOMS\System\File\PathException::class); - Directory::changed($this->con, __DIR__ . '/invalid'); + Directory::changed(self::$con, __DIR__ . '/invalid'); } /** @@ -497,13 +496,13 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase { $this->expectException(\phpOMS\System\File\PathException::class); - Directory::owner($this->con, __DIR__ . '/invalid'); + Directory::owner(self::$con, __DIR__ . '/invalid'); } public function testList() : void { $dirTestPath = __DIR__ . '/dirtest'; - $dir = new Directory(new HttpUri(self::BASE . '/' . $dirTestPath)); + $dir = new Directory(new HttpUri(self::BASE . '/' . $dirTestPath), '*', true, self::$con); self::assertEquals([ 'sub', @@ -514,20 +513,20 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeOutput() : void { $dirTestPath = __DIR__ . '/dirtest'; - $dir = new Directory(new HttpUri(self::BASE . '/' . $dirTestPath)); + $dir = new Directory(new HttpUri(self::BASE . '/' . $dirTestPath), '*', true, self::$con); self::assertInstanceOf(Directory::class, $dir->getNode('sub')); } public function testNodeCreate() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__)); - $dir->addNode(new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/nodedir'))); + $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__), '*', true, self::$con); + $dir->addNode(new Directory(new HttpUri(self::BASE . __DIR__ . '/nodedir'))); self::assertTrue(\file_exists(__DIR__ . '/nodedir')); \rmdir(__DIR__ . '/nodedir'); - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/nodedir2')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/nodedir2'), '*', true, self::$con); $dir->createNode(); self::assertTrue(\file_exists(__DIR__ . '/nodedir2')); @@ -536,8 +535,8 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeDelete() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__)); - $dir->addNode(new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/nodedir'))); + $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__), '*', true, self::$con); + $dir->addNode(new Directory(new HttpUri(self::BASE . __DIR__ . '/nodedir'))); self::assertTrue(\file_exists(__DIR__ . '/nodedir')); self::assertTrue($dir->getNode('nodedir')->deleteNode()); @@ -546,8 +545,8 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeCopy() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__)); - $dir->addNode(new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/nodedir'))); + $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__), '*', true, self::$con); + $dir->addNode(new Directory(new HttpUri(self::BASE . __DIR__ . '/nodedir'))); $dir->getNode('nodedir')->copyNode(__DIR__ . '/nodedir2'); self::assertTrue(\file_exists(__DIR__ . '/nodedir2')); @@ -558,8 +557,8 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeMove() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__)); - $dir->addNode(new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/nodedir'))); + $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__), '*', true, self::$con); + $dir->addNode(new Directory(new HttpUri(self::BASE . __DIR__ . '/nodedir'))); $dir->getNode('nodedir')->moveNode(__DIR__ . '/nodedir2'); self::assertFalse(\file_exists(__DIR__ . '/nodedir')); @@ -570,7 +569,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeExists() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__)); + $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__), '*', true, self::$con); self::assertTrue($dir->isExisting()); self::assertTrue($dir->isExisting('dirtest')); @@ -579,28 +578,28 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testParentOutput() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals(__DIR__, $dir->parentNode()->getPath()); } public function testNodeNext() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals(__DIR__ . '/dirtest/test.txt', $dir->next()->getPath()); } public function testNodeCurrent() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals(__DIR__ . '/dirtest/sub', $dir->current()->getPath()); } public function testNodeKey() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals('sub', $dir->key()); $dir->next(); @@ -609,20 +608,20 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeArrayRead() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals('test', $dir['test.txt']->getName()); } public function testNodeArraySet() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__)); - $dir[] = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/nodedir')); + $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__), '*', true, self::$con); + $dir[] = new Directory(new HttpUri(self::BASE . __DIR__ . '/nodedir')); self::assertTrue(\file_exists(__DIR__ . '/nodedir')); \rmdir(__DIR__ . '/nodedir'); - $dir['nodedir'] = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/nodedir')); + $dir['nodedir'] = new Directory(new HttpUri(self::BASE . __DIR__ . '/nodedir')); self::assertTrue(\file_exists(__DIR__ . '/nodedir')); \rmdir(__DIR__ . '/nodedir'); @@ -630,8 +629,8 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeArrayRemove() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__)); - $dir->addNode(new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/nodedir'))); + $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__), '*', true, self::$con); + $dir->addNode(new Directory(new HttpUri(self::BASE . __DIR__ . '/nodedir'))); self::assertTrue(\file_exists(__DIR__ . '/nodedir')); unset($dir['nodedir']); @@ -640,7 +639,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeArrayExists() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__)); + $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__), '*', true, self::$con); self::assertTrue(isset($dir['dirtest'])); self::assertFalse(isset($dir['invalid'])); @@ -649,7 +648,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeCreatedAt() : void { $dirPath = __DIR__ . '/test'; - $dir = new Directory(new HttpUri(self::BASE . '/' . $dirPath)); + $dir = new Directory(new HttpUri(self::BASE . '/' . $dirPath), '*', true, self::$con); self::assertTrue($dir->createNode()); @@ -662,7 +661,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeChangedAt() : void { $dirPath = __DIR__ . '/test'; - $dir = new Directory(new HttpUri(self::BASE . '/' . $dirPath)); + $dir = new Directory(new HttpUri(self::BASE . '/' . $dirPath), '*', true, self::$con); self::assertTrue($dir->createNode()); @@ -674,42 +673,42 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testNodeOwner() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertNotEmpty($dir->getOwner()); } public function testNodePermission() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertGreaterThan(0, $dir->getPermission()); } public function testDirname() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals('dirtest', $dir->next()->getDirname()); } public function testName() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals('test', $dir->next()->getName()); } public function testBaseame() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals('test.txt', $dir->next()->getBasename()); } public function testDirpath() : void { - $dir = new Directory(new HttpUri(self::BASE . '/' . __DIR__ . '/dirtest')); + $dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con); self::assertEquals(__DIR__ . '/dirtest', $dir->next()->getDirpath()); } diff --git a/tests/System/File/Ftp/FileTest.php b/tests/System/File/Ftp/FileTest.php index c689e6322..52771d699 100644 --- a/tests/System/File/Ftp/FileTest.php +++ b/tests/System/File/Ftp/FileTest.php @@ -28,15 +28,16 @@ class FileTest extends \PHPUnit\Framework\TestCase { const BASE = 'ftp://test:123456@127.0.0.1:20'; - private $con = null; + private static $con = null; + + public static function setUpBeforeClass() : void + { + self::$con = File::ftpConnect(new HttpUri(self::BASE)); + } protected function setUp() : void { - if ($this->con === null) { - $this->con = File::ftpConnect(new HttpUri(self::BASE)); - } - - if ($this->con === false) { + if (self::$con === false) { $this->markTestSkipped( 'The ftp connection is not available.' ); @@ -61,11 +62,11 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticCreate() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::create($this->con, $testFile)); + self::assertTrue(File::create(self::$con, $testFile)); self::assertTrue(\is_file($testFile)); self::assertEquals('', \file_get_contents($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -76,11 +77,11 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticCreate() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::create($this->con, $testFile)); - self::assertFalse(File::create($this->con, $testFile)); + self::assertTrue(File::create(self::$con, $testFile)); + self::assertFalse(File::create(self::$con, $testFile)); self::assertTrue(\is_file($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -91,11 +92,11 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticPut() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); + self::assertTrue(File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE)); self::assertTrue(\is_file($testFile)); self::assertEquals('test', \file_get_contents($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -106,7 +107,7 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticCreateReplace() : void { $testFile = __DIR__ . '/test.txt'; - self::assertFalse(File::put($this->con, $testFile, 'test', ContentPutMode::REPLACE)); + self::assertFalse(File::put(self::$con, $testFile, 'test', ContentPutMode::REPLACE)); self::assertfalse(\file_exists($testFile)); } @@ -118,7 +119,7 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticCreateAppend() : void { $testFile = __DIR__ . '/test.txt'; - self::assertFalse(File::put($this->con, $testFile, 'test', ContentPutMode::APPEND)); + self::assertFalse(File::put(self::$con, $testFile, 'test', ContentPutMode::APPEND)); self::assertfalse(\file_exists($testFile)); } @@ -130,7 +131,7 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticCreatePrepend() : void { $testFile = __DIR__ . '/test.txt'; - self::assertFalse(File::put($this->con, $testFile, 'test', ContentPutMode::PREPEND)); + self::assertFalse(File::put(self::$con, $testFile, 'test', ContentPutMode::PREPEND)); self::assertfalse(\file_exists($testFile)); } @@ -141,8 +142,8 @@ class FileTest extends \PHPUnit\Framework\TestCase */ public function testStaticExists() : void { - self::assertTrue(File::exists($this->con, __DIR__ . '/FileTest.php')); - self::assertFalse(File::exists($this->con, __DIR__ . '/invalid/file.txt')); + self::assertTrue(File::exists(self::$con, __DIR__ . '/FileTest.php')); + self::assertFalse(File::exists(self::$con, __DIR__ . '/invalid/file.txt')); } /** @@ -153,12 +154,12 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticReplace() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); - self::assertTrue(File::put($this->con, $testFile, 'test2', ContentPutMode::REPLACE)); + self::assertTrue(File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE)); + self::assertTrue(File::put(self::$con, $testFile, 'test2', ContentPutMode::REPLACE)); self::assertEquals('test2', \file_get_contents($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -169,12 +170,12 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticSetAlias() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); - self::assertTrue(File::set($this->con, $testFile, 'test2')); + self::assertTrue(File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE)); + self::assertTrue(File::set(self::$con, $testFile, 'test2')); self::assertEquals('test2', \file_get_contents($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -185,12 +186,12 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticAppend() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); - self::assertTrue(File::put($this->con, $testFile, 'test2', ContentPutMode::APPEND)); + self::assertTrue(File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE)); + self::assertTrue(File::put(self::$con, $testFile, 'test2', ContentPutMode::APPEND)); self::assertEquals('testtest2', \file_get_contents($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -201,12 +202,12 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticAppendAlias() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); - self::assertTrue(File::append($this->con, $testFile, 'test2')); + self::assertTrue(File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE)); + self::assertTrue(File::append(self::$con, $testFile, 'test2')); self::assertEquals('testtest2', \file_get_contents($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -217,12 +218,12 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticPrepend() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); - self::assertTrue(File::put($this->con, $testFile, 'test2', ContentPutMode::PREPEND)); + self::assertTrue(File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE)); + self::assertTrue(File::put(self::$con, $testFile, 'test2', ContentPutMode::PREPEND)); self::assertEquals('test2test', \file_get_contents($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -233,12 +234,12 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticPrependAlias() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); - self::assertTrue(File::prepend($this->con, $testFile, 'test2')); + self::assertTrue(File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE)); + self::assertTrue(File::prepend(self::$con, $testFile, 'test2')); self::assertEquals('test2test', \file_get_contents($testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -249,10 +250,10 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticGet() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); - self::assertEquals('test', File::get($this->con, $testFile)); + self::assertTrue(File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE)); + self::assertEquals('test', File::get(self::$con, $testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -347,12 +348,12 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticCreatedAt() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::create($this->con, $testFile)); + self::assertTrue(File::create(self::$con, $testFile)); $now = new \DateTime('now'); - self::assertEquals($now->format('Y-m-d'), File::created($this->con, $testFile)->format('Y-m-d')); + self::assertEquals($now->format('Y-m-d'), File::created(self::$con, $testFile)->format('Y-m-d')); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -363,12 +364,12 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticChangedAt() : void { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::create($this->con, $testFile)); + self::assertTrue(File::create(self::$con, $testFile)); $now = new \DateTime('now'); - self::assertEquals($now->format('Y-m-d'), File::changed($this->con, $testFile)->format('Y-m-d')); + self::assertEquals($now->format('Y-m-d'), File::changed(self::$con, $testFile)->format('Y-m-d')); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -380,9 +381,9 @@ class FileTest extends \PHPUnit\Framework\TestCase { $testFile = __DIR__ . '/test.txt'; - self::assertTrue(File::create($this->con, $testFile)); - self::assertTrue(File::delete($this->con, $testFile)); - self::assertFalse(File::exists($this->con, $testFile)); + self::assertTrue(File::create(self::$con, $testFile)); + self::assertTrue(File::delete(self::$con, $testFile)); + self::assertFalse(File::exists(self::$con, $testFile)); } /** @@ -394,7 +395,7 @@ class FileTest extends \PHPUnit\Framework\TestCase { $testFile = __DIR__ . '/test.txt'; - self::assertFalse(File::delete($this->con, $testFile)); + self::assertFalse(File::delete(self::$con, $testFile)); } /** @@ -405,11 +406,11 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticSize() : void { $testFile = __DIR__ . '/test.txt'; - File::put($this->con, $testFile, 'test', ContentPutMode::CREATE); + File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE); - self::assertGreaterThan(0, File::size($this->con, $testFile)); + self::assertGreaterThan(0, File::size(self::$con, $testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -420,11 +421,11 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testStaticPermission() : void { $testFile = __DIR__ . '/test.txt'; - File::put($this->con, $testFile, 'test', ContentPutMode::CREATE); + File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE); - self::assertGreaterThan(0, File::permission($this->con, $testFile)); + self::assertGreaterThan(0, File::permission(self::$con, $testFile)); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -435,7 +436,7 @@ class FileTest extends \PHPUnit\Framework\TestCase public function testInvalidStaticPermission() : void { $testFile = __DIR__ . '/test.txt'; - self::assertEquals(-1, File::permission($this->con, $testFile)); + self::assertEquals(-1, File::permission(self::$con, $testFile)); } /** @@ -448,17 +449,17 @@ class FileTest extends \PHPUnit\Framework\TestCase $testFile = __DIR__ . '/test.txt'; $newPath = __DIR__ . '/sub/path/testing.txt'; - File::put($this->con, $testFile, 'test', ContentPutMode::CREATE); + File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE); - self::assertTrue(File::copy($this->con, $testFile, $newPath)); - self::assertTrue(File::exists($this->con, $newPath)); - self::assertEquals('test', File::get($this->con, $newPath)); + self::assertTrue(File::copy(self::$con, $testFile, $newPath)); + self::assertTrue(File::exists(self::$con, $newPath)); + self::assertEquals('test', File::get(self::$con, $newPath)); - File::delete($this->con, $newPath); - Directory::delete($this->con, __DIR__ . '/sub/path/'); - Directory::delete($this->con, __DIR__ . '/sub/'); + File::delete(self::$con, $newPath); + Directory::delete(self::$con, __DIR__ . '/sub/path/'); + Directory::delete(self::$con, __DIR__ . '/sub/'); - File::delete($this->con, $testFile); + File::delete(self::$con, $testFile); } /** @@ -471,14 +472,14 @@ class FileTest extends \PHPUnit\Framework\TestCase $testFile = __DIR__ . '/test.txt'; $newPath = __DIR__ . '/test2.txt'; - File::put($this->con, $testFile, 'test', ContentPutMode::CREATE); - File::put($this->con, $newPath, 'test2', ContentPutMode::CREATE); + File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE); + File::put(self::$con, $newPath, 'test2', ContentPutMode::CREATE); - self::assertFalse(File::copy($this->con, $testFile, $newPath)); - self::assertEquals('test2', File::get($this->con, $newPath)); + self::assertFalse(File::copy(self::$con, $testFile, $newPath)); + self::assertEquals('test2', File::get(self::$con, $newPath)); - File::delete($this->con, $newPath); - File::delete($this->con, $testFile); + File::delete(self::$con, $newPath); + File::delete(self::$con, $testFile); } /** @@ -491,14 +492,14 @@ class FileTest extends \PHPUnit\Framework\TestCase $testFile = __DIR__ . '/test.txt'; $newPath = __DIR__ . '/test2.txt'; - File::put($this->con, $testFile, 'test', ContentPutMode::CREATE); - File::put($this->con, $newPath, 'test2', ContentPutMode::CREATE); + File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE); + File::put(self::$con, $newPath, 'test2', ContentPutMode::CREATE); - self::assertTrue(File::copy($this->con, $testFile, $newPath, true)); - self::assertEquals('test', File::get($this->con, $newPath)); + self::assertTrue(File::copy(self::$con, $testFile, $newPath, true)); + self::assertEquals('test', File::get(self::$con, $newPath)); - File::delete($this->con, $newPath); - File::delete($this->con, $testFile); + File::delete(self::$con, $newPath); + File::delete(self::$con, $testFile); } /** @@ -511,14 +512,14 @@ class FileTest extends \PHPUnit\Framework\TestCase $testFile = __DIR__ . '/test.txt'; $newPath = __DIR__ . '/sub/path/testing.txt'; - File::put($this->con, $testFile, 'test', ContentPutMode::CREATE); + File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE); - self::assertTrue(File::move($this->con, $testFile, $newPath)); - self::assertFalse(File::exists($this->con, $testFile)); - self::assertTrue(File::exists($this->con, $newPath)); - self::assertEquals('test', File::get($this->con, $newPath)); + self::assertTrue(File::move(self::$con, $testFile, $newPath)); + self::assertFalse(File::exists(self::$con, $testFile)); + self::assertTrue(File::exists(self::$con, $newPath)); + self::assertEquals('test', File::get(self::$con, $newPath)); - Directory::delete($this->con, __DIR__ . '/sub'); + Directory::delete(self::$con, __DIR__ . '/sub'); } /** @@ -531,15 +532,15 @@ class FileTest extends \PHPUnit\Framework\TestCase $testFile = __DIR__ . '/test.txt'; $newPath = __DIR__ . '/test2.txt'; - File::put($this->con, $testFile, 'test', ContentPutMode::CREATE); - File::put($this->con, $newPath, 'test2', ContentPutMode::CREATE); + File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE); + File::put(self::$con, $newPath, 'test2', ContentPutMode::CREATE); - self::assertFalse(File::move($this->con, $testFile, $newPath)); - self::assertTrue(File::exists($this->con, $testFile)); - self::assertEquals('test2', File::get($this->con, $newPath)); + self::assertFalse(File::move(self::$con, $testFile, $newPath)); + self::assertTrue(File::exists(self::$con, $testFile)); + self::assertEquals('test2', File::get(self::$con, $newPath)); - File::delete($this->con, $newPath); - File::delete($this->con, $testFile); + File::delete(self::$con, $newPath); + File::delete(self::$con, $testFile); } /** @@ -552,20 +553,20 @@ class FileTest extends \PHPUnit\Framework\TestCase $testFile = __DIR__ . '/test.txt'; $newPath = __DIR__ . '/test2.txt'; - File::put($this->con, $testFile, 'test', ContentPutMode::CREATE); - File::put($this->con, $newPath, 'test2', ContentPutMode::CREATE); + File::put(self::$con, $testFile, 'test', ContentPutMode::CREATE); + File::put(self::$con, $newPath, 'test2', ContentPutMode::CREATE); - self::assertTrue(File::move($this->con, $testFile, $newPath, true)); - self::assertFalse(File::exists($this->con, $testFile)); - self::assertEquals('test', File::get($this->con, $newPath)); + self::assertTrue(File::move(self::$con, $testFile, $newPath, true)); + self::assertFalse(File::exists(self::$con, $testFile)); + self::assertEquals('test', File::get(self::$con, $newPath)); - File::delete($this->con, $newPath); + File::delete(self::$con, $newPath); } public function testStaticOwner() : void { $dirTestPath = __DIR__ . '/dirtest/test.txt'; - self::assertNotEmpty(File::owner($this->con, $dirTestPath)); + self::assertNotEmpty(File::owner(self::$con, $dirTestPath)); } public function testFileNameSanitizing() : void @@ -580,7 +581,7 @@ class FileTest extends \PHPUnit\Framework\TestCase */ public function testInvalidSizePath() : void { - self::assertEquals(-1, File::size($this->con, __DIR__ . '/invalid.txt')); + self::assertEquals(-1, File::size(self::$con, __DIR__ . '/invalid.txt')); } /** @@ -590,7 +591,7 @@ class FileTest extends \PHPUnit\Framework\TestCase */ public function testInvalidCopyPath() : void { - self::assertFalse(File::copy($this->con, __DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt')); + self::assertFalse(File::copy(self::$con, __DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt')); } /** @@ -600,7 +601,7 @@ class FileTest extends \PHPUnit\Framework\TestCase */ public function testInvalidMovePath() : void { - self::assertFalse(File::move($this->con, __DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt')); + self::assertFalse(File::move(self::$con, __DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt')); } /** @@ -612,7 +613,7 @@ class FileTest extends \PHPUnit\Framework\TestCase { $this->expectException(\phpOMS\System\File\PathException::class); - File::get($this->con, __DIR__ . '/invalid.txt'); + File::get(self::$con, __DIR__ . '/invalid.txt'); } /** @@ -624,7 +625,7 @@ class FileTest extends \PHPUnit\Framework\TestCase { $this->expectException(\phpOMS\System\File\PathException::class); - File::created($this->con, __DIR__ . '/invalid.txt'); + File::created(self::$con, __DIR__ . '/invalid.txt'); } /** @@ -636,7 +637,7 @@ class FileTest extends \PHPUnit\Framework\TestCase { $this->expectException(\phpOMS\System\File\PathException::class); - File::changed($this->con, __DIR__ . '/invalid.txt'); + File::changed(self::$con, __DIR__ . '/invalid.txt'); } /** @@ -648,7 +649,7 @@ class FileTest extends \PHPUnit\Framework\TestCase { $this->expectException(\phpOMS\System\File\PathException::class); - File::owner($this->con, __DIR__ . '/invalid.txt'); + File::owner(self::$con, __DIR__ . '/invalid.txt'); } public function testNodeInputOutput() : void diff --git a/tests/System/File/Local/DirectoryTest.php b/tests/System/File/Local/DirectoryTest.php index 055f2a731..c4ac7cb7d 100644 --- a/tests/System/File/Local/DirectoryTest.php +++ b/tests/System/File/Local/DirectoryTest.php @@ -397,8 +397,10 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase public function testStaticListFiles() : void { $dirTestPath = __DIR__ . '/dirtest'; - self::assertCount(6, Directory::list($dirTestPath)); - self::assertEquals(['sub/test2.txt', 'sub/test4.md', 'sub/path/test3.txt'], Directory::list($dirTestPath, 'test[0-9]+.*')); + self::assertCount(6, Directory::list($dirTestPath, '*', true)); + self::assertEquals(['sub/test2.txt', 'sub/test4.md', 'sub/path/test3.txt'], Directory::list($dirTestPath, 'test[0-9]+.*', true)); + + self::assertCount(2, Directory::list($dirTestPath, '*', false)); } /** diff --git a/tests/Uri/ArgumentTest.php b/tests/Uri/ArgumentTest.php index d4ac2c8c3..e600f76b0 100644 --- a/tests/Uri/ArgumentTest.php +++ b/tests/Uri/ArgumentTest.php @@ -65,7 +65,7 @@ class ArgumentTest extends \PHPUnit\Framework\TestCase * @covers phpOMS\Uri\Argument * @group framework */ - public function testPathInputOutput() : void + public function testParsePathInputOutput() : void { $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); @@ -77,6 +77,54 @@ class ArgumentTest extends \PHPUnit\Framework\TestCase ); } + public function testPathInputOutput() : void + { + $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); + + $obj->setPath('modules/admin/new/path'); + self::assertEquals('modules/admin/new/path', $obj->getPath()); + } + + public function testSchemeInputOutput() : void + { + $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); + + $obj->setScheme('scheme'); + self::assertEquals('scheme', $obj->getScheme()); + } + + public function testUserInputOutput() : void + { + $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); + + $obj->setUser('user'); + self::assertEquals('user', $obj->getUser()); + } + + public function testPassInputOutput() : void + { + $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); + + $obj->setPass('pass'); + self::assertEquals('pass', $obj->getPass()); + } + + public function testHostInputOutput() : void + { + $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); + + $obj->setHost('host'); + self::assertEquals('host', $obj->getHost()); + } + + public function testPortInputOutput() : void + { + $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); + + $obj->setPort(123); + self::assertEquals(123, $obj->getPort()); + } + /** * @testdox The path offset can be set and returned * @covers phpOMS\Uri\Argument @@ -126,6 +174,9 @@ class ArgumentTest extends \PHPUnit\Framework\TestCase $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); self::assertEquals('frag', $obj->getFragment()); + + $obj->setFragment('frag2'); + self::assertEquals('frag2', $obj->getFragment()); } /** diff --git a/tests/Uri/HttpUriTest.php b/tests/Uri/HttpUriTest.php index af75b9d42..6419bed56 100644 --- a/tests/Uri/HttpUriTest.php +++ b/tests/Uri/HttpUriTest.php @@ -60,11 +60,24 @@ class HttpUriTest extends \PHPUnit\Framework\TestCase * @covers phpOMS\Uri\HttpUri * @group framework */ - public function testSchemaInputOutput() : void + public function testSchemeInputOutput() : void { $obj = new HttpUri('https://www.google.com/test/path.php?para1=abc¶2=2#frag'); self::assertEquals('https', $obj->getScheme()); + + $obj->setScheme('ftp'); + self::assertEquals('ftp', $obj->getScheme()); + } + + public function testPortInputOutput() : void + { + $obj = new HttpUri('https://www.google.com:21/test/path.php?para1=abc¶2=2#frag'); + + self::assertEquals(21, $obj->getPort()); + + $obj->setPort(123); + self::assertEquals(123, $obj->getPort()); } /** @@ -77,6 +90,9 @@ class HttpUriTest extends \PHPUnit\Framework\TestCase $obj = new HttpUri('https://www.google.com/test/path.php?para1=abc¶2=2#frag'); self::assertEquals('www.google.com', $obj->getHost()); + + $obj->setHost('127.0.0.1'); + self::assertEquals('127.0.0.1', $obj->getHost()); } /** @@ -89,6 +105,9 @@ class HttpUriTest extends \PHPUnit\Framework\TestCase $obj = new HttpUri('https://username:password@google.com/test/path.php?para1=abc¶2=2#frag'); self::assertEquals('username', $obj->getUser()); + + $obj->setUser('user'); + self::assertEquals('user', $obj->getUser()); } /** @@ -101,6 +120,9 @@ class HttpUriTest extends \PHPUnit\Framework\TestCase $obj = new HttpUri('https://username:password@google.com/test/path.php?para1=abc¶2=2#frag'); self::assertEquals('password', $obj->getPass()); + + $obj->setPass('pass'); + self::assertEquals('pass', $obj->getPass()); } /** @@ -164,6 +186,14 @@ class HttpUriTest extends \PHPUnit\Framework\TestCase self::assertEquals('a', $obj->getRootPath()); } + public function testPathInputOutput() : void + { + $obj = new HttpUri('https://www.google.com/test/path.php?para1=abc¶2=2#frag'); + + $obj->setPath('new'); + self::assertEquals('new', $obj->getPath()); + } + /** * @testdox The path offset can be set and returned * @covers phpOMS\Uri\HttpUri @@ -216,6 +246,9 @@ class HttpUriTest extends \PHPUnit\Framework\TestCase { $obj = new HttpUri('https://www.google.com/test/path.php?para1=abc¶2=2#frag'); self::assertEquals('frag', $obj->getFragment()); + + $obj->setFragment('frag2'); + self::assertEquals('frag2', $obj->getFragment()); } /**