tests and cleanup

This commit is contained in:
Dennis Eichhorn 2019-11-30 19:45:16 +01:00
parent c2d7d841de
commit 5e50b896fe
58 changed files with 3569 additions and 569 deletions

View File

@ -215,7 +215,6 @@ class HttpSession implements SessionInterface
*/ */
private function destroy() : void private function destroy() : void
{ {
if (\session_status() !== \PHP_SESSION_NONE) { if (\session_status() !== \PHP_SESSION_NONE) {
\session_destroy(); \session_destroy();
$this->sessionData = []; $this->sessionData = [];

View File

@ -158,7 +158,7 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory
public static function size($con, string $dir, bool $recursive = true) : int public static function size($con, string $dir, bool $recursive = true) : int
{ {
if (!self::exists($con, $dir)) { if (!self::exists($con, $dir)) {
throw new PathException($dir); return -1;
} }
$countSize = 0; $countSize = 0;
@ -189,7 +189,7 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory
public static function count($con, string $path, bool $recursive = true, array $ignore = []) : int public static function count($con, string $path, bool $recursive = true, array $ignore = []) : int
{ {
if (!self::exists($con, $path)) { if (!self::exists($con, $path)) {
throw new PathException($path); return -1;
} }
$size = 0; $size = 0;
@ -222,6 +222,12 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory
*/ */
public static function delete($con, string $path) : bool public static function delete($con, string $path) : bool
{ {
$path = \rtrim($path, '\\/');
if (!self::exists($con, $path)) {
return false;
}
$list = self::parseRawList($con, $path); $list = self::parseRawList($con, $path);
foreach ($list as $key => $item) { foreach ($list as $key => $item) {
@ -324,7 +330,7 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory
public static function permission($con, string $path) : int public static function permission($con, string $path) : int
{ {
if (!self::exists($con, $path)) { if (!self::exists($con, $path)) {
throw new PathException($path); return -1;
} }
return self::parseRawList($con, self::parent($path))[$path]['permission']; return self::parseRawList($con, self::parent($path))[$path]['permission'];

View File

@ -209,7 +209,7 @@ class File extends FileAbstract implements FileInterface
*/ */
public static function parent(string $path) : string public static function parent(string $path) : string
{ {
return Directory::parent($path); return Directory::parent(\dirname($path));
} }
/** /**
@ -251,7 +251,7 @@ class File extends FileAbstract implements FileInterface
public static function size($con, string $path, bool $recursive = true) : int public static function size($con, string $path, bool $recursive = true) : int
{ {
if (!self::exists($con, $path)) { if (!self::exists($con, $path)) {
throw new PathException($path); return -1;
} }
return \ftp_size($con, $path); return \ftp_size($con, $path);
@ -266,7 +266,7 @@ class File extends FileAbstract implements FileInterface
throw new PathException($path); throw new PathException($path);
} }
return Directory::parseRawList($con, self::parent($path))[$path]['user']; return Directory::parseRawList($con, self::dirpath($path))[$path]['user'];
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -274,10 +274,10 @@ class File extends FileAbstract implements FileInterface
public static function permission($con, string $path) : int public static function permission($con, string $path) : int
{ {
if (!self::exists($con, $path)) { if (!self::exists($con, $path)) {
throw new PathException($path); return -1;
} }
return Directory::parseRawList($con, self::parent($path))[$path]['permission']; return Directory::parseRawList($con, self::dirpath($path))[$path]['permission'];
} }
/** /**

View File

@ -115,6 +115,10 @@ final class Directory extends FileAbstract implements LocalContainerInterface, D
$list = []; $list = [];
$path = \rtrim($path, '\\/'); $path = \rtrim($path, '\\/');
if (!\file_exists($path)) {
return $list;
}
foreach ($iterator = new \RecursiveIteratorIterator( foreach ($iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST) as $item \RecursiveIteratorIterator::SELF_FIRST) as $item
@ -163,7 +167,7 @@ final class Directory extends FileAbstract implements LocalContainerInterface, D
public static function size(string $dir, bool $recursive = true) : int public static function size(string $dir, bool $recursive = true) : int
{ {
if (!\file_exists($dir) || !\is_readable($dir)) { if (!\file_exists($dir) || !\is_readable($dir)) {
throw new PathException($dir); return -1;
} }
$countSize = 0; $countSize = 0;
@ -205,7 +209,7 @@ final class Directory extends FileAbstract implements LocalContainerInterface, D
public static function count(string $path, bool $recursive = true, array $ignore = []) : int public static function count(string $path, bool $recursive = true, array $ignore = []) : int
{ {
if (!\file_exists($path)) { if (!\file_exists($path)) {
throw new PathException($path); return -1;
} }
$size = 0; $size = 0;
@ -238,7 +242,7 @@ final class Directory extends FileAbstract implements LocalContainerInterface, D
*/ */
public static function delete(string $path) : bool public static function delete(string $path) : bool
{ {
if (empty($path)) { if (empty($path) || !\file_exists($path)) {
return false; return false;
} }
@ -329,7 +333,7 @@ final class Directory extends FileAbstract implements LocalContainerInterface, D
public static function permission(string $path) : int public static function permission(string $path) : int
{ {
if (!\file_exists($path)) { if (!\file_exists($path)) {
throw new PathException($path); return -1;
} }
return (int) \fileperms($path); return (int) \fileperms($path);

View File

@ -255,7 +255,7 @@ final class File extends FileAbstract implements LocalContainerInterface, FileIn
public static function size(string $path, bool $recursive = true) : int public static function size(string $path, bool $recursive = true) : int
{ {
if (!\file_exists($path)) { if (!\file_exists($path)) {
return 0; return -1;
} }
return (int) \filesize($path); return (int) \filesize($path);
@ -279,7 +279,7 @@ final class File extends FileAbstract implements LocalContainerInterface, FileIn
public static function permission(string $path) : int public static function permission(string $path) : int
{ {
if (!\file_exists($path)) { if (!\file_exists($path)) {
throw new PathException($path); return -1;
} }
return (int) \fileperms($path); return (int) \fileperms($path);

View File

@ -92,7 +92,7 @@ final class UriFactory
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function setQuery(string $key, string $value, bool $overwrite = true) : bool public static function setQuery(string $key, string $value, bool $overwrite = false) : bool
{ {
if ($overwrite || !isset(self::$uri[$key])) { if ($overwrite || !isset(self::$uri[$key])) {
self::$uri[$key] = $value; self::$uri[$key] = $value;

View File

@ -94,7 +94,7 @@ class Numeric
return $newOutput; return $newOutput;
} }
$base10 = (int) ($fromBaseInput != '0123456789' ? self::convertBase($numberInput, $fromBaseInput, '0123456789') : $numberInput); $base10 = (int) ($fromBaseInput !== '0123456789' ? self::convertBase($numberInput, $fromBaseInput, '0123456789') : $numberInput);
if ($base10 < \strlen($toBaseInput)) { if ($base10 < \strlen($toBaseInput)) {
return $toBase[$base10]; return $toBase[$base10];

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace phpOMS\Utils\IO; namespace phpOMS\Utils\IO;
use phpOMS\Utils\IO\Csv\CsvInterface; use phpOMS\Utils\IO\Csv\CsvInterface;
use phpOMS\Utils\IO\Excel\ExcelInterface; use phpOMS\Utils\IO\Spreadsheet\SpreadsheetInterface;
use phpOMS\Utils\IO\Json\JsonInterface; use phpOMS\Utils\IO\Json\JsonInterface;
use phpOMS\Utils\IO\Pdf\PdfInterface; use phpOMS\Utils\IO\Pdf\PdfInterface;
@ -27,6 +27,6 @@ use phpOMS\Utils\IO\Pdf\PdfInterface;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
interface ExchangeInterface extends CsvInterface, JsonInterface, ExcelInterface, PdfInterface interface ExchangeInterface extends CsvInterface, JsonInterface, SpreadsheetInterface, PdfInterface
{ {
} }

View File

@ -4,7 +4,7 @@
* *
* PHP Version 7.4 * PHP Version 7.4
* *
* @package phpOMS\Utils\IO\Excel * @package phpOMS\Utils\IO\Spreadsheet
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 1.0.0
@ -12,7 +12,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\Utils\IO\Excel; namespace phpOMS\Utils\IO\Spreadsheet;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
@ -20,14 +20,14 @@ use phpOMS\Utils\IO\IODatabaseMapper;
use phpOMS\Utils\StringUtils; use phpOMS\Utils\StringUtils;
/** /**
* Excel database mapper. * Spreadsheet database mapper.
* *
* @package phpOMS\Utils\IO\Excel * @package phpOMS\Utils\IO\Spreadsheet
* @license OMS License 1.0 * @license OMS License 1.0
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class ExcelDatabaseMapper implements IODatabaseMapper class SpreadsheetDatabaseMapper implements IODatabaseMapper
{ {
/** /**
* Database connection * Database connection

View File

@ -4,7 +4,7 @@
* *
* PHP Version 7.4 * PHP Version 7.4
* *
* @package phpOMS\Utils\IO\Excel * @package phpOMS\Utils\IO\Spreadsheet
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 1.0.0
@ -12,21 +12,21 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\Utils\IO\Excel; namespace phpOMS\Utils\IO\Spreadsheet;
/** /**
* Excel interface. * Spreadsheet interface.
* *
* @package phpOMS\Utils\IO\Excel * @package phpOMS\Utils\IO\Spreadsheet
* @license OMS License 1.0 * @license OMS License 1.0
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
interface ExcelInterface interface SpreadsheetInterface
{ {
/** /**
* Export Excel. * Export Spreadsheet.
* *
* @param string $path Path to export * @param string $path Path to export
* *
@ -34,10 +34,10 @@ interface ExcelInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function exportExcel($path) : void; public function exportSpreadsheet($path) : void;
/** /**
* Import Excel. * Import Spreadsheet.
* *
* @param string $path Path to import * @param string $path Path to import
* *
@ -45,5 +45,5 @@ interface ExcelInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function importExcel($path) : void; public function importSpreadsheet($path) : void;
} }

View File

@ -35,7 +35,7 @@ interface ArchiveInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function pack($sources, string $destination, bool $overwrite = true) : bool; public static function pack($sources, string $destination, bool $overwrite = false) : bool;
/** /**
* Unpack archive. * Unpack archive.

View File

@ -29,7 +29,7 @@ class Gz implements ArchiveInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function pack($source, string $destination, bool $overwrite = true) : bool public static function pack($source, string $destination, bool $overwrite = false) : bool
{ {
$destination = \str_replace('\\', '/', $destination); $destination = \str_replace('\\', '/', $destination);
if (!$overwrite && \file_exists($destination)) { if (!$overwrite && \file_exists($destination)) {
@ -58,7 +58,7 @@ class Gz implements ArchiveInterface
public static function unpack(string $source, string $destination) : bool public static function unpack(string $source, string $destination) : bool
{ {
$destination = \str_replace('\\', '/', $destination); $destination = \str_replace('\\', '/', $destination);
if (\file_exists($destination)) { if (\file_exists($destination) || !\file_exists($source)) {
return false; return false;
} }

View File

@ -31,7 +31,7 @@ class Tar implements ArchiveInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function pack($sources, string $destination, bool $overwrite = true) : bool public static function pack($sources, string $destination, bool $overwrite = false) : bool
{ {
$destination = FileUtils::absolute(\str_replace('\\', '/', $destination)); $destination = FileUtils::absolute(\str_replace('\\', '/', $destination));

View File

@ -31,7 +31,7 @@ class TarGz implements ArchiveInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function pack($source, string $destination, bool $overwrite = true) : bool public static function pack($source, string $destination, bool $overwrite = false) : bool
{ {
if (!$overwrite && \file_exists($destination)) { if (!$overwrite && \file_exists($destination)) {
return false; return false;

View File

@ -32,7 +32,7 @@ class Zip implements ArchiveInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function pack($sources, string $destination, bool $overwrite = true) : bool public static function pack($sources, string $destination, bool $overwrite = false) : bool
{ {
$destination = FileUtils::absolute(\str_replace('\\', '/', $destination)); $destination = FileUtils::absolute(\str_replace('\\', '/', $destination));

View File

@ -18,10 +18,16 @@ use phpOMS\System\File\ExtensionType;
use phpOMS\System\File\FileUtils; use phpOMS\System\File\FileUtils;
/** /**
* @testdox phpOMS\tests\System\File\FileUtilsTest: File utilities
*
* @internal * @internal
*/ */
class FileUtilsTest extends \PHPUnit\Framework\TestCase class FileUtilsTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox File extensions can be categorized
* @covers phpOMS\System\File\FileUtils
*/
public function testExtension() : void public function testExtension() : void
{ {
self::assertEquals(ExtensionType::UNKNOWN, FileUtils::getExtensionType('test')); self::assertEquals(ExtensionType::UNKNOWN, FileUtils::getExtensionType('test'));
@ -40,11 +46,19 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
self::assertEquals(ExtensionType::DIRECTORY, FileUtils::getExtensionType('/')); self::assertEquals(ExtensionType::DIRECTORY, FileUtils::getExtensionType('/'));
} }
/**
* @testdox A relative path can be turned into an absolute path
* @covers phpOMS\System\File\FileUtils
*/
public function testAbsolute() : void public function testAbsolute() : void
{ {
self::assertEquals('/test/ative', FileUtils::absolute('/test/path/for/../rel/../../ative')); self::assertEquals('/test/ative', FileUtils::absolute('/test/path/for/../rel/../../ative'));
} }
/**
* @testdox Permissions can be turned into ocal values
* @covers phpOMS\System\File\FileUtils
*/
public function testPermissionToOctal() : void public function testPermissionToOctal() : void
{ {
self::assertEquals(0742, FileUtils::permissionToOctal('rwxr---w-')); self::assertEquals(0742, FileUtils::permissionToOctal('rwxr---w-'));

View File

@ -18,6 +18,8 @@ use phpOMS\System\File\Ftp\Directory;
use phpOMS\Uri\Http; use phpOMS\Uri\Http;
/** /**
* @testdox phpOMS\tests\System\File\Ftp\DirectoryTest: Directory handler for a ftp server
*
* @internal * @internal
*/ */
class DirectoryTest extends \PHPUnit\Framework\TestCase class DirectoryTest extends \PHPUnit\Framework\TestCase
@ -39,118 +41,354 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
} }
} }
public function testStatic() : void /**
* @testdox A directory can be created
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticCreate() : void
{
$dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create($this->con, $dirPath));
self::assertTrue(\is_dir($dirPath));
\rmdir($dirPath);
}
/**
* @testdox A directory can be checked for existence
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticExists() : void
{
self::assertTrue(Directory::exists($this->con, __DIR__));
self::assertFalse(Directory::exists($this->con, __DIR__ . '/invalid/path/here'));
}
/**
* @testdox An existing directory cannot be overwritten
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidStaticOverwrite() : void
{ {
self::assertNotFalse($this->con);
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create($this->con, $dirPath)); self::assertTrue(Directory::create($this->con, $dirPath));
self::assertTrue(Directory::exists($this->con, $dirPath));
self::assertFalse(Directory::create($this->con, $dirPath)); self::assertFalse(Directory::create($this->con, $dirPath));
self::assertFalse(Directory::create($this->con, __DIR__ . '/test/sub/path'));
self::assertTrue(Directory::create($this->con, __DIR__ . '/test/sub/path', 0755, true)); \rmdir($dirPath);
self::assertTrue(Directory::exists($this->con, __DIR__ . '/test/sub/path')); }
/**
* @testdox A directory can be forced to be created recursively
* @covers phpOMS\System\File\Ftp\Directory
*/
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));
Directory::delete($this->con, __DIR__ . '/test/sub/path');
Directory::delete($this->con, __DIR__ . '/test/sub');
Directory::delete($this->con, __DIR__ . '/test');
}
/**
* @testdox By default a directory is not created recursively
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidStaticSubdir() : void
{
self::assertFalse(Directory::create($this->con, __DIR__ . '/invalid/path/here'));
}
/**
* @testdox The name of a directory is just its name without its path
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticName() : void
{
$dirPath = __DIR__ . '/test';
self::assertEquals('test', Directory::name($dirPath)); self::assertEquals('test', Directory::name($dirPath));
}
/**
* @testdox The basename is the same as the name of the directory
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticBasename() : void
{
$dirPath = __DIR__ . '/test';
self::assertEquals('test', Directory::basename($dirPath)); self::assertEquals('test', Directory::basename($dirPath));
}
/**
* @testdox The dirname is the same as the name of the directory
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticDirname() : void
{
$dirPath = __DIR__ . '/test';
self::assertEquals('test', Directory::dirname($dirPath)); self::assertEquals('test', Directory::dirname($dirPath));
self::assertEquals(\str_replace('\\', '/', \realpath($dirPath . '/../')), Directory::parent($dirPath)); }
/**
* @testdox The parent of a directory can be returned
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticParent() : void
{
$dirPath = __DIR__ . '/test';
self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__)), Directory::parent($dirPath));
}
/**
* @testdox The full absolute path of a directory can be returned
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticDirectoryPath() : void
{
$dirPath = __DIR__ . '/test';
self::assertEquals($dirPath, Directory::dirpath($dirPath)); self::assertEquals($dirPath, Directory::dirpath($dirPath));
}
/**
* @testdox The directories creation date can be returned
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticCreatedAt() : void
{
self::markTestSkipped();
$dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create($this->con, $dirPath));
$now = new \DateTime('now'); $now = new \DateTime('now');
// todo: implement, doesn't work for ftp yet 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($this->con, $dirPath)->format('Y-m-d'));
//self::assertEquals($now->format('Y-m-d'), Directory::changed($this->con, $dirPath)->format('Y-m-d'));
\rmdir($dirPath);
}
/**
* @testdox The directories last change date can be returned
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticChangedAt() : void
{
self::markTestSkipped();
$dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create($this->con, $dirPath));
$now = new \DateTime('now');
self::assertEquals($now->format('Y-m-d'), Directory::changed($this->con, $dirPath)->format('Y-m-d'));
\rmdir($dirPath);
}
/**
* @testdox A directory can be deleted
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticDelete() : void
{
$dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create($this->con, $dirPath));
self::assertTrue(Directory::delete($this->con, $dirPath)); self::assertTrue(Directory::delete($this->con, $dirPath));
self::assertFalse(Directory::exists($this->con, $dirPath)); self::assertFalse(Directory::exists($this->con, $dirPath));
}
/**
* @testdox A none-existing directory cannot be deleted
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidStaticDelete() : void
{
$dirPath = __DIR__ . '/test';
self::assertFalse(Directory::delete($this->con, $dirPath));
}
/**
* @testdox The size of a directory can be returned
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticSizeRecursive() : void
{
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertGreaterThan(0, Directory::size($this->con, $dirTestPath)); self::assertGreaterThan(0, Directory::size($this->con, $dirTestPath));
}
/**
* @testdox The size of a none-existing directory is negative
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidStaticSizeRecursive() : void
{
$dirTestPath = __DIR__ . '/invalid/test/here';
self::assertEquals(-1, Directory::size($this->con, $dirTestPath));
}
/**
* @testdox The recursive size of a directory is equals or greater than the size of the same directory none-recursive
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticSize() : void
{
$dirTestPath = __DIR__ . '/dirtest';
self::assertGreaterThan(Directory::size($this->con, $dirTestPath, false), Directory::size($this->con, $dirTestPath)); self::assertGreaterThan(Directory::size($this->con, $dirTestPath, false), Directory::size($this->con, $dirTestPath));
}
/**
* @testdox The permission of a directory can be returned
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticPermission() : void
{
$dirTestPath = __DIR__ . '/dirtest';
self::assertGreaterThan(0, Directory::permission($this->con, $dirTestPath)); self::assertGreaterThan(0, Directory::permission($this->con, $dirTestPath));
} }
public function testStaticMove() : void /**
* @testdox The permission of a none-existing directory is negative
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidStaticPermission() : void
{ {
self::assertNotFalse($this->con); $dirTestPath = __DIR__ . '/invalid/test/here';
self::assertEquals(-1, Directory::permission($this->con, $dirTestPath));
}
/**
* @testdox A directory can be copied recursively
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticCopy() : void
{
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertTrue(Directory::copy($this->con, $dirTestPath, __DIR__ . '/newdirtest')); self::assertTrue(Directory::copy($this->con, $dirTestPath, __DIR__ . '/newdirtest'));
self::assertFileExists(__DIR__ . '/newdirtest/sub/path/test3.txt'); self::assertFileExists(__DIR__ . '/newdirtest/sub/path/test3.txt');
self::assertTrue(Directory::delete($this->con, $dirTestPath)); Directory::delete($this->con, __DIR__ . '/newdirtest');
self::assertFalse(Directory::exists($this->con, $dirTestPath)); }
self::assertTrue(Directory::move($this->con, __DIR__ . '/newdirtest', $dirTestPath)); /**
self::assertFileExists($dirTestPath . '/sub/path/test3.txt'); * @testdox A directory can be moved/renamed to a different path
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticMove() : void
{
$dirTestPath = __DIR__ . '/dirtest';
self::assertTrue(Directory::move($this->con, $dirTestPath, __DIR__ . '/newdirtest'));
self::assertFileExists(__DIR__ . '/newdirtest/sub/path/test3.txt');
Directory::move($this->con, __DIR__ . '/newdirtest', $dirTestPath);
}
/**
* @testdox The amount of files in a directory can be returned recursively
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticCountRecursive() : void
{
$dirTestPath = __DIR__ . '/dirtest';
self::assertEquals(4, Directory::count($this->con, $dirTestPath)); self::assertEquals(4, Directory::count($this->con, $dirTestPath));
self::assertEquals(1, Directory::count($this->con, $dirTestPath, false)); }
/**
* @testdox The amount of files in a directory can be returned none-recursively
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticCount() : void
{
$dirTestPath = __DIR__ . '/dirtest';
self::assertEquals(1, Directory::count($this->con, $dirTestPath, false));
}
/**
* @testdox The amount of files of a none-existing directory is negative
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidStaticCount() : void
{
$dirTestPath = __DIR__ . '/invalid/path/here';
self::assertEquals(-1, Directory::count($this->con, $dirTestPath, false));
}
/**
* @testdox All files and sub-directories of a directory can be listed
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testStaticListFiles() : void
{
$dirTestPath = __DIR__ . '/dirtest';
self::assertCount(6, Directory::list($this->con, $dirTestPath)); self::assertCount(6, Directory::list($this->con, $dirTestPath));
} }
/**
* @testdox A none-existing directory returns a empty list of files and sub-directories
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidListPath() : void public function testInvalidListPath() : void
{ {
self::assertNotFalse($this->con);
self::assertEquals([], Directory::list($this->con, __DIR__ . '/invalid.txt')); self::assertEquals([], Directory::list($this->con, __DIR__ . '/invalid.txt'));
} }
/**
* @testdox A invalid directory cannot be copied to a new destination
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidCopyPath() : void public function testInvalidCopyPath() : void
{ {
self::assertNotFalse($this->con);
self::assertFalse(Directory::copy($this->con, __DIR__ . '/invalid', __DIR__ . '/invalid2')); self::assertFalse(Directory::copy($this->con, __DIR__ . '/invalid', __DIR__ . '/invalid2'));
} }
/**
* @testdox A invalid directory cannot be moved to a new destination
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidMovePath() : void public function testInvalidMovePath() : void
{ {
self::assertNotFalse($this->con);
self::assertFalse(Directory::move($this->con, __DIR__ . '/invalid', __DIR__ . '/invalid2')); self::assertFalse(Directory::move($this->con, __DIR__ . '/invalid', __DIR__ . '/invalid2'));
} }
/**
* @testdox Reading the creation date of a none-existing directory throws a PathException
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidCreatedPath() : void public function testInvalidCreatedPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
Directory::created($this->con, __DIR__ . '/invalid'); Directory::created($this->con, __DIR__ . '/invalid');
} }
/**
* @testdox Reading the last change date of a none-existing directory throws a PathException
* @covers phpOMS\System\File\Ftp\Directory
*/
public function testInvalidChangedPath() : void public function testInvalidChangedPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
Directory::changed($this->con, __DIR__ . '/invalid'); Directory::changed($this->con, __DIR__ . '/invalid');
} }
public function testInvalidSizePath() : void /**
{ * @testdox Reading the owner of a none-existing directory throws a PathException
self::expectException(\phpOMS\System\File\PathException::class); * @covers phpOMS\System\File\Ftp\Directory
*/
self::assertNotFalse($this->con);
Directory::size($this->con, __DIR__ . '/invalid');
}
public function testInvalidPermissionPath() : void
{
self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
Directory::permission($this->con, __DIR__ . '/invalid');
}
public function testInvalidOwnerPath() : void public function testInvalidOwnerPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
Directory::owner($this->con, __DIR__ . '/invalid'); Directory::owner($this->con, __DIR__ . '/invalid');
} }
} }

View File

@ -20,6 +20,8 @@ use phpOMS\System\File\Ftp\File;
use phpOMS\Uri\Http; use phpOMS\Uri\Http;
/** /**
* @testdox phpOMS\tests\System\File\Ftp\FileTest: File handler for a ftp server
*
* @internal * @internal
*/ */
class FileTest extends \PHPUnit\Framework\TestCase class FileTest extends \PHPUnit\Framework\TestCase
@ -41,131 +43,550 @@ class FileTest extends \PHPUnit\Framework\TestCase
} }
} }
public function testStatic() : void /**
* @testdox A file without content can be created
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticCreate() : void
{ {
self::assertNotFalse($this->con); $testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($this->con, $testFile));
self::assertTrue(\is_file($testFile));
self::assertEquals('', \file_get_contents($testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox A file cannot be created if it already exists
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidStaticCreate() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($this->con, $testFile));
self::assertFalse(File::create($this->con, $testFile));
self::assertTrue(\is_file($testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox A file with content can be created
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticPut() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE));
self::assertTrue(\is_file($testFile));
self::assertEquals('test', \file_get_contents($testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox A file cannot be replaced if it doesn't exists
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidStaticCreateReplace() : void
{
$testFile = __DIR__ . '/test.txt'; $testFile = __DIR__ . '/test.txt';
self::assertFalse(File::put($this->con, $testFile, 'test', ContentPutMode::REPLACE)); self::assertFalse(File::put($this->con, $testFile, 'test', ContentPutMode::REPLACE));
self::assertFalse(File::exists($this->con, $testFile)); self::assertfalse(\file_exists($testFile));
self::assertTrue(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); }
self::assertTrue(File::exists($this->con, $testFile));
self::assertFalse(File::put($this->con, $testFile, 'test', ContentPutMode::CREATE)); /**
* @testdox A file cannot be appended if it doesn't exists
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidStaticCreateAppend() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertFalse(File::put($this->con, $testFile, 'test', ContentPutMode::APPEND));
self::assertfalse(\file_exists($testFile));
}
/**
* @testdox A file cannot be prepended if it doesn't exists
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidStaticCreatePrepend() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertFalse(File::put($this->con, $testFile, 'test', ContentPutMode::PREPEND));
self::assertfalse(\file_exists($testFile));
}
/**
* @testdox A file can be checked for existence
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticExists() : void
{
self::assertTrue(File::exists($this->con, __DIR__ . '/FileTest.php'));
self::assertFalse(File::exists($this->con, __DIR__ . '/invalid/file.txt'));
}
/**
* @testdox A file can be replaced with a new one
* @covers phpOMS\System\File\Ftp\File
*/
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($this->con, $testFile, 'test2', ContentPutMode::REPLACE));
self::assertEquals('test2', File::get($this->con, $testFile)); self::assertEquals('test2', \file_get_contents($testFile));
self::assertTrue(File::set($this->con, $testFile, 'test3'));
self::assertTrue(File::append($this->con, $testFile, 'test4')); File::delete($this->con, $testFile);
self::assertEquals('test3test4', File::get($this->con, $testFile)); }
self::assertTrue(File::prepend($this->con, $testFile, 'test5'));
self::assertEquals('test5test3test4', File::get($this->con, $testFile)); /**
* @testdox The set alias works like the replace flag
* @covers phpOMS\System\File\Ftp\File
*/
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::assertEquals('test2', \file_get_contents($testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox A file can be appended with additional content
* @covers phpOMS\System\File\Ftp\File
*/
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::assertEquals('testtest2', \file_get_contents($testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox The append alias works like the append flag
* @covers phpOMS\System\File\Ftp\File
*/
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::assertEquals('testtest2', \file_get_contents($testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox A file can be prepended with additional content
* @covers phpOMS\System\File\Ftp\File
*/
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::assertEquals('test2test', \file_get_contents($testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox The prepend alias works like the prepend flag
* @covers phpOMS\System\File\Ftp\File
*/
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::assertEquals('test2test', \file_get_contents($testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox The content of a file can be read
* @covers phpOMS\System\File\Ftp\File
*/
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));
File::delete($this->con, $testFile);
}
/**
* @testdox The parent directory of a file can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticParent() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__ . '/../')), File::parent($testFile));
}
/**
* @testdox The extension of a file can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticExtension() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(\str_replace('\\', '/', \realpath(\dirname($testFile))), File::parent($testFile));
self::assertEquals('txt', File::extension($testFile)); self::assertEquals('txt', File::extension($testFile));
}
/**
* @testdox The name of a file can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticName() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals('test', File::name($testFile)); self::assertEquals('test', File::name($testFile));
}
/**
* @testdox The basename of a file can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticBaseName() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals('test.txt', File::basename($testFile)); self::assertEquals('test.txt', File::basename($testFile));
}
/**
* @testdox The file name of a file can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticDirname() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(\basename(\realpath(__DIR__)), File::dirname($testFile)); self::assertEquals(\basename(\realpath(__DIR__)), File::dirname($testFile));
}
/**
* @testdox The file path of a file can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticDirectoryPath() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(\realpath(__DIR__), File::dirpath($testFile)); self::assertEquals(\realpath(__DIR__), File::dirpath($testFile));
}
/**
* @testdox The count of a file is always 1
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticCount() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(1, File::count($testFile)); self::assertEquals(1, File::count($testFile));
}
/**
* @testdox The directories creation date can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticCreatedAt() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($this->con, $testFile));
$now = new \DateTime('now'); $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($this->con, $testFile)->format('Y-m-d'));
self::assertEquals($now->format('Y-m-d'), File::changed($this->con, $testFile)->format('Y-m-d'));
self::assertGreaterThan(0, File::size($this->con, $testFile)); File::delete($this->con, $testFile);
self::assertGreaterThan(0, File::permission($this->con, $testFile));
$newPath = __DIR__ . '/sub/path/testing.txt';
self::assertTrue(File::copy($this->con, $testFile, $newPath));
self::assertTrue(File::exists($this->con, $newPath));
self::assertFalse(File::copy($this->con, $testFile, $newPath));
self::assertTrue(File::copy($this->con, $testFile, $newPath, true));
self::assertEquals('test5test3test4', File::get($this->con, $newPath));
$newPath2 = __DIR__ . '/sub/path/testing2.txt';
self::assertTrue(File::move($this->con, $testFile, $newPath2));
self::assertTrue(File::exists($this->con, $newPath2));
self::assertFalse(File::exists($this->con, $testFile));
self::assertEquals('test5test3test4', File::get($this->con, $newPath2));
self::assertTrue(File::delete($this->con, $newPath2));
self::assertFalse(File::exists($this->con, $newPath2));
self::assertFalse(File::delete($this->con, $newPath2));
File::delete($this->con, $newPath);
Directory::delete($this->con, __DIR__ . '/sub');
self::assertTrue(File::create($this->con, $testFile));
self::assertFalse(File::create($this->con, $testFile));
self::assertEquals('', File::get($this->con, $testFile));
\unlink($testFile);
} }
/**
* @testdox The directories last change date can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticChangedAt() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($this->con, $testFile));
$now = new \DateTime('now');
self::assertEquals($now->format('Y-m-d'), File::changed($this->con, $testFile)->format('Y-m-d'));
File::delete($this->con, $testFile);
}
/**
* @testdox A file can be deleted
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticDelete() : void
{
$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));
}
/**
* @testdox A none-existing file cannot be deleted
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidStaticDelete() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertFalse(File::delete($this->con, $testFile));
}
/**
* @testdox The size of a file can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticSize() : void
{
$testFile = __DIR__ . '/test.txt';
File::put($this->con, $testFile, 'test', ContentPutMode::CREATE);
self::assertGreaterThan(0, File::size($this->con, $testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox The permission of a file can be returned
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticPermission() : void
{
$testFile = __DIR__ . '/test.txt';
File::put($this->con, $testFile, 'test', ContentPutMode::CREATE);
self::assertGreaterThan(0, File::permission($this->con, $testFile));
File::delete($this->con, $testFile);
}
/**
* @testdox The permission of a none-existing file is negative
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidStaticPermission() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(-1, File::permission($this->con, $testFile));
}
/**
* @testdox A file can be copied to a different location
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticCopy() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/sub/path/testing.txt';
File::put($this->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));
File::delete($this->con, $newPath);
Directory::delete($this->con, __DIR__ . '/sub/path/');
Directory::delete($this->con, __DIR__ . '/sub/');
File::delete($this->con, $testFile);
}
/**
* @testdox A file cannot be copied to a different location if the destination already exists
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidStaticCopy() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/test2.txt';
File::put($this->con, $testFile, 'test', ContentPutMode::CREATE);
File::put($this->con, $newPath, 'test2', ContentPutMode::CREATE);
self::assertFalse(File::copy($this->con, $testFile, $newPath));
self::assertEquals('test2', File::get($this->con, $newPath));
File::delete($this->con, $newPath);
File::delete($this->con, $testFile);
}
/**
* @testdox A file can be forced to be copied to a different location even if the destination already exists
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticCopyOverwrite() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/test2.txt';
File::put($this->con, $testFile, 'test', ContentPutMode::CREATE);
File::put($this->con, $newPath, 'test2', ContentPutMode::CREATE);
self::assertTrue(File::copy($this->con, $testFile, $newPath, true));
self::assertEquals('test', File::get($this->con, $newPath));
File::delete($this->con, $newPath);
File::delete($this->con, $testFile);
}
/**
* @testdox A file can be moved to a different location
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticMove() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/sub/path/testing.txt';
File::put($this->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));
Directory::delete($this->con, __DIR__ . '/sub');
}
/**
* @testdox A file cannot be moved to a different location if the destination already exists
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidStaticMove() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/test2.txt';
File::put($this->con, $testFile, 'test', ContentPutMode::CREATE);
File::put($this->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));
File::delete($this->con, $newPath);
File::delete($this->con, $testFile);
}
/**
* @testdox A file can be forced to be moved to a different location even if the destination already exists
* @covers phpOMS\System\File\Ftp\File
*/
public function testStaticMoveOverwrite() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/test2.txt';
File::put($this->con, $testFile, 'test', ContentPutMode::CREATE);
File::put($this->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));
File::delete($this->con, $newPath);
}
/**
* @testdox The size of a none-existing file is negative
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidSizePath() : void
{
self::assertEquals(-1, File::size($this->con, __DIR__ . '/invalid.txt'));
}
/**
* @testdox A none-existing file cannot be copied
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidCopyPath() : void
{
self::assertFalse(File::copy($this->con, __DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt'));
}
/**
* @testdox A none-existing file cannot be moved
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidMovePath() : void
{
self::assertFalse(File::move($this->con, __DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt'));
}
/**
* @testdox Reading the content of a none-existing file throws a PathException
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidGetPath() : void public function testInvalidGetPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
File::get($this->con, __DIR__ . '/invalid.txt'); File::get($this->con, __DIR__ . '/invalid.txt');
} }
public function testInvalidCopyPath() : void /**
{ * @testdox Reading the created date of a none-existing file throws a PathException
self::assertNotFalse($this->con); * @covers phpOMS\System\File\Ftp\File
self::assertFalse(File::copy($this->con, __DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt')); */
}
public function testInvalidMovePath() : void
{
self::assertNotFalse($this->con);
self::assertFalse(File::move($this->con, __DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt'));
}
public function testInvalidCreatedPath() : void public function testInvalidCreatedPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
File::created($this->con, __DIR__ . '/invalid.txt'); File::created($this->con, __DIR__ . '/invalid.txt');
} }
/**
* @testdox Reading the last change date of a none-existing file throws a PathException
* @covers phpOMS\System\File\Ftp\File
*/
public function testInvalidChangedPath() : void public function testInvalidChangedPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
File::changed($this->con, __DIR__ . '/invalid.txt'); File::changed($this->con, __DIR__ . '/invalid.txt');
} }
public function testInvalidSizePath() : void /**
{ * @testdox Reading the owner of a none-existing file throws a PathException
self::expectException(\phpOMS\System\File\PathException::class); * @covers phpOMS\System\File\Ftp\File
*/
self::assertNotFalse($this->con);
File::size($this->con, __DIR__ . '/invalid.txt');
}
public function testInvalidPermissionPath() : void
{
self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
File::permission($this->con, __DIR__ . '/invalid.txt');
}
public function testInvalidOwnerPath() : void public function testInvalidOwnerPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
self::assertNotFalse($this->con);
File::owner($this->con, __DIR__ . '/invalid.txt'); File::owner($this->con, __DIR__ . '/invalid.txt');
} }
} }

View File

@ -17,71 +17,120 @@ namespace phpOMS\tests\System\File\Local;
use phpOMS\System\File\Local\Directory; use phpOMS\System\File\Local\Directory;
/** /**
* @testdox phpOMS\tests\System\File\Local\DirectoryTest: Directory handler for local file system
*
* @internal * @internal
*/ */
class DirectoryTest extends \PHPUnit\Framework\TestCase class DirectoryTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox A directory can be created
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticCreate() : void public function testStaticCreate() : void
{ {
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create($dirPath)); self::assertTrue(Directory::create($dirPath));
self::assertTrue(Directory::exists($dirPath));
self::assertTrue(\is_dir($dirPath)); self::assertTrue(\is_dir($dirPath));
\unlink($dirPath); \rmdir($dirPath);
} }
/**
* @testdox A directory can be checked for existence
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticExists() : void public function testStaticExists() : void
{ {
$dirPath = __DIR__; self::assertTrue(Directory::exists(__DIR__));
self::assertTrue(Directory::exists($dirPath)); self::assertFalse(Directory::exists(__DIR__ . '/invalid/path/here'));
}
public function testInvalidStaticExists() : void
{
$dirPath = __DIR__ . '/invalid/path/here';
self::assertFalse(Directory::exists($dirPath));
} }
/**
* @testdox An existing directory cannot be overwritten
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidStaticOverwrite() : void public function testInvalidStaticOverwrite() : void
{ {
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create($dirPath)); self::assertTrue(Directory::create($dirPath));
self::assertFalse(Directory::create($dirPath)); self::assertFalse(Directory::create($dirPath));
\unlink($dirPath); \rmdir($dirPath);
} }
/**
* @testdox A directory can be forced to be created recursively
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticSubdir() : void public function testStaticSubdir() : void
{ {
$dirPath = __DIR__ . '/test/sub/path'; $dirPath = __DIR__ . '/test/sub/path';
self::assertTrue(Directory::create($dirPath, 0755, true)); self::assertTrue(Directory::create($dirPath, 0755, true));
self::assertTrue(Directory::exists($dirPath)); self::assertTrue(Directory::exists($dirPath));
\unlink($dirPath); \rmdir(__DIR__ . '/test/sub/path');
\rmdir(__DIR__ . '/test/sub');
\rmdir(__DIR__ . '/test');
} }
/**
* @testdox By default a directory is not created recursively
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidStaticSubdir() : void public function testInvalidStaticSubdir() : void
{ {
self::assertFalse(Directory::create(__DIR__ . '/test/sub/path')); self::assertFalse(Directory::create(__DIR__ . '/invalid/path/here'));
} }
public function testStaticNames() : void /**
* @testdox The name of a directory is just its name without its path
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticName() : void
{ {
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
self::assertEquals('test', Directory::name($dirPath)); self::assertEquals('test', Directory::name($dirPath));
}
/**
* @testdox The basename is the same as the name of the directory
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticBasename() : void
{
$dirPath = __DIR__ . '/test';
self::assertEquals('test', Directory::basename($dirPath)); self::assertEquals('test', Directory::basename($dirPath));
}
/**
* @testdox The dirname is the same as the name of the directory
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticDirname() : void
{
$dirPath = __DIR__ . '/test';
self::assertEquals('test', Directory::dirname($dirPath)); self::assertEquals('test', Directory::dirname($dirPath));
} }
/**
* @testdox The parent of a directory can be returned
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticParent() : void public function testStaticParent() : void
{ {
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
self::assertEquals(\str_replace('\\', '/', \realpath($dirPath . '/../')), Directory::parent($dirPath)); self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__)), Directory::parent($dirPath));
} }
/**
* @testdox The full absolute path of a directory can be returned
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticDirectoryPath() : void public function testStaticDirectoryPath() : void
{ {
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
@ -89,6 +138,10 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
self::assertEquals($dirPath, Directory::dirpath($dirPath)); self::assertEquals($dirPath, Directory::dirpath($dirPath));
} }
/**
* @testdox The directories creation date can be returned
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticCreatedAt() : void public function testStaticCreatedAt() : void
{ {
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
@ -98,9 +151,13 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
$now = new \DateTime('now'); $now = new \DateTime('now');
self::assertEquals($now->format('Y-m-d'), Directory::created($dirPath)->format('Y-m-d')); self::assertEquals($now->format('Y-m-d'), Directory::created($dirPath)->format('Y-m-d'));
\unlink($dirPath); \rmdir($dirPath);
} }
/**
* @testdox The directories last change date can be returned
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticChangedAt() : void public function testStaticChangedAt() : void
{ {
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
@ -110,9 +167,13 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
$now = new \DateTime('now'); $now = new \DateTime('now');
self::assertEquals($now->format('Y-m-d'), Directory::changed($dirPath)->format('Y-m-d')); self::assertEquals($now->format('Y-m-d'), Directory::changed($dirPath)->format('Y-m-d'));
\unlink($dirPath); \rmdir($dirPath);
} }
/**
* @testdox A directory can be deleted
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticDelete() : void public function testStaticDelete() : void
{ {
$dirPath = __DIR__ . '/test'; $dirPath = __DIR__ . '/test';
@ -122,36 +183,71 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
self::assertFalse(Directory::exists($dirPath)); self::assertFalse(Directory::exists($dirPath));
} }
/**
* @testdox A none-existing directory cannot be deleted
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidStaticDelete() : void
{
$dirPath = __DIR__ . '/test';
self::assertFalse(Directory::delete($dirPath));
}
/**
* @testdox The size of a directory can be returned
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticSizeRecursive() : void public function testStaticSizeRecursive() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertGreaterThan(0, Directory::size($dirTestPath)); self::assertGreaterThan(0, Directory::size($dirTestPath));
} }
/**
* @testdox The size of a none-existing directory is negative
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidStaticSizeRecursive() : void public function testInvalidStaticSizeRecursive() : void
{ {
$dirTestPath = __DIR__ . '/invalid/test/here'; $dirTestPath = __DIR__ . '/invalid/test/here';
self::assertEquals(0, Directory::size($dirTestPath)); self::assertEquals(-1, Directory::size($dirTestPath));
} }
/**
* @testdox The recursive size of a directory is equals or greater than the size of the same directory none-recursive
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticSize() : void public function testStaticSize() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertGreaterThan(Directory::size($dirTestPath, false), Directory::size($dirTestPath)); self::assertGreaterThan(Directory::size($dirTestPath, false), Directory::size($dirTestPath));
} }
/**
* @testdox The permission of a directory can be returned
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticPermission() : void public function testStaticPermission() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertGreaterThan(0, Directory::permission($dirTestPath)); self::assertGreaterThan(0, Directory::permission($dirTestPath));
} }
/**
* @testdox The permission of a none-existing directory is negative
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidStaticPermission() : void public function testInvalidStaticPermission() : void
{ {
$dirTestPath = __DIR__ . '/invalid/test/here'; $dirTestPath = __DIR__ . '/invalid/test/here';
self::assertEquals(0, Directory::permission($dirTestPath)); self::assertEquals(-1, Directory::permission($dirTestPath));
} }
/**
* @testdox A directory can be copied recursively
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticCopy() : void public function testStaticCopy() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
@ -161,6 +257,10 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
Directory::delete(__DIR__ . '/newdirtest'); Directory::delete(__DIR__ . '/newdirtest');
} }
/**
* @testdox A directory can be moved/renamed to a different path
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticMove() : void public function testStaticMove() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
@ -171,51 +271,96 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
Directory::move(__DIR__ . '/newdirtest', $dirTestPath); Directory::move(__DIR__ . '/newdirtest', $dirTestPath);
} }
/**
* @testdox The amount of files in a directory can be returned recursively
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticCountRecursive() : void public function testStaticCountRecursive() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertEquals(4, Directory::count($dirTestPath)); self::assertEquals(4, Directory::count($dirTestPath));
} }
/**
* @testdox The amount of files in a directory can be returned none-recursively
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticCount() : void public function testStaticCount() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertEquals(1, Directory::count($dirTestPath, false)); self::assertEquals(1, Directory::count($dirTestPath, false));
} }
/**
* @testdox The amount of files of a none-existing directory is negative
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidStaticCount() : void public function testInvalidStaticCount() : void
{ {
$dirTestPath = __DIR__ . '/invalid/path/here'; $dirTestPath = __DIR__ . '/invalid/path/here';
self::assertEquals(0, Directory::count($dirTestPath, false)); self::assertEquals(-1, Directory::count($dirTestPath, false));
} }
/**
* @testdox All files and sub-directories of a directory can be listed
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticListFiles() : void public function testStaticListFiles() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertCount(6, Directory::list($dirTestPath)); self::assertCount(6, Directory::list($dirTestPath));
} }
/**
* @testdox All files of a directory can be listed by file extension
* @covers phpOMS\System\File\Local\Directory
*/
public function testStaticListFilesByExtension() : void public function testStaticListFilesByExtension() : void
{ {
$dirTestPath = __DIR__ . '/dirtest'; $dirTestPath = __DIR__ . '/dirtest';
self::assertCount(3, Directory::listByExtension($dirTestPath, 'txt')); self::assertCount(3, Directory::listByExtension($dirTestPath, 'txt'));
} }
/**
* @testdox A none-existing directory returns a empty list of files and sub-directories
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidListPath() : void public function testInvalidListPath() : void
{ {
self::assertEquals([], Directory::list(__DIR__ . '/invalid.txt')); self::assertEquals([], Directory::list(__DIR__ . '/invalid/path/here'));
} }
/**
* @testdox A none-existing directory returns a empty list of files for the extension
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidListFilesByExtension() : void
{
self::assertEquals([], Directory::listByExtension(__DIR__ . '/invalid/path/here', 'txt'));
}
/**
* @testdox A invalid directory cannot be copied to a new destination
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidCopyPath() : void public function testInvalidCopyPath() : void
{ {
self::assertFalse(Directory::copy(__DIR__ . '/invalid', __DIR__ . '/invalid2')); self::assertFalse(Directory::copy(__DIR__ . '/invalid', __DIR__ . '/invalid2'));
} }
/**
* @testdox A invalid directory cannot be moved to a new destination
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidMovePath() : void public function testInvalidMovePath() : void
{ {
self::assertFalse(Directory::move(__DIR__ . '/invalid', __DIR__ . '/invalid2')); self::assertFalse(Directory::move(__DIR__ . '/invalid', __DIR__ . '/invalid2'));
} }
/**
* @testdox Reading the creation date of a none-existing directory throws a PathException
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidCreatedPath() : void public function testInvalidCreatedPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
@ -223,6 +368,10 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
Directory::created(__DIR__ . '/invalid'); Directory::created(__DIR__ . '/invalid');
} }
/**
* @testdox Reading the last change date of a none-existing directory throws a PathException
* @covers phpOMS\System\File\Local\Directory
*/
public function testInvalidChangedPath() : void public function testInvalidChangedPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
@ -230,20 +379,10 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
Directory::changed(__DIR__ . '/invalid'); Directory::changed(__DIR__ . '/invalid');
} }
public function testInvalidSizePath() : void /**
{ * @testdox Reading the owner of a none-existing directory throws a PathException
self::expectException(\phpOMS\System\File\PathException::class); * @covers phpOMS\System\File\Local\Directory
*/
Directory::size(__DIR__ . '/invalid');
}
public function testInvalidPermissionPath() : void
{
self::expectException(\phpOMS\System\File\PathException::class);
Directory::permission(__DIR__ . '/invalid');
}
public function testInvalidOwnerPath() : void public function testInvalidOwnerPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);

View File

@ -18,71 +18,521 @@ use phpOMS\System\File\ContentPutMode;
use phpOMS\System\File\Local\File; use phpOMS\System\File\Local\File;
/** /**
* @testdox phpOMS\tests\System\File\Local\FileTest: File handler for local file system
*
* @internal * @internal
*/ */
class FileTest extends \PHPUnit\Framework\TestCase class FileTest extends \PHPUnit\Framework\TestCase
{ {
public function testStatic() : void /**
* @testdox A file without content can be created
* @covers phpOMS\System\File\Local\File
*/
public function testStaticCreate() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($testFile));
self::assertTrue(\is_file($testFile));
self::assertEquals('', \file_get_contents($testFile));
\unlink($testFile);
}
/**
* @testdox A file cannot be created if it already exists
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidStaticCreate() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($testFile));
self::assertFalse(File::create($testFile));
self::assertTrue(\is_file($testFile));
\unlink($testFile);
}
/**
* @testdox A file with content can be created
* @covers phpOMS\System\File\Local\File
*/
public function testStaticPut() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE));
self::assertTrue(\is_file($testFile));
self::assertEquals('test', \file_get_contents($testFile));
\unlink($testFile);
}
/**
* @testdox A file cannot be replaced if it doesn't exists
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidStaticCreateReplace() : void
{ {
$testFile = __DIR__ . '/test.txt'; $testFile = __DIR__ . '/test.txt';
self::assertFalse(File::put($testFile, 'test', ContentPutMode::REPLACE)); self::assertFalse(File::put($testFile, 'test', ContentPutMode::REPLACE));
self::assertFalse(File::exists($testFile)); self::assertfalse(\file_exists($testFile));
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE)); }
self::assertTrue(File::exists($testFile));
self::assertFalse(File::put($testFile, 'test', ContentPutMode::CREATE)); /**
* @testdox A file cannot be appended if it doesn't exists
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidStaticCreateAppend() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertFalse(File::put($testFile, 'test', ContentPutMode::APPEND));
self::assertfalse(\file_exists($testFile));
}
/**
* @testdox A file cannot be prepended if it doesn't exists
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidStaticCreatePrepend() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertFalse(File::put($testFile, 'test', ContentPutMode::PREPEND));
self::assertfalse(\file_exists($testFile));
}
/**
* @testdox A file can be checked for existence
* @covers phpOMS\System\File\Local\File
*/
public function testStaticExists() : void
{
self::assertTrue(File::exists(__DIR__ . '/FileTest.php'));
self::assertFalse(File::exists(__DIR__ . '/invalid/file.txt'));
}
/**
* @testdox A file can be replaced with a new one
* @covers phpOMS\System\File\Local\File
*/
public function testStaticReplace() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE));
self::assertTrue(File::put($testFile, 'test2', ContentPutMode::REPLACE)); self::assertTrue(File::put($testFile, 'test2', ContentPutMode::REPLACE));
self::assertEquals('test2', File::get($testFile)); self::assertEquals('test2', \file_get_contents($testFile));
self::assertTrue(File::set($testFile, 'test3'));
self::assertTrue(File::append($testFile, 'test4')); \unlink($testFile);
self::assertEquals('test3test4', File::get($testFile)); }
self::assertTrue(File::prepend($testFile, 'test5'));
self::assertEquals('test5test3test4', File::get($testFile)); /**
* @testdox The set alias works like the replace flag
* @covers phpOMS\System\File\Local\File
*/
public function testStaticSetAlias() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE));
self::assertTrue(File::set($testFile, 'test2'));
self::assertEquals('test2', \file_get_contents($testFile));
\unlink($testFile);
}
/**
* @testdox A file can be appended with additional content
* @covers phpOMS\System\File\Local\File
*/
public function testStaticAppend() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE));
self::assertTrue(File::put($testFile, 'test2', ContentPutMode::APPEND));
self::assertEquals('testtest2', \file_get_contents($testFile));
\unlink($testFile);
}
/**
* @testdox The append alias works like the append flag
* @covers phpOMS\System\File\Local\File
*/
public function testStaticAppendAlias() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE));
self::assertTrue(File::append($testFile, 'test2'));
self::assertEquals('testtest2', \file_get_contents($testFile));
\unlink($testFile);
}
/**
* @testdox A file can be prepended with additional content
* @covers phpOMS\System\File\Local\File
*/
public function testStaticPrepend() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE));
self::assertTrue(File::put($testFile, 'test2', ContentPutMode::PREPEND));
self::assertEquals('test2test', \file_get_contents($testFile));
\unlink($testFile);
}
/**
* @testdox The prepend alias works like the prepend flag
* @covers phpOMS\System\File\Local\File
*/
public function testStaticPrependAlias() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE));
self::assertTrue(File::prepend($testFile, 'test2'));
self::assertEquals('test2test', \file_get_contents($testFile));
\unlink($testFile);
}
/**
* @testdox The content of a file can be read
* @covers phpOMS\System\File\Local\File
*/
public function testStaticGet() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::put($testFile, 'test', ContentPutMode::CREATE));
self::assertEquals('test', File::get($testFile));
\unlink($testFile);
}
/**
* @testdox The parent directory of a file can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticParent() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__ . '/../')), File::parent($testFile));
}
/**
* @testdox The extension of a file can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticExtension() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(\str_replace('\\', '/', \realpath(\dirname($testFile) . '/../')), File::parent($testFile));
self::assertEquals('txt', File::extension($testFile)); self::assertEquals('txt', File::extension($testFile));
}
/**
* @testdox The name of a file can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticName() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals('test', File::name($testFile)); self::assertEquals('test', File::name($testFile));
}
/**
* @testdox The basename of a file can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticBaseName() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals('test.txt', File::basename($testFile)); self::assertEquals('test.txt', File::basename($testFile));
}
/**
* @testdox The file name of a file can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticDirname() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(\basename(\realpath(__DIR__)), File::dirname($testFile)); self::assertEquals(\basename(\realpath(__DIR__)), File::dirname($testFile));
}
/**
* @testdox The file path of a file can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticDirectoryPath() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(\realpath(__DIR__), File::dirpath($testFile)); self::assertEquals(\realpath(__DIR__), File::dirpath($testFile));
}
/**
* @testdox The count of a file is always 1
* @covers phpOMS\System\File\Local\File
*/
public function testStaticCount() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(1, File::count($testFile)); self::assertEquals(1, File::count($testFile));
}
/**
* @testdox The directories creation date can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticCreatedAt() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($testFile));
$now = new \DateTime('now'); $now = new \DateTime('now');
self::assertEquals($now->format('Y-m-d'), File::created($testFile)->format('Y-m-d')); self::assertEquals($now->format('Y-m-d'), File::created($testFile)->format('Y-m-d'));
\unlink($testFile);
}
/**
* @testdox The directories last change date can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticChangedAt() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($testFile));
$now = new \DateTime('now');
self::assertEquals($now->format('Y-m-d'), File::changed($testFile)->format('Y-m-d')); self::assertEquals($now->format('Y-m-d'), File::changed($testFile)->format('Y-m-d'));
\unlink($testFile);
}
/**
* @testdox A file can be deleted
* @covers phpOMS\System\File\Local\File
*/
public function testStaticDelete() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertTrue(File::create($testFile));
self::assertTrue(File::delete($testFile));
self::assertFalse(File::exists($testFile));
}
/**
* @testdox A none-existing file cannot be deleted
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidStaticDelete() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertFalse(File::delete($testFile));
}
/**
* @testdox The size of a file can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticSize() : void
{
$testFile = __DIR__ . '/test.txt';
File::put($testFile, 'test', ContentPutMode::CREATE);
self::assertGreaterThan(0, File::size($testFile)); self::assertGreaterThan(0, File::size($testFile));
\unlink($testFile);
}
/**
* @testdox The permission of a file can be returned
* @covers phpOMS\System\File\Local\File
*/
public function testStaticPermission() : void
{
$testFile = __DIR__ . '/test.txt';
File::put($testFile, 'test', ContentPutMode::CREATE);
self::assertGreaterThan(0, File::permission($testFile)); self::assertGreaterThan(0, File::permission($testFile));
$newPath = __DIR__ . '/sub/path/testing.txt'; \unlink($testFile);
}
/**
* @testdox The permission of a none-existing file is negative
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidStaticPermission() : void
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(-1, File::permission($testFile));
}
/**
* @testdox A file can be copied to a different location
* @covers phpOMS\System\File\Local\File
*/
public function testStaticCopy() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/sub/path/testing.txt';
File::put($testFile, 'test', ContentPutMode::CREATE);
self::assertTrue(File::copy($testFile, $newPath)); self::assertTrue(File::copy($testFile, $newPath));
self::assertTrue(File::exists($newPath)); self::assertTrue(File::exists($newPath));
self::assertFalse(File::copy($testFile, $newPath)); self::assertEquals('test', File::get($newPath));
self::assertTrue(File::copy($testFile, $newPath, true));
self::assertEquals('test5test3test4', File::get($newPath));
$newPath2 = __DIR__ . '/sub/path/testing2.txt';
self::assertTrue(File::move($testFile, $newPath2));
self::assertTrue(File::exists($newPath2));
self::assertFalse(File::exists($testFile));
self::assertEquals('test5test3test4', File::get($newPath2));
self::assertTrue(File::delete($newPath2));
self::assertFalse(File::exists($newPath2));
self::assertFalse(File::delete($newPath2));
\unlink($newPath); \unlink($newPath);
\rmdir(__DIR__ . '/sub/path/'); \rmdir(__DIR__ . '/sub/path/');
\rmdir(__DIR__ . '/sub/'); \rmdir(__DIR__ . '/sub/');
self::assertTrue(File::create($testFile));
self::assertFalse(File::create($testFile));
self::assertEquals('', File::get($testFile));
\unlink($testFile); \unlink($testFile);
} }
/**
* @testdox A file cannot be copied to a different location if the destination already exists
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidStaticCopy() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/test2.txt';
File::put($testFile, 'test', ContentPutMode::CREATE);
File::put($newPath, 'test2', ContentPutMode::CREATE);
self::assertFalse(File::copy($testFile, $newPath));
self::assertEquals('test2', File::get($newPath));
\unlink($newPath);
\unlink($testFile);
}
/**
* @testdox A file can be forced to be copied to a different location even if the destination already exists
* @covers phpOMS\System\File\Local\File
*/
public function testStaticCopyOverwrite() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/test2.txt';
File::put($testFile, 'test', ContentPutMode::CREATE);
File::put($newPath, 'test2', ContentPutMode::CREATE);
self::assertTrue(File::copy($testFile, $newPath, true));
self::assertEquals('test', File::get($newPath));
\unlink($newPath);
\unlink($testFile);
}
/**
* @testdox A file can be moved to a different location
* @covers phpOMS\System\File\Local\File
*/
public function testStaticMove() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/sub/path/testing.txt';
File::put($testFile, 'test', ContentPutMode::CREATE);
self::assertTrue(File::move($testFile, $newPath));
self::assertFalse(File::exists($testFile));
self::assertTrue(File::exists($newPath));
self::assertEquals('test', File::get($newPath));
\unlink($newPath);
\rmdir(__DIR__ . '/sub/path/');
\rmdir(__DIR__ . '/sub/');
}
/**
* @testdox A file cannot be moved to a different location if the destination already exists
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidStaticMove() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/test2.txt';
File::put($testFile, 'test', ContentPutMode::CREATE);
File::put($newPath, 'test2', ContentPutMode::CREATE);
self::assertFalse(File::move($testFile, $newPath));
self::assertTrue(File::exists($testFile));
self::assertEquals('test2', File::get($newPath));
\unlink($newPath);
\unlink($testFile);
}
/**
* @testdox A file can be forced to be moved to a different location even if the destination already exists
* @covers phpOMS\System\File\Local\File
*/
public function testStaticMoveOverwrite() : void
{
$testFile = __DIR__ . '/test.txt';
$newPath = __DIR__ . '/test2.txt';
File::put($testFile, 'test', ContentPutMode::CREATE);
File::put($newPath, 'test2', ContentPutMode::CREATE);
self::assertTrue(File::move($testFile, $newPath, true));
self::assertFalse(File::exists($testFile));
self::assertEquals('test', File::get($newPath));
\unlink($newPath);
}
/**
* @testdox The size of a none-existing file is negative
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidSizePath() : void
{
self::assertEquals(-1, File::size(__DIR__ . '/invalid.txt'));
}
/**
* @testdox A none-existing file cannot be copied
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidCopyPath() : void
{
self::assertFalse(File::copy(__DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt'));
}
/**
* @testdox A none-existing file cannot be moved
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidMovePath() : void
{
self::assertFalse(File::move(__DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt'));
}
/**
* @testdox Reading the content of a none-existing file throws a PathException
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidGetPath() : void public function testInvalidGetPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
@ -90,16 +540,10 @@ class FileTest extends \PHPUnit\Framework\TestCase
File::get(__DIR__ . '/invalid.txt'); File::get(__DIR__ . '/invalid.txt');
} }
public function testInvalidCopyPath() : void /**
{ * @testdox Reading the created date of a none-existing file throws a PathException
self::assertFalse(File::copy(__DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt')); * @covers phpOMS\System\File\Local\File
} */
public function testInvalidMovePath() : void
{
self::assertFalse(File::move(__DIR__ . '/invalid.txt', __DIR__ . '/invalid2.txt'));
}
public function testInvalidCreatedPath() : void public function testInvalidCreatedPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
@ -107,6 +551,10 @@ class FileTest extends \PHPUnit\Framework\TestCase
File::created(__DIR__ . '/invalid.txt'); File::created(__DIR__ . '/invalid.txt');
} }
/**
* @testdox Reading the last change date of a none-existing file throws a PathException
* @covers phpOMS\System\File\Local\File
*/
public function testInvalidChangedPath() : void public function testInvalidChangedPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);
@ -114,18 +562,10 @@ class FileTest extends \PHPUnit\Framework\TestCase
File::changed(__DIR__ . '/invalid.txt'); File::changed(__DIR__ . '/invalid.txt');
} }
public function testInvalidSizePath() : void /**
{ * @testdox Reading the owner of a none-existing file throws a PathException
self::assertEquals(0, File::size(__DIR__ . '/invalid.txt')); * @covers phpOMS\System\File\Local\File
} */
public function testInvalidPermissionPath() : void
{
self::expectException(\phpOMS\System\File\PathException::class);
File::permission(__DIR__ . '/invalid.txt');
}
public function testInvalidOwnerPath() : void public function testInvalidOwnerPath() : void
{ {
self::expectException(\phpOMS\System\File\PathException::class); self::expectException(\phpOMS\System\File\PathException::class);

File diff suppressed because it is too large Load Diff

View File

@ -18,23 +18,57 @@ use phpOMS\System\File\Local\LocalStorage;
use phpOMS\System\File\Storage; use phpOMS\System\File\Storage;
/** /**
* @testdox phpOMS\tests\System\File\StorageTest: Storage handler for the different storage handler types
*
* @internal * @internal
*/ */
class StorageTest extends \PHPUnit\Framework\TestCase class StorageTest extends \PHPUnit\Framework\TestCase
{ {
public function testStorage() : void /**
* @testdox By default the local storage handler is returned
* @covers phpOMS\System\File\Storage
*/
public function testStorageDefault() : void
{
self::assertInstanceOf('\phpOMS\System\File\Local\LocalStorage', Storage::env());
}
/**
* @testdox The pre-defined storage handlers can be returned by their name
* @covers phpOMS\System\File\Storage
*/
public function testStoragePreDefined() : void
{ {
self::assertInstanceOf('\phpOMS\System\File\Local\LocalStorage', Storage::env('local')); self::assertInstanceOf('\phpOMS\System\File\Local\LocalStorage', Storage::env('local'));
self::assertInstanceOf('\phpOMS\System\File\Local\LocalStorage', Storage::env());
self::assertTrue(Storage::register('ftp', '\phpOMS\System\File\Ftp\FtpStorage'));
self::assertTrue(Storage::register('test', LocalStorage::getInstance()));
self::assertFalse(Storage::register('test', LocalStorage::getInstance()));
self::assertInstanceOf('\phpOMS\System\File\Ftp\FtpStorage', Storage::env('ftp')); self::assertInstanceOf('\phpOMS\System\File\Ftp\FtpStorage', Storage::env('ftp'));
}
/**
* @testdox Storages can be registered and returned
* @covers phpOMS\System\File\Storage
*/
public function testInputOutput() : void
{
self::assertTrue(Storage::register('ftps', '\phpOMS\System\File\Ftp\FtpStorage'));
self::assertTrue(Storage::register('test', LocalStorage::getInstance()));
self::assertInstanceOf('\phpOMS\System\File\Ftp\FtpStorage', Storage::env('ftps'));
self::assertInstanceOf('\phpOMS\System\File\Local\LocalStorage', Storage::env('test')); self::assertInstanceOf('\phpOMS\System\File\Local\LocalStorage', Storage::env('test'));
} }
/**
* @testdox Registered storage handlers cannot be overwritten
* @covers phpOMS\System\File\Storage
*/
public function testInvalidRegister() : void
{
self::assertTrue(Storage::register('test2', LocalStorage::getInstance()));
self::assertFalse(Storage::register('test2', LocalStorage::getInstance()));
}
/**
* @testdox A invalid or none-existing storage throws a Exception
* @covers phpOMS\System\File\Storage
*/
public function testInvalidStorage() : void public function testInvalidStorage() : void
{ {
self::expectException(\Exception::class); self::expectException(\Exception::class);

View File

@ -19,14 +19,15 @@ use phpOMS\System\SystemUtils;
require_once __DIR__ . '/../Autoloader.php'; require_once __DIR__ . '/../Autoloader.php';
/** /**
* @testdox phpOMS\System\SystemUtils: System information * @testdox phpOMS\tests\System\SystemUtilsTest: System information
* *
* @internal * @internal
*/ */
class SystemUtilsTest extends \PHPUnit\Framework\TestCase class SystemUtilsTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @testdox Test if it is possible to get information about the available RAM and usage (on Windows) * @testdox Test if it is possible to get information about the available RAM and usage
* @covers phpOMS\System\SystemUtils
*/ */
public function testRAM() : void public function testRAM() : void
{ {
@ -43,6 +44,7 @@ class SystemUtilsTest extends \PHPUnit\Framework\TestCase
/** /**
* @testdox Test if it is possible to get information about the CPU usage * @testdox Test if it is possible to get information about the CPU usage
* @covers phpOMS\System\SystemUtils
*/ */
public function testCPUUsage() : void public function testCPUUsage() : void
{ {

View File

@ -19,30 +19,18 @@ require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Uri\Argument; use phpOMS\Uri\Argument;
/** /**
* @testdox phpOMS\tests\Uri\ArgumentTest: Argument uri / uri
*
* @internal * @internal
*/ */
class ArgumentTest extends \PHPUnit\Framework\TestCase class ArgumentTest extends \PHPUnit\Framework\TestCase
{ {
public function testAttributes() : void
{
$obj = new Argument('');
/* Testing members */ /**
self::assertObjectHasAttribute('rootPath', $obj); * @testdox A uri can be validated
self::assertObjectHasAttribute('uri', $obj); * @covers phpOMS\Uri\Argument
self::assertObjectHasAttribute('scheme', $obj); */
self::assertObjectHasAttribute('host', $obj); public function testValidator() : void
self::assertObjectHasAttribute('port', $obj);
self::assertObjectHasAttribute('user', $obj);
self::assertObjectHasAttribute('pass', $obj);
self::assertObjectHasAttribute('path', $obj);
self::assertObjectHasAttribute('query', $obj);
self::assertObjectHasAttribute('queryString', $obj);
self::assertObjectHasAttribute('fragment', $obj);
self::assertObjectHasAttribute('base', $obj);
}
public function testHelper() : void
{ {
self::assertTrue(Argument::isValid('http://www.google.de')); self::assertTrue(Argument::isValid('http://www.google.de'));
self::assertTrue(Argument::isValid('http://google.de')); self::assertTrue(Argument::isValid('http://google.de'));
@ -51,9 +39,13 @@ class ArgumentTest extends \PHPUnit\Framework\TestCase
self::assertTrue(Argument::isValid('https:/google.de')); self::assertTrue(Argument::isValid('https:/google.de'));
} }
public function testSetGet() : void /**
* @testdox The argument uri has the expected default values after initialization
* @covers phpOMS\Uri\Argument
*/
public function testDefault() : void
{ {
$obj = new Argument($uri = ':modules/admin/test/path.php ?para1=abc ?para2=2 #frag'); $obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag');
self::assertEquals('/', $obj->getRootPath()); self::assertEquals('/', $obj->getRootPath());
self::assertEquals(0, $obj->getPathOffset()); self::assertEquals(0, $obj->getPathOffset());
@ -62,17 +54,77 @@ class ArgumentTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $obj->getPort()); self::assertEquals(0, $obj->getPort());
self::assertEquals('', $obj->getPass()); self::assertEquals('', $obj->getPass());
self::assertEquals('', $obj->getUser()); self::assertEquals('', $obj->getUser());
self::assertEquals('', $obj->getAuthority());
self::assertEquals('', $obj->getUserInfo());
self::assertEquals('', $obj->getBase());
}
/**
* @testdox The path can be parsed correctly from a uri
* @covers phpOMS\Uri\Argument
*/
public function testPathInputOutput() : void
{
$obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag');
self::assertEquals('modules/admin/test/path', $obj->getPath()); self::assertEquals('modules/admin/test/path', $obj->getPath());
self::assertEquals('modules/admin/test/path ?para1=abc ?para2=2', $obj->getRoute());
self::assertEquals('modules', $obj->getPathElement(0)); self::assertEquals('modules', $obj->getPathElement(0));
}
/**
* @testdox The route can be parsed correctly from a uri
* @covers phpOMS\Uri\Argument
*/
public function testRouteInputOutput() : void
{
$obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag');
self::assertEquals('modules/admin/test/path ?para1=abc ?para2=2', $obj->getRoute());
}
/**
* @testdox The query data can be parsed correctly from a uri
* @covers phpOMS\Uri\Argument
*/
public function testQueryInputOutput() : void
{
$obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag');
self::assertEquals('?para1=abc ?para2=2', $obj->getQuery()); self::assertEquals('?para1=abc ?para2=2', $obj->getQuery());
self::assertEquals(['para1' => 'abc', 'para2' => '2'], $obj->getQueryArray()); self::assertEquals(['para1' => 'abc', 'para2' => '2'], $obj->getQueryArray());
self::assertEquals('2', $obj->getQuery('para2')); self::assertEquals('2', $obj->getQuery('para2'));
}
/**
* @testdox The fragment can be parsed correctly from a uri
* @covers phpOMS\Uri\Argument
*/
public function testFragmentInputOutput() : void
{
$obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag');
self::assertEquals('frag', $obj->getFragment()); self::assertEquals('frag', $obj->getFragment());
self::assertEquals('', $obj->getBase()); }
/**
* @testdox The uri can be turned into a string
* @covers phpOMS\Uri\Argument
*/
public function testStringify() : void
{
$obj = new Argument($uri = ':modules/admin/test/path.php ?para1=abc ?para2=2 #frag');
self::assertEquals($uri, $obj->__toString()); self::assertEquals($uri, $obj->__toString());
self::assertEquals('', $obj->getAuthority()); }
self::assertEquals('', $obj->getUserInfo());
/**
* @testdox The root path can be set and returned
* @covers phpOMS\Uri\Argument
*/
public function testRootPathInputOutput() : void
{
$obj = new Argument(':modules/admin/test/path.php ?para1=abc ?para2=2 #frag');
$obj->setRootPath('a'); $obj->setRootPath('a');
self::assertEquals('a', $obj->getRootPath()); self::assertEquals('a', $obj->getRootPath());

View File

@ -19,30 +19,17 @@ require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Uri\Http; use phpOMS\Uri\Http;
/** /**
* @testdox phpOMS\tests\Uri\HttpTest: Http uri / url
*
* @internal * @internal
*/ */
class HttpTest extends \PHPUnit\Framework\TestCase class HttpTest extends \PHPUnit\Framework\TestCase
{ {
public function testAttributes() : void /**
{ * @testdox A url can be validated
$obj = new Http(''); * @covers phpOMS\Uri\Http
*/
/* Testing members */ public function testValidator() : void
self::assertObjectHasAttribute('rootPath', $obj);
self::assertObjectHasAttribute('uri', $obj);
self::assertObjectHasAttribute('scheme', $obj);
self::assertObjectHasAttribute('host', $obj);
self::assertObjectHasAttribute('port', $obj);
self::assertObjectHasAttribute('user', $obj);
self::assertObjectHasAttribute('pass', $obj);
self::assertObjectHasAttribute('path', $obj);
self::assertObjectHasAttribute('query', $obj);
self::assertObjectHasAttribute('queryString', $obj);
self::assertObjectHasAttribute('fragment', $obj);
self::assertObjectHasAttribute('base', $obj);
}
public function testHelper() : void
{ {
self::assertTrue(Http::isValid('http://www.google.de')); self::assertTrue(Http::isValid('http://www.google.de'));
self::assertTrue(Http::isValid('http://google.de')); self::assertTrue(Http::isValid('http://google.de'));
@ -50,39 +37,138 @@ class HttpTest extends \PHPUnit\Framework\TestCase
self::assertFalse(Http::isValid('https:/google.de')); self::assertFalse(Http::isValid('https:/google.de'));
} }
public function testGeneralUriComponents() : void /**
* @testdox The http url has the expected default values after initialization
* @covers phpOMS\Uri\Http
*/
public function testDefault() : void
{
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('', $obj->getPass());
self::assertEquals('', $obj->getUser());
self::assertEquals(80, $obj->getPort());
self::assertEquals('', $obj->getUserInfo());
self::assertEquals('', $obj->getRootPath());
self::assertEquals(0, $obj->getPathOffset());
}
/**
* @testdox The url schema can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testSchemaInputOutput() : void
{
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('https', $obj->getScheme());
}
/**
* @testdox The host can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testHostInputOutput() : void
{
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('www.google.com', $obj->getHost());
}
/**
* @testdox The username can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testUsernameInputOutput() : void
{
$obj = new Http('https://username:password@google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('username', $obj->getUser());
}
/**
* @testdox The password can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testPasswordInputOutput() : void
{
$obj = new Http('https://username:password@google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('password', $obj->getPass());
}
/**
* @testdox The base can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testBaseInputOutput() : void
{
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('https://www.google.com', $obj->getBase());
}
/**
* @testdox The url can be turned into a string
* @covers phpOMS\Uri\Http
*/
public function testStringify() : void
{ {
$obj = new Http($uri = 'https://www.google.com/test/path.php?para1=abc&para2=2#frag'); $obj = new Http($uri = 'https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('https', $obj->getScheme());
self::assertEquals('www.google.com', $obj->getHost());
self::assertEquals(80, $obj->getPort());
self::assertEquals('', $obj->getPass());
self::assertEquals('', $obj->getUser());
self::assertEquals('https://www.google.com', $obj->getBase());
self::assertEquals($uri, $obj->__toString()); self::assertEquals($uri, $obj->__toString());
self::assertEquals('www.google.com:80', $obj->getAuthority());
self::assertEquals('', $obj->getUserInfo());
} }
public function testRootPath() : void /**
* @testdox The authority can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testAuthorityInputOutput() : void
{
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('www.google.com:80', $obj->getAuthority());
}
/**
* @testdox The user info can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testUserinfoInputOutput() : void
{
$obj = new Http('https://username:password@google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('username:password', $obj->getUserInfo());
}
/**
* @testdox The root path can be set and returned
* @covers phpOMS\Uri\Http
*/
public function testRootPathInputOutput() : void
{ {
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag'); $obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('', $obj->getRootPath());
$obj->setRootPath('a'); $obj->setRootPath('a');
self::assertEquals('a', $obj->getRootPath()); self::assertEquals('a', $obj->getRootPath());
} }
public function testPathOffset() : void /**
* @testdox The path offset can be set and returned
* @covers phpOMS\Uri\Http
*/
public function testPathOffsetInputOutput() : void
{ {
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag'); $obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals(0, $obj->getPathOffset());
$obj->setPathOffset(2); $obj->setPathOffset(2);
self::assertEquals(2, $obj->getPathOffset()); self::assertEquals(2, $obj->getPathOffset());
} }
/**
* @testdox The subdomain can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testSubdmonain() : void public function testSubdmonain() : void
{ {
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag'); $obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
@ -95,15 +181,32 @@ class HttpTest extends \PHPUnit\Framework\TestCase
self::assertEquals('test.www', $obj->getSubdomain()); self::assertEquals('test.www', $obj->getSubdomain());
} }
/**
* @testdox The query data can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testQueryData() : void public function testQueryData() : void
{ {
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag'); $obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('para1=abc&para2=2', $obj->getQuery()); self::assertEquals('para1=abc&para2=2', $obj->getQuery());
self::assertEquals(['para1' => 'abc', 'para2' => '2'], $obj->getQueryArray()); self::assertEquals(['para1' => 'abc', 'para2' => '2'], $obj->getQueryArray());
self::assertEquals('2', $obj->getQuery('para2')); self::assertEquals('2', $obj->getQuery('para2'));
}
/**
* @testdox The fragment data can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testFragment() : void
{
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('frag', $obj->getFragment()); self::assertEquals('frag', $obj->getFragment());
} }
/**
* @testdox The path data can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testPathData() : void public function testPathData() : void
{ {
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag'); $obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
@ -111,4 +214,14 @@ class HttpTest extends \PHPUnit\Framework\TestCase
self::assertEquals('/test/path?para1=abc&para2=2', $obj->getRoute()); self::assertEquals('/test/path?para1=abc&para2=2', $obj->getRoute());
self::assertEquals('test', $obj->getPathElement(0)); self::assertEquals('test', $obj->getPathElement(0));
} }
/**
* @testdox The route can be parsed correctly from a url
* @covers phpOMS\Uri\Http
*/
public function testRouteInputOutput() : void
{
$obj = new Http('https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('/test/path?para1=abc&para2=2', $obj->getRoute());
}
} }

View File

@ -20,54 +20,134 @@ use phpOMS\Uri\UriFactory;
require_once __DIR__ . '/../Autoloader.php'; require_once __DIR__ . '/../Autoloader.php';
/** /**
* @testdox phpOMS\tests\Uri\UriFactoryTest: Http uri / url factory
*
* @internal * @internal
*/ */
class UriFactoryTest extends \PHPUnit\Framework\TestCase class UriFactoryTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The http url factory has the expected default values after initialization
* @covers phpOMS\Uri\UriFactory
*/
public function testDefault() : void public function testDefault() : void
{ {
self::assertNull(UriFactory::getQuery('Invalid')); self::assertNull(UriFactory::getQuery('Invalid'));
self::assertFalse(UriFactory::clear('Valid5'));
} }
public function testSetGet() : void /**
* @testdox Data can be set to the factory and returned
* @covers phpOMS\Uri\UriFactory
*/
public function testQueryInputOutput() : void
{ {
self::assertTrue(UriFactory::setQuery('Valid', 'query1')); self::assertTrue(UriFactory::setQuery('Valid', 'query1'));
self::assertEquals('query1', UriFactory::getQuery('Valid')); self::assertEquals('query1', UriFactory::getQuery('Valid'));
self::assertTrue(UriFactory::setQuery('Valid', 'query2', true));
self::assertEquals('query2', UriFactory::getQuery('Valid'));
self::assertFalse(UriFactory::setQuery('Valid', 'query3', false));
self::assertEquals('query2', UriFactory::getQuery('Valid'));
self::assertTrue(UriFactory::setQuery('/valid2', 'query4'));
self::assertEquals('query4', UriFactory::getQuery('/valid2'));
} }
/**
* @testdox Data can be forcefully overwritten
* @covers phpOMS\Uri\UriFactory
*/
public function testOverwrite() : void
{
UriFactory::setQuery('Valid2', 'query1');
self::assertTrue(UriFactory::setQuery('Valid2', 'query2', true));
self::assertEquals('query2', UriFactory::getQuery('Valid2'));
}
/**
* @testdox By default data is not overwritten in the factory
* @covers phpOMS\Uri\UriFactory
*/
public function testInvalidOverwrite() : void
{
UriFactory::setQuery('Valid3', 'query1');
self::assertFalse(UriFactory::setQuery('Valid3', 'query3'));
self::assertEquals('query1', UriFactory::getQuery('Valid3'));
}
/**
* @testdox Data can be removed/cleared from the factory
* @covers phpOMS\Uri\UriFactory
*/
public function testClearing() : void public function testClearing() : void
{ {
self::assertTrue(UriFactory::clear('Valid')); UriFactory::setQuery('Valid4', 'query1');
self::assertFalse(UriFactory::clear('Valid')); self::assertTrue(UriFactory::clear('Valid4'));
self::assertNull(UriFactory::getQuery('Valid')); self::assertNull(UriFactory::getQuery('Valid4'));
self::assertEquals('query4', UriFactory::getQuery('/valid2')); }
/**
* @testdox None-existing data cannot be cleared from the factory
* @covers phpOMS\Uri\UriFactory
*/
public function testInvalidClearing() : void
{
UriFactory::setQuery('Valid5', 'query1');
self::assertTrue(UriFactory::clear('Valid5'));
self::assertFalse(UriFactory::clear('Valid5'));
}
/**
* @testdox Data can be removed from the factory by category
* @covers phpOMS\Uri\UriFactory
*/
public function testClean() : void
{
UriFactory::setQuery('\Valid6', 'query1');
UriFactory::setQuery('\Valid7', 'query2');
UriFactory::clean('\\');
self::assertNull(UriFactory::getQuery('\Valid6'));
self::assertNull(UriFactory::getQuery('\Valid7'));
}
/**
* @testdox All data can be removed from the factory with a wildcard
* @covers phpOMS\Uri\UriFactory
*/
public function testCleanWildcard() : void
{
UriFactory::setQuery('\Valid8', 'query1');
UriFactory::setQuery('.Valid9', 'query2');
UriFactory::clean('*'); UriFactory::clean('*');
self::assertNull(UriFactory::getQuery('/valid2')); self::assertNull(UriFactory::getQuery('\Valid8'));
self::assertNull(UriFactory::getQuery('.Valid9'));
}
/**
* @testdox Data can be removed from the factory with regular expression matches
* @covers phpOMS\Uri\UriFactory
*/
public function testClearingLike() : void
{
UriFactory::setQuery('/abc', 'query1');
UriFactory::setQuery('/Valid10', 'query2');
UriFactory::setQuery('/Valid11', 'query3');
self::assertTrue(UriFactory::clearLike('\/[a-zA-Z]*\d+'));
self::assertTrue(UriFactory::setQuery('/abc', 'query1'));
self::assertTrue(UriFactory::setQuery('/valid2', 'query2'));
self::assertTrue(UriFactory::setQuery('/valid3', 'query3'));
self::assertFalse(UriFactory::clearLike('\d+'));
self::assertTrue(UriFactory::clearLike('\/[a-z]*\d'));
self::assertNull(UriFactory::getQuery('/valid2')); self::assertNull(UriFactory::getQuery('/valid2'));
self::assertNull(UriFactory::getQuery('/valid3')); self::assertNull(UriFactory::getQuery('/valid3'));
self::assertEquals('query1', UriFactory::getQuery('/abc')); self::assertEquals('query1', UriFactory::getQuery('/abc'));
UriFactory::clean('/');
self::assertNull(UriFactory::getQuery('/abc'));
} }
/**
* @testdox Data whitch doesn't match the regular expression is not removed
* @covers phpOMS\Uri\UriFactory
*/
public function testInvalidClearingLike() : void
{
UriFactory::setQuery('/def', 'query1');
UriFactory::setQuery('/ghi3', 'query2');
UriFactory::setQuery('/jkl4', 'query3');
self::assertFalse(UriFactory::clearLike('\d+'));
}
/**
* @testdox A url can be build with the defined factory data and/or build specific data
* @covers phpOMS\Uri\UriFactory
*/
public function testBuilder() : void public function testBuilder() : void
{ {
$uri = 'www.test-uri.com?id={@ID}&test={.mTest}&two={/path}&hash={#hash}&none=#none&found={/not}?v={/valid2}'; $uri = 'www.test-uri.com?id={@ID}&test={.mTest}&two={/path}&hash={#hash}&none=#none&found={/not}?v={/valid2}';
@ -86,7 +166,11 @@ class UriFactoryTest extends \PHPUnit\Framework\TestCase
self::assertEquals($expected, UriFactory::build($uri, $vars)); self::assertEquals($expected, UriFactory::build($uri, $vars));
} }
public function testSetup() : void /**
* @testdox The uri factory can be set up with default values from a url and build with these default values
* @covers phpOMS\Uri\UriFactory
*/
public function testSetupBuild() : void
{ {
$uri = 'http://www.test-uri.com/path/here?id=123&ab=c#fragi'; $uri = 'http://www.test-uri.com/path/here?id=123&ab=c#fragi';

View File

@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\Compression;
use phpOMS\Utils\Compression\LZW; use phpOMS\Utils\Compression\LZW;
/** /**
* @testdox phpOMS\tests\Utils\Compression\LZWTest: LZW compression
*
* @internal * @internal
*/ */
class LZWTest extends \PHPUnit\Framework\TestCase class LZWTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox A string can be LZW compressed and uncompressed
* @covers phpOMS\Utils\Compression\LZW
*/
public function testLZW() : void public function testLZW() : void
{ {
$expected = 'This is a test'; $expected = 'This is a test';

View File

@ -18,19 +18,44 @@ use phpOMS\Localization\ISO4217CharEnum;
use phpOMS\Utils\Converter\Currency; use phpOMS\Utils\Converter\Currency;
/** /**
* @testdox phpOMS\tests\Utils\Converter\CurrencyTest: Currency converter
*
* @internal * @internal
*/ */
class CurrencyTest extends \PHPUnit\Framework\TestCase class CurrencyTest extends \PHPUnit\Framework\TestCase
{ {
public function testCurrency() : void /**
* @testdox A currency can be converted from euro to another currency
* @covers phpOMS\Utils\Converter\Currency
*/
public function testCurrencyFromEur() : void
{ {
self::assertGreaterThan(0, Currency::fromEurTo(1, ISO4217CharEnum::_USD)); self::assertGreaterThan(0, Currency::fromEurTo(1, ISO4217CharEnum::_USD));
self::assertGreaterThan(0, Currency::fromToEur(1, ISO4217CharEnum::_USD)); }
/**
* @testdox A currency can be converted to euro from another currency
* @covers phpOMS\Utils\Converter\Currency
*/
public function testCurrencyToEur() : void
{
self::assertGreaterThan(0, Currency::fromToEur(1, ISO4217CharEnum::_USD));
}
/**
* @testdox A currency can be converted from one currency to another currency
* @covers phpOMS\Utils\Converter\Currency
*/
public function testCurrency() : void
{
Currency::resetCurrencies(); Currency::resetCurrencies();
self::assertGreaterThan(0, Currency::convertCurrency(1, ISO4217CharEnum::_USD, ISO4217CharEnum::_GBP)); self::assertGreaterThan(0, Currency::convertCurrency(1, ISO4217CharEnum::_USD, ISO4217CharEnum::_GBP));
} }
/**
* @testdox A currency conversion from eur to a invalid currency throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Currency
*/
public function testInvalidFromEur() : void public function testInvalidFromEur() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -38,6 +63,10 @@ class CurrencyTest extends \PHPUnit\Framework\TestCase
Currency::fromEurTo(1, 'ERROR'); Currency::fromEurTo(1, 'ERROR');
} }
/**
* @testdox A currency conversion from a invalid currency to eur throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Currency
*/
public function testInvalidToEur() : void public function testInvalidToEur() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -45,6 +74,10 @@ class CurrencyTest extends \PHPUnit\Framework\TestCase
Currency::fromToEur(1, 'ERROR'); Currency::fromToEur(1, 'ERROR');
} }
/**
* @testdox A currency conversion from a invalid currency to a invalid currency throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Currency
*/
public function testInvalidConvert() : void public function testInvalidConvert() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);

View File

@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\Converter;
use phpOMS\Utils\Converter\File; use phpOMS\Utils\Converter\File;
/** /**
* @testdox phpOMS\tests\Utils\Converter\FileTest: File size converter
*
* @internal * @internal
*/ */
class FileTest extends \PHPUnit\Framework\TestCase class FileTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox A byte number can be converted to a string representation
* @covers phpOMS\Utils\Converter\File
*/
public function testByteSizeToString() : void public function testByteSizeToString() : void
{ {
self::assertEquals('400b', File::byteSizeToString(400)); self::assertEquals('400b', File::byteSizeToString(400));
@ -29,6 +35,10 @@ class FileTest extends \PHPUnit\Framework\TestCase
self::assertEquals('1.5gb', File::byteSizeToString(1500000000)); self::assertEquals('1.5gb', File::byteSizeToString(1500000000));
} }
/**
* @testdox A kilobyte number can be converted to a string representation
* @covers phpOMS\Utils\Converter\File
*/
public function testKilobyteSizeToString() : void public function testKilobyteSizeToString() : void
{ {
self::assertEquals('500kb', File::kilobyteSizeToString(500)); self::assertEquals('500kb', File::kilobyteSizeToString(500));

View File

@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\Converter;
use phpOMS\Utils\Converter\Ip; use phpOMS\Utils\Converter\Ip;
/** /**
* @testdox phpOMS\tests\Utils\Converter\IpTest: IP converter
*
* @internal * @internal
*/ */
class IpTest extends \PHPUnit\Framework\TestCase class IpTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox An ip can be converted to a float
* @covers phpOMS\Utils\Converter\Ip
*/
public function testIp() : void public function testIp() : void
{ {
self::assertTrue(\abs(1527532998.0 - Ip::ip2Float('91.12.77.198')) < 1); self::assertTrue(\abs(1527532998.0 - Ip::ip2Float('91.12.77.198')) < 1);

View File

@ -28,10 +28,16 @@ use phpOMS\Utils\Converter\VolumeType;
use phpOMS\Utils\Converter\WeightType; use phpOMS\Utils\Converter\WeightType;
/** /**
* @testdox phpOMS\tests\Utils\Converter\MeasurementTest: Measurement converter
*
* @internal * @internal
*/ */
class MeasurementTest extends \PHPUnit\Framework\TestCase class MeasurementTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox Temperatures can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testTemperature() : void public function testTemperature() : void
{ {
$temps = TemperatureType::getConstants(); $temps = TemperatureType::getConstants();
@ -39,11 +45,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($temps as $from) { foreach ($temps as $from) {
foreach ($temps as $to) { foreach ($temps as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertTemperature(Measurement::convertTemperature($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertTemperature(Measurement::convertTemperature($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Weights can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testWeight() : void public function testWeight() : void
{ {
$weights = WeightType::getConstants(); $weights = WeightType::getConstants();
@ -51,11 +65,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($weights as $from) { foreach ($weights as $from) {
foreach ($weights as $to) { foreach ($weights as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertWeight(Measurement::convertWeight($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertWeight(Measurement::convertWeight($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Lengths can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testLength() : void public function testLength() : void
{ {
$lengths = LengthType::getConstants(); $lengths = LengthType::getConstants();
@ -63,11 +85,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($lengths as $from) { foreach ($lengths as $from) {
foreach ($lengths as $to) { foreach ($lengths as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertLength(Measurement::convertLength($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertLength(Measurement::convertLength($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Areas can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testArea() : void public function testArea() : void
{ {
$areas = AreaType::getConstants(); $areas = AreaType::getConstants();
@ -75,11 +105,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($areas as $from) { foreach ($areas as $from) {
foreach ($areas as $to) { foreach ($areas as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertArea(Measurement::convertArea($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertArea(Measurement::convertArea($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Volumes can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testVolume() : void public function testVolume() : void
{ {
$volumes = VolumeType::getConstants(); $volumes = VolumeType::getConstants();
@ -87,11 +125,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($volumes as $from) { foreach ($volumes as $from) {
foreach ($volumes as $to) { foreach ($volumes as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertVolume(Measurement::convertVolume($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertVolume(Measurement::convertVolume($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Speeds can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testSpeed() : void public function testSpeed() : void
{ {
$speeds = SpeedType::getConstants(); $speeds = SpeedType::getConstants();
@ -99,11 +145,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($speeds as $from) { foreach ($speeds as $from) {
foreach ($speeds as $to) { foreach ($speeds as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertSpeed(Measurement::convertSpeed($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertSpeed(Measurement::convertSpeed($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Times can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testTime() : void public function testTime() : void
{ {
$times = TimeType::getConstants(); $times = TimeType::getConstants();
@ -111,11 +165,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($times as $from) { foreach ($times as $from) {
foreach ($times as $to) { foreach ($times as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertTime(Measurement::convertTime($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertTime(Measurement::convertTime($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Angles can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testAngle() : void public function testAngle() : void
{ {
$angles = AngleType::getConstants(); $angles = AngleType::getConstants();
@ -123,11 +185,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($angles as $from) { foreach ($angles as $from) {
foreach ($angles as $to) { foreach ($angles as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertAngle(Measurement::convertAngle($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertAngle(Measurement::convertAngle($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Pressures can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testPressure() : void public function testPressure() : void
{ {
$pressures = PressureType::getConstants(); $pressures = PressureType::getConstants();
@ -135,11 +205,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($pressures as $from) { foreach ($pressures as $from) {
foreach ($pressures as $to) { foreach ($pressures as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertPressure(Measurement::convertPressure($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertPressure(Measurement::convertPressure($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Energies can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testEnergy() : void public function testEnergy() : void
{ {
$energies = EnergyPowerType::getConstants(); $energies = EnergyPowerType::getConstants();
@ -147,11 +225,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($energies as $from) { foreach ($energies as $from) {
foreach ($energies as $to) { foreach ($energies as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertEnergy(Measurement::convertEnergy($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertEnergy(Measurement::convertEnergy($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Filesizes can be converted
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testFileSize() : void public function testFileSize() : void
{ {
$fileSizes = FileSizeType::getConstants(); $fileSizes = FileSizeType::getConstants();
@ -159,11 +245,19 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
foreach ($fileSizes as $from) { foreach ($fileSizes as $from) {
foreach ($fileSizes as $to) { foreach ($fileSizes as $to) {
$rand = \mt_rand(0, 100); $rand = \mt_rand(0, 100);
self::assertTrue(($rand - Measurement::convertFileSize(Measurement::convertFileSize($rand, $from, $to), $to, $from)) < 1); if ($rand - Measurement::convertFileSize(Measurement::convertFileSize($rand, $from, $to), $to, $from) >= 1) {
self::assertTrue(false);
}
} }
} }
self::assertTrue(true);
} }
/**
* @testdox Invalid convertion from unknown temperature throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidTemperatureFrom() : void public function testInvalidTemperatureFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -171,6 +265,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertTemperature(1.1, 'invalid', TemperatureType::CELSIUS); Measurement::convertTemperature(1.1, 'invalid', TemperatureType::CELSIUS);
} }
/**
* @testdox Invalid convertion to unknown temperature throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidTemperatureTo() : void public function testInvalidTemperatureTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -178,6 +276,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertTemperature(1.1, TemperatureType::CELSIUS, 'invalid'); Measurement::convertTemperature(1.1, TemperatureType::CELSIUS, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown weight throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidWeightFrom() : void public function testInvalidWeightFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -185,6 +287,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertWeight(1.1, 'invalid', WeightType::KILOGRAM); Measurement::convertWeight(1.1, 'invalid', WeightType::KILOGRAM);
} }
/**
* @testdox Invalid convertion to unknown weight throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidWeightTo() : void public function testInvalidWeightTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -192,6 +298,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertWeight(1.1, WeightType::KILOGRAM, 'invalid'); Measurement::convertWeight(1.1, WeightType::KILOGRAM, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown length throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidLengthFrom() : void public function testInvalidLengthFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -199,6 +309,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertLength(1.1, 'invalid', LengthType::METERS); Measurement::convertLength(1.1, 'invalid', LengthType::METERS);
} }
/**
* @testdox Invalid convertion to unknown length throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidLengthTo() : void public function testInvalidLengthTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -206,6 +320,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertLength(1.1, LengthType::METERS, 'invalid'); Measurement::convertLength(1.1, LengthType::METERS, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown area throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidAreaFrom() : void public function testInvalidAreaFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -213,6 +331,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertArea(1.1, 'invalid', AreaType::SQUARE_METERS); Measurement::convertArea(1.1, 'invalid', AreaType::SQUARE_METERS);
} }
/**
* @testdox Invalid convertion to unknown area throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidAreaTo() : void public function testInvalidAreaTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -220,6 +342,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertArea(1.1, AreaType::SQUARE_METERS, 'invalid'); Measurement::convertArea(1.1, AreaType::SQUARE_METERS, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown volume throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidVolumeFrom() : void public function testInvalidVolumeFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -227,6 +353,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertVolume(1.1, 'invalid', VolumeType::LITER); Measurement::convertVolume(1.1, 'invalid', VolumeType::LITER);
} }
/**
* @testdox Invalid convertion to unknown volume throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidVolumeTo() : void public function testInvalidVolumeTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -234,6 +364,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertVolume(1.1, VolumeType::LITER, 'invalid'); Measurement::convertVolume(1.1, VolumeType::LITER, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown speed throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidSpeedFrom() : void public function testInvalidSpeedFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -241,6 +375,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertSpeed(1.1, 'invalid', SpeedType::KILOMETERS_PER_HOUR); Measurement::convertSpeed(1.1, 'invalid', SpeedType::KILOMETERS_PER_HOUR);
} }
/**
* @testdox Invalid convertion to unknown speed throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidSpeedTo() : void public function testInvalidSpeedTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -248,6 +386,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertSpeed(1.1, SpeedType::KILOMETERS_PER_HOUR, 'invalid'); Measurement::convertSpeed(1.1, SpeedType::KILOMETERS_PER_HOUR, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown time throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidTimeFrom() : void public function testInvalidTimeFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -255,6 +397,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertTime(1.1, 'invalid', TimeType::HOURS); Measurement::convertTime(1.1, 'invalid', TimeType::HOURS);
} }
/**
* @testdox Invalid convertion to unknown time throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidTimeTo() : void public function testInvalidTimeTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -262,6 +408,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertTime(1.1, TimeType::HOURS, 'invalid'); Measurement::convertTime(1.1, TimeType::HOURS, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown angle throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidAngleFrom() : void public function testInvalidAngleFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -269,6 +419,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertAngle(1.1, 'invalid', AngleType::RADIAN); Measurement::convertAngle(1.1, 'invalid', AngleType::RADIAN);
} }
/**
* @testdox Invalid convertion to unknown angle throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidAngleTo() : void public function testInvalidAngleTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -276,6 +430,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertAngle(1.1, AngleType::RADIAN, 'invalid'); Measurement::convertAngle(1.1, AngleType::RADIAN, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown pressure throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidPressureFrom() : void public function testInvalidPressureFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -283,6 +441,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertPressure(1.1, 'invalid', PressureType::BAR); Measurement::convertPressure(1.1, 'invalid', PressureType::BAR);
} }
/**
* @testdox Invalid convertion to unknown pressure throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidPressureTo() : void public function testInvalidPressureTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -290,6 +452,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertPressure(1.1, PressureType::BAR, 'invalid'); Measurement::convertPressure(1.1, PressureType::BAR, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown energy throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidEnergyPowerFrom() : void public function testInvalidEnergyPowerFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -297,6 +463,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertEnergy(1.1, 'invalid', EnergyPowerType::JOULS); Measurement::convertEnergy(1.1, 'invalid', EnergyPowerType::JOULS);
} }
/**
* @testdox Invalid convertion to unknown energy throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidEnergyPowerTo() : void public function testInvalidEnergyPowerTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -304,6 +474,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertEnergy(1.1, EnergyPowerType::JOULS, 'invalid'); Measurement::convertEnergy(1.1, EnergyPowerType::JOULS, 'invalid');
} }
/**
* @testdox Invalid convertion from unknown filesize throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidFileSizeFrom() : void public function testInvalidFileSizeFrom() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -311,6 +485,10 @@ class MeasurementTest extends \PHPUnit\Framework\TestCase
Measurement::convertFileSize(1.1, 'invalid', FileSizeType::KILOBYTE); Measurement::convertFileSize(1.1, 'invalid', FileSizeType::KILOBYTE);
} }
/**
* @testdox Invalid convertion to unknown filesize throws a InvalidArgumentException
* @covers phpOMS\Utils\Converter\Measurement
*/
public function testInvalidFileSizeTo() : void public function testInvalidFileSizeTo() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);

View File

@ -17,11 +17,17 @@ namespace phpOMS\tests\Utils\Converter;
use phpOMS\Utils\Converter\Numeric; use phpOMS\Utils\Converter\Numeric;
/** /**
* @testdox phpOMS\tests\Utils\Converter\NumericTest: Numeric converter
*
* @internal * @internal
*/ */
class NumericTest extends \PHPUnit\Framework\TestCase class NumericTest extends \PHPUnit\Framework\TestCase
{ {
public function testArabicRoman() : void /**
* @testdox Arabic numbers can be converted to roman numbers
* @covers phpOMS\Utils\Converter\Numeric
*/
public function testArabicToRoman() : void
{ {
$rand = \mt_rand(1, 9999); $rand = \mt_rand(1, 9999);
self::assertEquals($rand, Numeric::romanToArabic(Numeric::arabicToRoman($rand))); self::assertEquals($rand, Numeric::romanToArabic(Numeric::arabicToRoman($rand)));
@ -32,17 +38,44 @@ class NumericTest extends \PHPUnit\Framework\TestCase
self::assertEquals('XI', Numeric::arabicToRoman(11)); self::assertEquals('XI', Numeric::arabicToRoman(11));
} }
public function testAlphaNumeric() : void /**
* @testdox Roman numbers can be converted to arabic numbers
* @covers phpOMS\Utils\Converter\Numeric
*/
public function testRomanToArabic() : void
{
self::assertEquals(8, Numeric::romanToArabic('VIII'));
self::assertEquals(9, Numeric::romanToArabic('IX'));
self::assertEquals(10, Numeric::romanToArabic('X'));
self::assertEquals(11, Numeric::romanToArabic('XI'));
}
/**
* @testdox Letters can be converted to numbers
* @covers phpOMS\Utils\Converter\Numeric
*/
public function testAlphaToNumeric() : void
{ {
self::assertEquals(0, Numeric::alphaToNumeric('A')); self::assertEquals(0, Numeric::alphaToNumeric('A'));
self::assertEquals(1, Numeric::alphaToNumeric('B')); self::assertEquals(1, Numeric::alphaToNumeric('B'));
self::assertEquals(53, Numeric::alphaToNumeric('BB')); self::assertEquals(53, Numeric::alphaToNumeric('BB'));
}
/**
* @testdox Numbers can be converted to letters
* @covers phpOMS\Utils\Converter\Numeric
*/
public function testNumericToAlpha() : void
{
self::assertEquals('A', Numeric::numericToAlpha(0)); self::assertEquals('A', Numeric::numericToAlpha(0));
self::assertEquals('B', Numeric::numericToAlpha(1)); self::assertEquals('B', Numeric::numericToAlpha(1));
self::assertEquals('BB', Numeric::numericToAlpha(53)); self::assertEquals('BB', Numeric::numericToAlpha(53));
} }
/**
* @testdox Numbers can be converted between bases
* @covers phpOMS\Utils\Converter\Numeric
*/
public function testBase() : void public function testBase() : void
{ {
self::assertEquals('443', Numeric::convertBase('123', '0123456789', '01234')); self::assertEquals('443', Numeric::convertBase('123', '0123456789', '01234'));

View File

@ -18,21 +18,21 @@ use phpOMS\Utils\Encoding\Caesar;
use phpOMS\Utils\RnG\StringUtils; use phpOMS\Utils\RnG\StringUtils;
/** /**
* @testdox phpOMS\tests\Utils\Encoding\CaesarTest: Caesar text encoding/decoding
* @internal * @internal
*/ */
class CaesarTest extends \PHPUnit\Framework\TestCase class CaesarTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @testdox Text can be encoded and decoded with the ceasar encoding
* @covers phpOMS\Utils\Encoding\Caesar * @covers phpOMS\Utils\Encoding\Caesar
*/ */
public function testVolume() : void public function testEncoding() : void
{ {
for ($i = 0; $i < 100; ++$i) { $raw = StringUtils::generateString(1, 100);
$raw = StringUtils::generateString(1, 100); $key = StringUtils::generateString(1, 100);
$key = StringUtils::generateString(1, 100);
self::assertNotEquals($raw, Caesar::encode($raw, $key)); self::assertNotEquals($raw, Caesar::encode($raw, $key));
self::assertEquals($raw, Caesar::decode(Caesar::encode($raw, $key), $key)); self::assertEquals($raw, Caesar::decode(Caesar::encode($raw, $key), $key));
}
} }
} }

View File

@ -17,11 +17,14 @@ namespace phpOMS\tests\Utils\Encoding;
use phpOMS\Utils\Encoding\Gray; use phpOMS\Utils\Encoding\Gray;
/** /**
* @testdox phpOMS\tests\Utils\Encoding\GrayTest: Gray text encoding/decoding
*
* @internal * @internal
*/ */
class GrayTest extends \PHPUnit\Framework\TestCase class GrayTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @testdox Text can be encoded and decoded with the gray encoding
* @covers phpOMS\Utils\Encoding\Gray * @covers phpOMS\Utils\Encoding\Gray
*/ */
public function testEncoding() : void public function testEncoding() : void
@ -29,16 +32,4 @@ class GrayTest extends \PHPUnit\Framework\TestCase
self::assertEquals(55, Gray::encode(37)); self::assertEquals(55, Gray::encode(37));
self::assertEquals(37, Gray::decode(55)); self::assertEquals(37, Gray::decode(55));
} }
/**
* @covers phpOMS\Utils\Encoding\Gray
*/
public function testVolume() : void
{
for ($i = 0; $i < 100; ++$i) {
$raw = \mt_rand(0, 2040140512);
self::assertEquals($raw, Gray::decode(Gray::encode($raw)));
}
}
} }

View File

@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\Encoding\Huffman;
use phpOMS\Utils\Encoding\Huffman\Dictionary; use phpOMS\Utils\Encoding\Huffman\Dictionary;
/** /**
* @testdox phpOMS\tests\Utils\Encoding\Huffman\DictionaryTest: Dictionary for the huffman encoding
*
* @internal * @internal
*/ */
class DictionaryTest extends \PHPUnit\Framework\TestCase class DictionaryTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox Only single characters can be returned from the dictionary. Multiple characters throw a InvalidArgumentException
* @covers phpOMS\Utils\Encoding\Huffman\Dictionary
*/
public function testInvalidGetCharacter() : void public function testInvalidGetCharacter() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -29,6 +35,10 @@ class DictionaryTest extends \PHPUnit\Framework\TestCase
$dict->get('as'); $dict->get('as');
} }
/**
* @testdox A none-existing character throws a InvalidArgumentException
* @covers phpOMS\Utils\Encoding\Huffman\Dictionary
*/
public function testNotExistingGetCharacter() : void public function testNotExistingGetCharacter() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -37,6 +47,10 @@ class DictionaryTest extends \PHPUnit\Framework\TestCase
$dict->get('a'); $dict->get('a');
} }
/**
* @testdox Only single chracters can be set in the dictionary. Multiple characters throw a InvalidArgumentException
* @covers phpOMS\Utils\Encoding\Huffman\Dictionary
*/
public function testInvalidSetCharacter() : void public function testInvalidSetCharacter() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -45,6 +59,10 @@ class DictionaryTest extends \PHPUnit\Framework\TestCase
$dict->set('as', 'test'); $dict->set('as', 'test');
} }
/**
* @testdox Dictionary elements cannot be overwritten and throw a InvalidArgumentException
* @covers phpOMS\Utils\Encoding\Huffman\Dictionary
*/
public function testInvalidSetDuplicateCharacter() : void public function testInvalidSetDuplicateCharacter() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -54,6 +72,10 @@ class DictionaryTest extends \PHPUnit\Framework\TestCase
$dict->set('a', '1'); $dict->set('a', '1');
} }
/**
* @testdox Invalid dictionary values throw a InvalidArgumentException
* @covers phpOMS\Utils\Encoding\Huffman\Dictionary
*/
public function testInvalidFormattedValue() : void public function testInvalidFormattedValue() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);

View File

@ -17,10 +17,26 @@ namespace phpOMS\tests\Utils\Encoding\Huffman;
use phpOMS\Utils\Encoding\Huffman\Huffman; use phpOMS\Utils\Encoding\Huffman\Huffman;
/** /**
* @testdox phpOMS\tests\Utils\Encoding\Huffman\HuffmanTest: Data can be ecoded with huffman
*
* @internal * @internal
*/ */
class HuffmanTest extends \PHPUnit\Framework\TestCase class HuffmanTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox Encoding and decoding empty data results in an empty output
*/
public function testEmpty() : void
{
$huff = new Huffman();
self::assertEquals('', $huff->encode(''));
self::assertEquals('', $huff->decode(''));
}
/**
* @testdox Data can be huffman encoded and decoded
*/
public function testHuffman() : void public function testHuffman() : void
{ {
$huff = new Huffman(); $huff = new Huffman();
@ -30,8 +46,6 @@ class HuffmanTest extends \PHPUnit\Framework\TestCase
$huff->encode('This is a test message in order to test the encoding and decoding of the Huffman algorithm.') $huff->encode('This is a test message in order to test the encoding and decoding of the Huffman algorithm.')
); );
self::assertEquals('', $huff->encode(''));
$man = new Huffman(); $man = new Huffman();
$man->setDictionary($huff->getDictionary()); $man->setDictionary($huff->getDictionary());
@ -39,7 +53,5 @@ class HuffmanTest extends \PHPUnit\Framework\TestCase
'This is a test message in order to test the encoding and decoding of the Huffman algorithm.', 'This is a test message in order to test the encoding and decoding of the Huffman algorithm.',
$man->decode(\hex2bin('a42f5debafd35bee6a940f78f38638fb3f4d6fd13cc672cf01d61bb1ce59e03cdbe89e8e56b5d63aa61387d1ba10')) $man->decode(\hex2bin('a42f5debafd35bee6a940f78f38638fb3f4d6fd13cc672cf01d61bb1ce59e03cdbe89e8e56b5d63aa61387d1ba10'))
); );
self::assertEquals('', $man->decode(''));
} }
} }

View File

@ -18,24 +18,20 @@ use phpOMS\Utils\Encoding\XorEncoding;
use phpOMS\Utils\RnG\StringUtils; use phpOMS\Utils\RnG\StringUtils;
/** /**
* @testdox phpOMS\tests\Utils\Encoding\XorEncodingTest: XOR text encoding/decoding
*
* @internal * @internal
*/ */
class XorEncodingTest extends \PHPUnit\Framework\TestCase class XorEncodingTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox Text can be encoded and decoded with the xor encoding
* @covers phpOMS\Utils\Encoding\XorEncoding
*/
public function testEncoding() : void public function testEncoding() : void
{ {
$test = XorEncoding::encode('This is a test.', 'abcd'); $test = XorEncoding::encode('This is a test.', 'abcd');
self::assertEquals(\hex2bin('350a0a17410b10440042170112164d'), XorEncoding::encode('This is a test.', 'abcd')); self::assertEquals(\hex2bin('350a0a17410b10440042170112164d'), XorEncoding::encode('This is a test.', 'abcd'));
self::assertEquals('This is a test.', XorEncoding::decode(\hex2bin('350a0a17410b10440042170112164d'), 'abcd')); self::assertEquals('This is a test.', XorEncoding::decode(\hex2bin('350a0a17410b10440042170112164d'), 'abcd'));
} }
public function testVolume() : void
{
for ($i = 0; $i < 100; ++$i) {
$raw = StringUtils::generateString(1, 100);
$key = StringUtils::generateString(1, 100);
self::assertEquals($raw, XorEncoding::decode(XorEncoding::encode($raw, $key), $key));
}
}
} }

View File

@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\Git;
use phpOMS\Utils\Git\Author; use phpOMS\Utils\Git\Author;
/** /**
* @testdox phpOMS\tests\Utils\Git\AuthorTest: Git author
*
* @internal * @internal
*/ */
class AuthorTest extends \PHPUnit\Framework\TestCase class AuthorTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The author has the expected default values after initialization
* @covers phpOMS\Utils\Git\Author
*/
public function testDefault() : void public function testDefault() : void
{ {
$author = new Author(); $author = new Author();
@ -31,17 +37,48 @@ class AuthorTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $author->getRemovalCount()); self::assertEquals(0, $author->getRemovalCount());
} }
public function testGetSet() : void /**
* @testdox The author name and email can be set during initialization and returned
* @covers phpOMS\Utils\Git\Author
*/
public function testConstructInputOutput() : void
{ {
$author = new Author('test', 'email'); $author = new Author('test', 'email');
self::assertEquals('test', $author->getName()); self::assertEquals('test', $author->getName());
self::assertEquals('email', $author->getEmail()); self::assertEquals('email', $author->getEmail());
}
/**
* @testdox The commit count can be set and returned
* @covers phpOMS\Utils\Git\Author
*/
public function testCommitCountInputOutput() : void
{
$author = new Author('test', 'email');
$author->setCommitCount(1); $author->setCommitCount(1);
self::assertEquals(1, $author->getCommitCount()); self::assertEquals(1, $author->getCommitCount());
}
/**
* @testdox The addition count can be set and returned
* @covers phpOMS\Utils\Git\Author
*/
public function testAdditionCountInputOutput() : void
{
$author = new Author('test', 'email');
$author->setAdditionCount(2); $author->setAdditionCount(2);
self::assertEquals(2, $author->getAdditionCount()); self::assertEquals(2, $author->getAdditionCount());
}
/**
* @testdox The removal count can be set and returned
* @covers phpOMS\Utils\Git\Author
*/
public function testRemovalCountInputOutput() : void
{
$author = new Author('test', 'email');
$author->setRemovalCount(3); $author->setRemovalCount(3);
self::assertEquals(3, $author->getRemovalCount()); self::assertEquals(3, $author->getRemovalCount());

View File

@ -17,17 +17,27 @@ namespace phpOMS\tests\Utils\Git;
use phpOMS\Utils\Git\Branch; use phpOMS\Utils\Git\Branch;
/** /**
* @testdox phpOMS\tests\Utils\Git\BranchTest: Git branch
*
* @internal * @internal
*/ */
class BranchTest extends \PHPUnit\Framework\TestCase class BranchTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The branch has the expected default values after initialization
* @covers phpOMS\Utils\Git\Branch
*/
public function testDefault() : void public function testDefault() : void
{ {
$branch = new Branch(); $branch = new Branch();
self::assertEquals('', $branch->getName()); self::assertEquals('', $branch->getName());
} }
public function testGetSet() : void /**
* @testdox The branch name can be set during initialization and returned
* @covers phpOMS\Utils\Git\Branch
*/
public function testConstructInputOutput() : void
{ {
$branch = new Branch('test'); $branch = new Branch('test');
self::assertEquals('test', $branch->getName()); self::assertEquals('test', $branch->getName());

View File

@ -21,10 +21,16 @@ use phpOMS\Utils\Git\Repository;
use phpOMS\Utils\Git\Tag; use phpOMS\Utils\Git\Tag;
/** /**
* @testdox phpOMS\tests\Utils\Git\CommitTest: Git commit
*
* @internal * @internal
*/ */
class CommitTest extends \PHPUnit\Framework\TestCase class CommitTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The commit has the expected default values after initialization
* @covers phpOMS\Utils\Git\Commit
*/
public function testDefault() : void public function testDefault() : void
{ {
$commit = new Commit(); $commit = new Commit();
@ -38,26 +44,67 @@ class CommitTest extends \PHPUnit\Framework\TestCase
self::assertInstanceOf('\DateTime', $commit->getDate()); self::assertInstanceOf('\DateTime', $commit->getDate());
} }
public function testAddRemoveFile() : void /**
* @testdox A file can be added and returned
* @covers phpOMS\Utils\Git\Commit
*/
public function testFileInputOutput() : void
{ {
$commit = new Commit(); $commit = new Commit();
self::assertTrue($commit->addFile('/some/file/path')); self::assertTrue($commit->addFile('/some/file/path'));
self::assertFalse($commit->addFile('/some/file/path'));
self::assertTrue($commit->addFile('/some/file/path2')); self::assertTrue($commit->addFile('/some/file/path2'));
self::assertEquals([ self::assertEquals([
'/some/file/path' => [], '/some/file/path' => [],
'/some/file/path2' => [], '/some/file/path2' => [],
], $commit->getFiles()); ], $commit->getFiles());
}
/**
* @testdox A file can only be added one time
* @covers phpOMS\Utils\Git\Commit
*/
public function testInvalidOverwrite() : void
{
$commit = new Commit();
self::assertTrue($commit->addFile('/some/file/path'));
self::assertFalse($commit->addFile('/some/file/path'));
}
/**
* @testdox A file can be removed
* @covers phpOMS\Utils\Git\Commit
*/
public function testRemoveFile() : void
{
$commit = new Commit();
self::assertTrue($commit->addFile('/some/file/path'));
self::assertTrue($commit->addFile('/some/file/path2'));
self::assertFalse($commit->removeFile('/some/file/path3'));
self::assertTrue($commit->removeFile('/some/file/path')); self::assertTrue($commit->removeFile('/some/file/path'));
self::assertEquals([ self::assertEquals([
'/some/file/path2' => [], '/some/file/path2' => [],
], $commit->getFiles()); ], $commit->getFiles());
} }
public function testChanges() : void /**
* @testdox A none-existing file cannot be removed
* @covers phpOMS\Utils\Git\Commit
*/
public function testInvalidRemoveFile() : void
{
$commit = new Commit();
self::assertFalse($commit->removeFile('/some/file/path3'));
}
/**
* @testdox A change can be added and returned
* @covers phpOMS\Utils\Git\Commit
*/
public function testChangeInputOutput() : void
{ {
$commit = new Commit(); $commit = new Commit();
@ -73,6 +120,10 @@ class CommitTest extends \PHPUnit\Framework\TestCase
], $commit->getFiles()); ], $commit->getFiles());
} }
/**
* @testdox Adding the same change throws a Exception
* @covers phpOMS\Utils\Git\Commit
*/
public function testDuplicateLineChange() : void public function testDuplicateLineChange() : void
{ {
self::expectException(\Exception::class); self::expectException(\Exception::class);
@ -82,7 +133,11 @@ class CommitTest extends \PHPUnit\Framework\TestCase
$commit->addChanges(__DIR__ . '/CommitTest.php', 1, '<?php', 'test'); $commit->addChanges(__DIR__ . '/CommitTest.php', 1, '<?php', 'test');
} }
public function testMessage() : void /**
* @testdox A commit message can be set and returned
* @covers phpOMS\Utils\Git\Commit
*/
public function testMessageInputOutput() : void
{ {
$commit = new Commit(); $commit = new Commit();
@ -90,7 +145,11 @@ class CommitTest extends \PHPUnit\Framework\TestCase
self::assertEquals('My Message', $commit->getMessage()); self::assertEquals('My Message', $commit->getMessage());
} }
public function testAuthor() : void /**
* @testdox The author can be set and returned
* @covers phpOMS\Utils\Git\Commit
*/
public function testAuthorInputOutput() : void
{ {
$commit = new Commit(); $commit = new Commit();
@ -98,7 +157,11 @@ class CommitTest extends \PHPUnit\Framework\TestCase
self::assertEquals('Orange', $commit->getAuthor()->getName()); self::assertEquals('Orange', $commit->getAuthor()->getName());
} }
public function testBranch() : void /**
* @testdox The branch can be set and returned
* @covers phpOMS\Utils\Git\Commit
*/
public function testBranchInputOutput() : void
{ {
$commit = new Commit(); $commit = new Commit();
@ -106,7 +169,11 @@ class CommitTest extends \PHPUnit\Framework\TestCase
self::assertEquals('develop', $commit->getBranch()->getName()); self::assertEquals('develop', $commit->getBranch()->getName());
} }
public function testTag() : void /**
* @testdox The tag can be set and returned
* @covers phpOMS\Utils\Git\Commit
*/
public function testTagInputOutput() : void
{ {
$commit = new Commit(); $commit = new Commit();
@ -114,7 +181,11 @@ class CommitTest extends \PHPUnit\Framework\TestCase
self::assertEquals('1.0.0', $commit->getTag()->getName()); self::assertEquals('1.0.0', $commit->getTag()->getName());
} }
public function testDate() : void /**
* @testdox The date can be set and returned
* @covers phpOMS\Utils\Git\Commit
*/
public function testDateInputOutput() : void
{ {
$commit = new Commit(); $commit = new Commit();
@ -122,7 +193,11 @@ class CommitTest extends \PHPUnit\Framework\TestCase
self::assertEquals($date->format('Y-m-d'), $commit->getDate()->format('Y-m-d')); self::assertEquals($date->format('Y-m-d'), $commit->getDate()->format('Y-m-d'));
} }
public function testRepository() : void /**
* @testdox The repository can be set and returned
* @covers phpOMS\Utils\Git\Commit
*/
public function testRepositoryInputOutput() : void
{ {
$commit = new Commit(); $commit = new Commit();

View File

@ -17,11 +17,17 @@ namespace phpOMS\tests\Utils\Git;
use phpOMS\Utils\Git\Git; use phpOMS\Utils\Git\Git;
/** /**
* @testdox phpOMS\tests\Utils\Git\GitTest: Git utilities
*
* @internal * @internal
*/ */
class GitTest extends \PHPUnit\Framework\TestCase class GitTest extends \PHPUnit\Framework\TestCase
{ {
public function testDefault() : void /**
* @testdox The git path can be returned
* @covers phpOMS\Utils\Git\Git
*/
public function testBinary() : void
{ {
self::assertEquals('/usr/bin/git', Git::getBin()); self::assertEquals('/usr/bin/git', Git::getBin());
} }

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Utils\Git;
use phpOMS\Utils\Git\Repository; use phpOMS\Utils\Git\Repository;
/** /**
* @testdox phpOMS\tests\Utils\Git\RepositoryTest: Git repository
*
* @internal * @internal
* @todo create tests for other functions
*/ */
class RepositoryTest extends \PHPUnit\Framework\TestCase class RepositoryTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The repository has the expected default values after initialization
* @covers phpOMS\Utils\Git\Repository
*/
public function testDefault() : void public function testDefault() : void
{ {
$repo = new Repository(\realpath(__DIR__ . '/../../../')); $repo = new Repository(\realpath(__DIR__ . '/../../../'));

View File

@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\Git;
use phpOMS\Utils\Git\Tag; use phpOMS\Utils\Git\Tag;
/** /**
* @testdox phpOMS\tests\Utils\Git\TagTest: Git tag
*
* @internal * @internal
*/ */
class TagTest extends \PHPUnit\Framework\TestCase class TagTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The tag has the expected default values after initialization
* @covers phpOMS\Utils\Git\Repository
*/
public function testDefault() : void public function testDefault() : void
{ {
$tag = new Tag(); $tag = new Tag();
@ -28,10 +34,23 @@ class TagTest extends \PHPUnit\Framework\TestCase
self::assertEquals('', $tag->getName()); self::assertEquals('', $tag->getName());
} }
public function testGetSet() : void /**
* @testdox The tag name can be set during initialization and returned
* @covers phpOMS\Utils\Git\Repository
*/
public function testConstructorInputOutput() : void
{ {
$tag = new Tag('test'); $tag = new Tag('test');
self::assertEquals('test', $tag->getName()); self::assertEquals('test', $tag->getName());
}
/**
* @testdox The message can be set and returned
* @covers phpOMS\Utils\Git\Repository
*/
public function testMessageInputOutput() : void
{
$tag = new Tag('test');
$tag->setMessage('msg'); $tag->setMessage('msg');
self::assertEquals('msg', $tag->getMessage()); self::assertEquals('msg', $tag->getMessage());

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Utils\IO\Csv;
use phpOMS\Utils\IO\Csv\CsvSettings; use phpOMS\Utils\IO\Csv\CsvSettings;
/** /**
* @testdox phpOMS\tests\Utils\IO\Csv\CsvSettingsTest: Csv file settings
*
* @internal * @internal
*/ */
class CsvSettingsTest extends \PHPUnit\Framework\TestCase class CsvSettingsTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The delimitar in a csv file can be guessed
* @covers phpOMS\Utils\IO\Csv\CsvSettings
*/
public function testDelimiter() : void public function testDelimiter() : void
{ {
self::assertEquals(':', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/colon.csv', 'r'))); self::assertEquals(':', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/colon.csv', 'r')));

View File

@ -12,18 +12,20 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Utils\IO\Excel; namespace phpOMS\tests\Utils\IO\Spreadsheet;
use phpOMS\DataStorage\Database\Connection\SQLiteConnection; use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\Utils\IO\Excel\ExcelDatabaseMapper; use phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper;
use tests\Autoloader; use tests\Autoloader;
use phpOMS\Utils\StringUtils; use phpOMS\Utils\StringUtils;
/** /**
* @testdox phpOMS\tests\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapperTest: Spreadsheet database mapper
*
* @internal * @internal
*/ */
class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
{ {
protected $sqlite; protected $sqlite;
@ -54,12 +56,13 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper * @testdox Data can be inserted into a database from an ods files
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper
*/ */
public function testInsertOds() : void public function testInsertOds() : void
{ {
Autoloader::addPath(__DIR__ . '/../../../../../Resources/'); Autoloader::addPath(__DIR__ . '/../../../../../Resources/');
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -88,11 +91,12 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::insert * @testdox Data can be inserted into a database from a xls files
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper::insert
*/ */
public function testInsertXls() : void public function testInsertXls() : void
{ {
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -121,11 +125,12 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::insert * @testdox Data can be inserted into a database from a xlsx files
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper::insert
*/ */
public function testInsertXlsx() : void public function testInsertXlsx() : void
{ {
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -154,11 +159,12 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::update * @testdox Data can be updated in a database from an ods files
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper::update
*/ */
public function testUpdateOds() : void public function testUpdateOds() : void
{ {
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -185,7 +191,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
$data $data
); );
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/update.ods'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/update.ods');
$mapper->update(); $mapper->update();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -214,11 +220,12 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::update * @testdox Data can be updated in a database from a xls files
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper::update
*/ */
public function testUpdateXls() : void public function testUpdateXls() : void
{ {
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -245,7 +252,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
$data $data
); );
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/update.xls'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/update.xls');
$mapper->update(); $mapper->update();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -274,11 +281,12 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::update * @testdox Data can be updated in a database from a xlsx files
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper::update
*/ */
public function testUpdateXlsx() : void public function testUpdateXlsx() : void
{ {
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -305,7 +313,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
$data $data
); );
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/update.xlsx'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/update.xlsx');
$mapper->update(); $mapper->update();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -334,7 +342,8 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::select * @testdox Data can be inserted into an ods files from a database
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper::select
*/ */
public function testSelectOds() : void public function testSelectOds() : void
{ {
@ -342,7 +351,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
\unlink(__DIR__ . '/select.ods'); \unlink(__DIR__ . '/select.ods');
} }
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -369,7 +378,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
$data $data
); );
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/select.ods'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/select.ods');
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1'); $data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');
@ -384,7 +393,8 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::select * @testdox Data can be inserted into a xls files from a database
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper::select
*/ */
public function testSelectXls() : void public function testSelectXls() : void
{ {
@ -392,7 +402,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
\unlink(__DIR__ . '/select.xls'); \unlink(__DIR__ . '/select.xls');
} }
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -419,7 +429,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
$data $data
); );
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/select.xls'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/select.xls');
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1'); $data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');
@ -434,7 +444,8 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @covers phpOMS\Utils\IO\Excel\ExcelDatabaseMapper::select * @testdox Data can be inserted into a xlsx files from a database
* @covers phpOMS\Utils\IO\Spreadsheet\SpreadsheetDatabaseMapper::select
*/ */
public function testSelectXlsx() : void public function testSelectXlsx() : void
{ {
@ -442,7 +453,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
\unlink(__DIR__ . '/select.xlsx'); \unlink(__DIR__ . '/select.xlsx');
} }
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx');
$mapper->insert(); $mapper->insert();
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
@ -469,7 +480,7 @@ class ExcelDatabaseMapperTest extends \PHPUnit\Framework\TestCase
$data $data
); );
$mapper = new ExcelDatabaseMapper($this->sqlite, __DIR__ . '/select.xlsx'); $mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/select.xlsx');
$builder = new Builder($this->sqlite, true); $builder = new Builder($this->sqlite, true);
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1'); $data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');

View File

@ -17,10 +17,16 @@ namespace phpOMS\tests\Utils\IO\Gz;
use phpOMS\Utils\IO\Zip\Gz; use phpOMS\Utils\IO\Zip\Gz;
/** /**
* @testdox phpOMS\tests\Utils\IO\Zip\GzTest: Gz archive
*
* @internal * @internal
*/ */
class GzTest extends \PHPUnit\Framework\TestCase class GzTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox Data can be gz packed and unpacked
* @covers phpOMS\Utils\IO\Zip\Gz
*/
public function testGz() : void public function testGz() : void
{ {
self::assertTrue(Gz::pack( self::assertTrue(Gz::pack(
@ -33,14 +39,56 @@ class GzTest extends \PHPUnit\Framework\TestCase
$a = \file_get_contents(__DIR__ . '/test a.txt'); $a = \file_get_contents(__DIR__ . '/test a.txt');
\unlink(__DIR__ . '/test a.txt'); \unlink(__DIR__ . '/test a.txt');
self::assertFileNotExists(__DIR__ . '/test a.txt'); self::assertFileNotExists(__DIR__ . '/test a.txt');
self::assertTrue(Gz::unpack(__DIR__ . '/test.gz', __DIR__ . '/test a.txt')); self::assertTrue(Gz::unpack(__DIR__ . '/test.gz', __DIR__ . '/test a.txt'));
self::assertFileExists(__DIR__ . '/test a.txt'); self::assertFileExists(__DIR__ . '/test a.txt');
self::assertEquals($a, \file_get_contents(__DIR__ . '/test a.txt')); self::assertEquals($a, \file_get_contents(__DIR__ . '/test a.txt'));
\unlink(__DIR__ . '/test.gz'); \unlink(__DIR__ . '/test.gz');
self::assertFileNotExists(__DIR__ . '/test.gz'); }
/**
* @testdox A gz archive cannot be overwritten by default
* @covers phpOMS\Utils\IO\Zip\Gz
*/
public function testInvalidGz() : void
{
Gz::pack(
__DIR__ . '/test a.txt',
__DIR__ . '/test.gz'
);
self::assertFalse(Gz::pack(
__DIR__ . '/test a.txt',
__DIR__ . '/test.gz'
));
\unlink(__DIR__ . '/test.gz');
}
/**
* @testdox A none-existing source cannot be unpacked
* @covers phpOMS\Utils\IO\Zip\Gz
*/
public function testInvalidUnpackSource() : void
{
self::assertFalse(Gz::unpack(__DIR__ . '/test.gz', __DIR__ . '/test c.txt'));
}
/**
* @testdox A destination cannot be overwritten
* @covers phpOMS\Utils\IO\Zip\Gz
*/
public function testInvalidUnpackDestination() : void
{
self::assertTrue(Gz::pack(
__DIR__ . '/test a.txt',
__DIR__ . '/test.gz'
));
self::assertFalse(Gz::unpack(__DIR__ . '/test.gz', __DIR__ . '/test a.txt')); self::assertFalse(Gz::unpack(__DIR__ . '/test.gz', __DIR__ . '/test a.txt'));
\unlink(__DIR__ . '/test.gz');
} }
} }

View File

@ -17,6 +17,8 @@ namespace phpOMS\tests\Utils\IO\TarGz;
use phpOMS\Utils\IO\Zip\TarGz; use phpOMS\Utils\IO\Zip\TarGz;
/** /**
* @testdox phpOMS\tests\Utils\IO\Zip\TarGzTest: TarGz archive
*
* @internal * @internal
*/ */
class TarGzTest extends \PHPUnit\Framework\TestCase class TarGzTest extends \PHPUnit\Framework\TestCase
@ -30,6 +32,10 @@ class TarGzTest extends \PHPUnit\Framework\TestCase
} }
} }
/**
* @testdox Data can be tar gz packed and unpacked
* @covers phpOMS\Utils\IO\Zip\TarGz
*/
public function testTarGz() : void public function testTarGz() : void
{ {
self::assertTrue(TarGz::pack( self::assertTrue(TarGz::pack(
@ -43,15 +49,6 @@ class TarGzTest extends \PHPUnit\Framework\TestCase
self::assertFileExists(__DIR__ . '/test.tar.gz'); self::assertFileExists(__DIR__ . '/test.tar.gz');
self::assertFalse(TarGz::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.txt' => 'test b.txt',
],
__DIR__ . '/test.tar.gz',
false
));
$a = \file_get_contents(__DIR__ . '/test a.txt'); $a = \file_get_contents(__DIR__ . '/test a.txt');
$b = \file_get_contents(__DIR__ . '/test b.md'); $b = \file_get_contents(__DIR__ . '/test b.md');
$c = \file_get_contents(__DIR__ . '/test/test c.txt'); $c = \file_get_contents(__DIR__ . '/test/test c.txt');
@ -66,14 +63,6 @@ class TarGzTest extends \PHPUnit\Framework\TestCase
\rmdir(__DIR__ . '/test/sub'); \rmdir(__DIR__ . '/test/sub');
\rmdir(__DIR__ . '/test'); \rmdir(__DIR__ . '/test');
self::assertFileNotExists(__DIR__ . '/test a.txt');
self::assertFileNotExists(__DIR__ . '/test b.md');
self::assertFileNotExists(__DIR__ . '/test/test c.txt');
self::assertFileNotExists(__DIR__ . '/test/test d.txt');
self::assertFileNotExists(__DIR__ . '/test/sub/test e.txt');
self::assertFileNotExists(__DIR__ . '/test/sub');
self::assertFileNotExists(__DIR__ . '/test');
self::assertTrue(TarGz::unpack(__DIR__ . '/test.tar.gz', __DIR__)); self::assertTrue(TarGz::unpack(__DIR__ . '/test.tar.gz', __DIR__));
self::assertFileExists(__DIR__ . '/test a.txt'); self::assertFileExists(__DIR__ . '/test a.txt');
@ -91,7 +80,62 @@ class TarGzTest extends \PHPUnit\Framework\TestCase
self::assertEquals($e, \file_get_contents(__DIR__ . '/test/sub/test e.txt')); self::assertEquals($e, \file_get_contents(__DIR__ . '/test/sub/test e.txt'));
\unlink(__DIR__ . '/test.tar.gz'); \unlink(__DIR__ . '/test.tar.gz');
self::assertFileNotExists(__DIR__ . '/test.tar.gz'); }
/**
* @testdox A tar gz archive cannot be overwritten by default
* @covers phpOMS\Utils\IO\Zip\TarGz
*/
public function testInvalidTarGz() : void
{
TarGz::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test2.tar.gz'
);
self::assertFalse(TarGz::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test2.tar.gz'
));
\unlink(__DIR__ . '/test2.tar.gz');
}
/**
* @testdox A none-existing source cannot be unpacked
* @covers phpOMS\Utils\IO\Zip\TarGz
*/
public function testInvalidUnpackSource() : void
{
self::assertFalse(TarGz::unpack(__DIR__ . '/test.tar.gz', __DIR__)); self::assertFalse(TarGz::unpack(__DIR__ . '/test.tar.gz', __DIR__));
} }
/**
* @testdox A destination cannot be overwritten
* @covers phpOMS\Utils\IO\Zip\TarGz
*/
public function testInvalidUnpackDestination() : void
{
self::assertTrue(TarGz::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test3.tar.gz'
));
TarGz::unpack(__DIR__ . '/abc/test3.tar.gz', __DIR__);
self::assertFalse(TarGz::unpack(__DIR__ . '/abc/test3.tar.gz', __DIR__));
\unlink(__DIR__ . '/test3.tar.gz');
}
} }

View File

@ -17,6 +17,8 @@ namespace phpOMS\tests\Utils\IO\Tar;
use phpOMS\Utils\IO\Zip\Tar; use phpOMS\Utils\IO\Zip\Tar;
/** /**
* @testdox phpOMS\tests\Utils\IO\Zip\TarTest: Tar archive
*
* @internal * @internal
*/ */
class TarTest extends \PHPUnit\Framework\TestCase class TarTest extends \PHPUnit\Framework\TestCase
@ -30,6 +32,10 @@ class TarTest extends \PHPUnit\Framework\TestCase
} }
} }
/**
* @testdox Data can be tar packed and unpacked
* @covers phpOMS\Utils\IO\Zip\Tar
*/
public function testTar() : void public function testTar() : void
{ {
self::assertTrue(Tar::pack( self::assertTrue(Tar::pack(
@ -43,15 +49,6 @@ class TarTest extends \PHPUnit\Framework\TestCase
self::assertFileExists(__DIR__ . '/test.tar'); self::assertFileExists(__DIR__ . '/test.tar');
self::assertFalse(Tar::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.txt' => 'test b.txt',
],
__DIR__ . '/test.tar',
false
));
$a = \file_get_contents(__DIR__ . '/test a.txt'); $a = \file_get_contents(__DIR__ . '/test a.txt');
$b = \file_get_contents(__DIR__ . '/test b.md'); $b = \file_get_contents(__DIR__ . '/test b.md');
$c = \file_get_contents(__DIR__ . '/test/test c.txt'); $c = \file_get_contents(__DIR__ . '/test/test c.txt');
@ -66,14 +63,6 @@ class TarTest extends \PHPUnit\Framework\TestCase
\rmdir(__DIR__ . '/test/sub'); \rmdir(__DIR__ . '/test/sub');
\rmdir(__DIR__ . '/test'); \rmdir(__DIR__ . '/test');
self::assertFileNotExists(__DIR__ . '/test a.txt');
self::assertFileNotExists(__DIR__ . '/test b.md');
self::assertFileNotExists(__DIR__ . '/test/test c.txt');
self::assertFileNotExists(__DIR__ . '/test/test d.txt');
self::assertFileNotExists(__DIR__ . '/test/sub/test e.txt');
self::assertFileNotExists(__DIR__ . '/test/sub');
self::assertFileNotExists(__DIR__ . '/test');
self::assertTrue(Tar::unpack(__DIR__ . '/test.tar', __DIR__)); self::assertTrue(Tar::unpack(__DIR__ . '/test.tar', __DIR__));
self::assertFileExists(__DIR__ . '/test a.txt'); self::assertFileExists(__DIR__ . '/test a.txt');
@ -91,7 +80,62 @@ class TarTest extends \PHPUnit\Framework\TestCase
self::assertEquals($e, \file_get_contents(__DIR__ . '/test/sub/test e.txt')); self::assertEquals($e, \file_get_contents(__DIR__ . '/test/sub/test e.txt'));
\unlink(__DIR__ . '/test.tar'); \unlink(__DIR__ . '/test.tar');
self::assertFileNotExists(__DIR__ . '/test.tar'); }
/**
* @testdox A tar archive cannot be overwritten by default
* @covers phpOMS\Utils\IO\Zip\Tar
*/
public function testInvalidTar() : void
{
Tar::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test2.tar'
);
self::assertFalse(Tar::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test2.tar'
));
\unlink(__DIR__ . '/test2.tar');
}
/**
* @testdox A none-existing source cannot be unpacked
* @covers phpOMS\Utils\IO\Zip\Tar
*/
public function testInvalidUnpackSource() : void
{
self::assertFalse(Tar::unpack(__DIR__ . '/test.tar', __DIR__)); self::assertFalse(Tar::unpack(__DIR__ . '/test.tar', __DIR__));
} }
/**
* @testdox A destination cannot be overwritten
* @covers phpOMS\Utils\IO\Zip\Tar
*/
public function testInvalidUnpackDestination() : void
{
self::assertTrue(Tar::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test3.tar'
));
Tar::unpack(__DIR__ . '/abc/test3.tar', __DIR__);
self::assertFalse(Tar::unpack(__DIR__ . '/abc/test3.tar', __DIR__));
\unlink(__DIR__ . '/test3.tar');
}
} }

View File

@ -17,6 +17,8 @@ namespace phpOMS\tests\Utils\IO\Zip;
use phpOMS\Utils\IO\Zip\Zip; use phpOMS\Utils\IO\Zip\Zip;
/** /**
* @testdox phpOMS\tests\Utils\IO\Zip\ZipTest: Zip archive
*
* @internal * @internal
*/ */
class ZipTest extends \PHPUnit\Framework\TestCase class ZipTest extends \PHPUnit\Framework\TestCase
@ -30,6 +32,10 @@ class ZipTest extends \PHPUnit\Framework\TestCase
} }
} }
/**
* @testdox Data can be zip packed and unpacked
* @covers phpOMS\Utils\IO\Zip\Zip
*/
public function testZip() : void public function testZip() : void
{ {
self::assertTrue(Zip::pack( self::assertTrue(Zip::pack(
@ -43,15 +49,6 @@ class ZipTest extends \PHPUnit\Framework\TestCase
self::assertFileExists(__DIR__ . '/test.zip'); self::assertFileExists(__DIR__ . '/test.zip');
self::assertFalse(Zip::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.txt' => 'test b.txt',
],
__DIR__ . '/test.zip',
false
));
$a = \file_get_contents(__DIR__ . '/test a.txt'); $a = \file_get_contents(__DIR__ . '/test a.txt');
$b = \file_get_contents(__DIR__ . '/test b.md'); $b = \file_get_contents(__DIR__ . '/test b.md');
$c = \file_get_contents(__DIR__ . '/test/test c.txt'); $c = \file_get_contents(__DIR__ . '/test/test c.txt');
@ -66,14 +63,6 @@ class ZipTest extends \PHPUnit\Framework\TestCase
\rmdir(__DIR__ . '/test/sub'); \rmdir(__DIR__ . '/test/sub');
\rmdir(__DIR__ . '/test'); \rmdir(__DIR__ . '/test');
self::assertFileNotExists(__DIR__ . '/test a.txt');
self::assertFileNotExists(__DIR__ . '/test b.md');
self::assertFileNotExists(__DIR__ . '/test/test c.txt');
self::assertFileNotExists(__DIR__ . '/test/test d.txt');
self::assertFileNotExists(__DIR__ . '/test/sub/test e.txt');
self::assertFileNotExists(__DIR__ . '/test/sub');
self::assertFileNotExists(__DIR__ . '/test');
self::assertTrue(Zip::unpack(__DIR__ . '/test.zip', __DIR__)); self::assertTrue(Zip::unpack(__DIR__ . '/test.zip', __DIR__));
self::assertFileExists(__DIR__ . '/test a.txt'); self::assertFileExists(__DIR__ . '/test a.txt');
@ -91,7 +80,62 @@ class ZipTest extends \PHPUnit\Framework\TestCase
self::assertEquals($e, \file_get_contents(__DIR__ . '/test/sub/test e.txt')); self::assertEquals($e, \file_get_contents(__DIR__ . '/test/sub/test e.txt'));
\unlink(__DIR__ . '/test.zip'); \unlink(__DIR__ . '/test.zip');
self::assertFileNotExists(__DIR__ . '/test.zip'); }
/**
* @testdox A zip archive cannot be overwritten by default
* @covers phpOMS\Utils\IO\Zip\Zip
*/
public function testInvalidZip() : void
{
Zip::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test2.zip'
);
self::assertFalse(Zip::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test2.zip'
));
\unlink(__DIR__ . '/test2.zip');
}
/**
* @testdox A none-existing source cannot be unpacked
* @covers phpOMS\Utils\IO\Zip\Zip
*/
public function testInvalidUnpackSource() : void
{
self::assertFalse(Zip::unpack(__DIR__ . '/test.zip', __DIR__)); self::assertFalse(Zip::unpack(__DIR__ . '/test.zip', __DIR__));
} }
/**
* @testdox A destination cannot be overwritten
* @covers phpOMS\Utils\IO\Zip\Zip
*/
public function testInvalidUnpackDestination() : void
{
self::assertTrue(Zip::pack(
[
__DIR__ . '/test a.txt' => 'test a.txt',
__DIR__ . '/test b.md' => 'test b.md',
__DIR__ . '/test' => 'test',
],
__DIR__ . '/test3.zip'
));
Zip::unpack(__DIR__ . '/abc/test3.zip', __DIR__);
self::assertFalse(Zip::unpack(__DIR__ . '/abc/test3.zip', __DIR__));
\unlink(__DIR__ . '/test3.zip');
}
} }

View File

@ -29,13 +29,13 @@ class MarkdownTest extends \PHPUnit\Framework\TestCase
foreach ($files as $file) { foreach ($files as $file) {
$data = \explode('.', $file); $data = \explode('.', $file);
if ($data[1] === 'md') { if ($data[1] === 'md'
self::assertEquals( && (\file_get_contents(__DIR__ . '/data/' . $data[0] . '.html') !== Markdown::parse(\file_get_contents(__DIR__ . '/data/' . $data[0] . '.md')))
\file_get_contents(__DIR__ . '/data/' . $data[0] . '.html'), ) {
Markdown::parse(\file_get_contents(__DIR__ . '/data/' . $data[0] . '.md')), self::asserTrue(false, $file);
$file
);
} }
} }
self::assertTrue(true);
} }
} }

View File

@ -35,7 +35,11 @@ class DateTimeTest extends \PHPUnit\Framework\TestCase
$rng = DateTime::generateDateTime($dateMin, $dateMax); $rng = DateTime::generateDateTime($dateMin, $dateMax);
self::assertTrue($rng->getTimestamp() >= $min && $rng->getTimestamp() <= $max); if (!($rng->getTimestamp() >= $min && $rng->getTimestamp() <= $max)) {
self::assertTrue(false);
}
} }
self::assertTrue(true);
} }
} }