impl. more tests

This commit is contained in:
Dennis Eichhorn 2020-10-03 22:34:58 +02:00
parent 2f37ad1200
commit 14fcafc9a5
35 changed files with 1543 additions and 224 deletions

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace phpOMS\Ai\Ocr;
use phpOMS\Math\Topology\MetricsND;
use phpOMS\System\File\PathException;
/**
* Basic OCR implementation for MNIST data
@ -53,164 +54,135 @@ final class BasicOcr
*
* @param string $dataPath Impage path to read
* @param string $labelPath Label path to read
* @param string $limit Limit
*
* @return void
*
* @since 1.0.0
*/
public function trainWith(string $dataPath, string $labelPath) : void
public function trainWith(string $dataPath, string $labelPath, int $limit = 0) : void
{
$Xtrain = $this->readImages($dataPath);
$ytrain = $this->readLabels($labelPath);
$Xtrain = $this->readImages($dataPath, $limit);
$ytrain = $this->readLabels($labelPath, $limit);
$this->Xtrain = \array_merge($this->Xtrain, $this->extractFeatures($Xtrain));
$this->ytrain = \array_merge($this->ytrain, $this->extractFeatures($ytrain));
$this->Xtrain = \array_merge($this->Xtrain, $Xtrain);
$this->ytrain = \array_merge($this->ytrain, $ytrain);
}
/**
* Reat image from path
*
* @param string $path Image to read
* @param string $path Image to read
* @param string $limit Limit
*
* @return array
*
* @since 1.0.0
*/
private function readImages(string $path) : array
private function readImages(string $path, int $limit = 0) : array
{
if (!\file_exists($path)) {
throw new PathException($path);
}
$fp = \fopen($path, 'r');
if ($fp === false) {
throw new \Exception();
throw new PathException($path); // @codeCoverageIgnore
}
$read = \fread($fp, 4);
if (!$read) {
return [];
if ($read === false) {
return []; // @codeCoverageIgnore
}
$magicNumber = \unpack('l', $read)[1];
$magicNumber = \unpack('N', $read)[1];
$read = \fread($fp, 4);
if (!$read) {
return [];
if ($read === false) {
return []; // @codeCoverageIgnore
}
$numberOfImages = \unpack('N', $read)[1];
if ($limit > 0) {
$numberOfImages = \min($numberOfImages, $limit);
}
$numberOfImages = \unpack('l', $read)[1];
$read = \fread($fp, 4);
if (!$read) {
return [];
if ($read === false) {
return []; // @codeCoverageIgnore
}
$numberOfRows = \unpack('l', $read)[1];
$numberOfRows = \unpack('N', $read)[1];
$read = \fread($fp, 4);
if (!$read) {
return [];
if ($read === false) {
return []; // @codeCoverageIgnore
}
$numberOfColumns = \unpack('l', $read)[1];
$numberOfColumns = \unpack('N', $read)[1];
$images = [];
for ($i = 0; $i < $numberOfImages; ++$i) {
$image = [];
for ($row = 0; $row < $numberOfRows; ++$row) {
$rows = [];
for ($col = 0; $col < $numberOfColumns; ++$col) {
$read = \fread($fp, 1);
if (!$read) {
return [];
}
$rows[] = \unpack('l', $read)[1]; //fread($fp, 1);
}
$image[] = $rows;
$read = \fread($fp, $numberOfRows * $numberOfColumns);
if ($read === false) {
return []; // @codeCoverageIgnore
}
$images[] = $image;
$images[] = \array_values(\unpack('C*', $read));
}
\fclose($fp);
return $images;
}
/**
* Read labels from from path
*
* @param string $path Labels path
* @param string $path Labels path
* @param string $limit Limit
*
* @return array
*
* @since 1.0.0
*/
private function readLabels(string $path) : array
private function readLabels(string $path, int $limit = 0) : array
{
if (!\file_exists($path)) {
throw new PathException($path);
}
$fp = \fopen($path, 'r');
if ($fp === false) {
throw new \Exception();
throw new PathException($path); // @codeCoverageIgnore
}
$read = \fread($fp, 4);
if (!$read) {
return [];
if ($read === false) {
return []; // @codeCoverageIgnore
}
$magicNumber = \unpack('l', $read)[1];
$magicNumber = \unpack('N', $read)[1];
$read = \fread($fp, 4);
if (!$read) {
return [];
if ($read === false) {
return []; // @codeCoverageIgnore
}
$numberOfLabels = \unpack('N', $read)[1];
if ($limit > 0) {
$numberOfLabels = \min($numberOfLabels, $limit);
}
$numberOfLabels = \unpack('l', $read)[1];
$labels = [];
for ($i = 0; $i < $numberOfLabels; ++$i) {
$read = \fread($fp, 1);
if (!$read) {
return [];
if ($read === false) {
return []; // @codeCoverageIgnore
}
$labels[] = \unpack('l', $read)[1]; //fread($fp, 1);
$labels[] = \unpack('C', $read)[1];
}
\fclose($fp);
return $labels;
}
/**
* Extract data and labe information from image data
*
* @param array $data Image data and label information from the images
*
* @return array
*
* @since 1.0.0
*/
private function extractFeatures(array $data) : array
{
$features = [];
foreach ($data as $sample) {
$features[] = $this->flatten($sample);
}
return $features;
}
/**
* Reduce the dimension of the data and label information
*
* @param array $data Image data and labell information to flatten
*
* @return array
*
* @sicne 1.0.0
*/
private function flatten(array $data) : array
{
$flat = [];
foreach ($data as $sublist) {
foreach ($sublist as $pixel) {
$flat[] = $pixel;
}
}
return $flat;
}
/**
* Find the k-nearest matches for test data
*
@ -227,19 +199,22 @@ final class BasicOcr
$distances = $this->getDistances($Xtrain, $sample);
\asort($distances);
// find possible k-labels for a image
$kKeys = \array_keys(\array_slice($distances, 0, $k));
$candidateLabels = [];
$keys = \array_keys($distances);
foreach ($kKeys as $key) {
$candidateLabels[] = $ytrain[$key];
$candidateLabels = [];
for ($i = 0; $i < $k; ++$i) {
$candidateLabels[] = $ytrain[$keys[$i]];
}
// find best match
$countedCandidates = \array_count_values($candidateLabels);
\asort($countedCandidates);
$predictedLabels[] = ['label' => \array_key_first($countedCandidates), 'prob' => \reset($countedCandidates) / $k];
foreach ($candidateLabels as $i => $label) {
$predictedLabels[] = [
'label' => $label,
'prob' => $countedCandidates[$candidateLabels[$i]] / $k,
];
}
}
return $predictedLabels;
@ -268,17 +243,19 @@ final class BasicOcr
/**
* Categorize an unknown image
*
* @param string $path Path to the image to categorize/evaluate/match against the training data
* @param string $path Path to the image to categorize/evaluate/match against the training data
* @param string $comparison Amount of comparisons
* @param string $limit Limit
*
* @return array
*
* @since 1.0.0
*/
public function match(string $path) : array
public function match(string $path, int $comparison = 3, int $limit = 0) : array
{
// @todo: implement image reading if it isn't an mnist file
$Xtest = $this->readImages($path);
$Xtest = $this->readImages($path, $limit);
return $this->kNearest($this->Xtrain, $this->ytrain, $Xtest);
return $this->kNearest($this->Xtrain, $this->ytrain, $Xtest, $comparison);
}
}

View File

@ -128,13 +128,13 @@ final class Autoloader
public static function invalidate(string $class) : bool
{
if (!\extension_loaded('opcache')
|| !\opcache_is_script_cached(__DIR__ . '/../../Models/NewsArticleMapper.php')
|| !\opcache_is_script_cached($class)
) {
return false;
}
\opcache_invalidate(__DIR__ . '/../../Models/NewsArticleMapper.php');
\opcache_compile_file(__DIR__ . '/../../Models/NewsArticleMapper.php');
\opcache_invalidate($class);
\opcache_compile_file($class);
return true;
}

View File

@ -142,7 +142,7 @@ abstract class InstallerAbstract
$content = \file_get_contents($path);
if ($content === false) {
return;
return; // @codeCoverageIgnore
}
$definitions = \json_decode($content, true);

View File

@ -376,7 +376,7 @@ final class ModuleManager
return true;
} catch (\Exception $e) {
return false;
return false; // @codeCoverageIgnore
}
}
@ -427,7 +427,7 @@ final class ModuleManager
return true;
} catch (\Exception $e) {
return false;
return false; // @codeCoverageIgnore
}
}
@ -528,10 +528,8 @@ final class ModuleManager
$this->installApplications($module);
return true;
} catch (PathException $e) {
return false;
} catch (\Exception $e) {
return false;
} catch (\Throwable $t) {
return false; // @codeCoverageIgnore
}
}
@ -587,9 +585,7 @@ final class ModuleManager
}
return true;
} catch (PathException $e) {
return false;
} catch (\Exception $e) {
} catch (\Throwable $t) {
return false;
}
}

View File

@ -162,7 +162,7 @@ final class PackageManager
$contents = \file_get_contents($this->extractPath . '/' . $file);
if ($contents === false) {
throw new \Exception();
throw new \Exception(); // @codeCoverageIgnore
}
\sodium_crypto_generichash_update($state, $contents);

View File

@ -68,12 +68,11 @@ abstract class UninstallerAbstract
$content = \file_get_contents($path);
if ($content === false) {
return;
return; // @codeCoverageIgnore
}
$definitions = \json_decode($content, true);
$builder = new SchemaBuilder($dbPool->get('schema'));
$builder = new SchemaBuilder($dbPool->get('schema'));
foreach ($definitions as $definition) {
$builder->dropTable($definition['table'] ?? '');

View File

@ -50,6 +50,20 @@ class File extends FileAbstract implements FileInterface
$this->con = $con ?? self::ftpConnect($this->uri);
parent::__construct($uri->getPath());
if (self::exists($this->con, $this->path)) {
$this->index();
}
}
/**
* {@inheritdoc}
*/
public function index() : void
{
parent::index();
$this->size = (int) \ftp_size($this->con, $this->path);
}
/**
@ -162,7 +176,7 @@ class File extends FileAbstract implements FileInterface
/**
* {@inheritdoc}
*/
public static function count(string $path, bool $recursive = true, array $ignore = []) : int
public static function count($con, string $path, bool $recursive = true, array $ignore = []) : int
{
return 1;
}
@ -377,6 +391,18 @@ class File extends FileAbstract implements FileInterface
return LocalFile::extension($path);
}
/**
* Check if the file exists
*
* @return bool
*
* @since 1.0.0
*/
public function isExisting() : bool
{
return self::exists($this->con, $this->path);
}
/**
* Get the parent path of the resource.
*
@ -388,12 +414,10 @@ class File extends FileAbstract implements FileInterface
*/
public function getParent() : ContainerInterface
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement getParent()
*/
$uri = clone $this->uri;
$uri->setPath(self::parent($this->path));
return $this;
return new Directory($uri, '*', true, $this->con);
}
/**
@ -420,12 +444,7 @@ class File extends FileAbstract implements FileInterface
*/
public function copyNode(string $to, bool $overwrite = false) : bool
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement copyNode()
*/
return true;
return self::copy($this->con, $this->path, $to, $overwrite);
}
/**
@ -440,12 +459,7 @@ class File extends FileAbstract implements FileInterface
*/
public function moveNode(string $to, bool $overwrite = false) : bool
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement moveNode()
*/
return true;
return self::move($this->con, $this->path, $to, $overwrite);
}
/**
@ -457,12 +471,7 @@ class File extends FileAbstract implements FileInterface
*/
public function deleteNode() : bool
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement deleteNode()
*/
return true;
return self::delete($this->con, $this->path);
}
/**
@ -477,12 +486,7 @@ class File extends FileAbstract implements FileInterface
*/
public function putContent(string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement putContent()
*/
return true;
return self::put($this->con, $this->path, $content, $mode);
}
/**
@ -498,12 +502,7 @@ class File extends FileAbstract implements FileInterface
*/
public function setContent(string $content) : bool
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement setContent()
*/
return true;
return $this->putContent($content, ContentPutMode::REPLACE | ContentPutMode::CREATE);
}
/**
@ -519,12 +518,7 @@ class File extends FileAbstract implements FileInterface
*/
public function appendContent(string $content) : bool
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement appendContent()
*/
return true;
return $this->putContent($content, ContentPutMode::APPEND);
}
/**
@ -540,12 +534,7 @@ class File extends FileAbstract implements FileInterface
*/
public function prependContent(string $content) : bool
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement prependContent()
*/
return true;
return $this->putContent($content, ContentPutMode::PREPEND);
}
/**
@ -557,12 +546,7 @@ class File extends FileAbstract implements FileInterface
*/
public function getContent() : string
{
/**
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
* Implement getContent()
*/
return '';
return self::get($this->con, $this->path);
}
/**
@ -606,4 +590,12 @@ class File extends FileAbstract implements FileInterface
{
return \dirname($this->path);
}
public function getDirectory() : ContainerInterface
{
$uri = clone $this->uri;
$uri->setPath(self::dirpath($this->path));
return new Directory($uri, '*', true, $this->con);
}
}

View File

@ -173,17 +173,6 @@ abstract class FileAbstract implements ContainerInterface
return $this->path;
}
/**
* {@inheritdoc}
*/
public function parentNode() : Directory
{
$uri = clone $this->uri;
$uri->setPath(Directory::parent($this->path));
return new Directory($uri, '*', true, $this->con);
}
/**
* {@inheritdoc}
*/

View File

@ -26,16 +26,24 @@ use phpOMS\System\File\StorageAbstract;
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
* @codeCoverageIgnore
*/
class FtpStorage extends StorageAbstract
{
private static $con = null;
public static function with($con)
{
self::$con = $con;
}
/**
* {@inheritdoc}
*/
protected static function getClassType(string $path) : string
{
return \is_dir($path) || (!\is_file($path) && \stripos($path, '.') === false) ? Directory::class : File::class;
return \ftp_size(self::$con, $path) === -1 && \stripos($path, '.') === false
? Directory::class
: File::class;
}
/**
@ -43,11 +51,11 @@ class FtpStorage extends StorageAbstract
*/
public static function put(string $path, string $content, int $mode = 0) : bool
{
if (\is_dir($path)) {
if (static::getClassType($path) === Directory::class) {
throw new PathException($path);
}
return File::put($path, $content, $mode);
return File::put(self::$con, $path, $content, $mode);
}
/**
@ -55,11 +63,11 @@ class FtpStorage extends StorageAbstract
*/
public static function get(string $path) : string
{
if (\is_dir($path)) {
if (static::getClassType($path) === Directory::class) {
throw new PathException($path);
}
return File::get($path);
return File::get(self::$con, $path);
}
/**
@ -67,19 +75,21 @@ class FtpStorage extends StorageAbstract
*/
public static function create(string $path) : bool
{
return \stripos($path, '.') === false ? Directory::create($path, 0755, true) : File::create($path);
return \stripos($path, '.') === false
? Directory::create(self::$con, $path, 0755, true)
: File::create(self::$con, $path);
}
/**
* {@inheritdoc}
*/
public static function list(string $path, string $filter = '*') : array
public static function list(string $path, string $filter = '*', bool $recursive = false) : array
{
if (\is_file($path)) {
if (static::getClassType($path) === File::class) {
throw new PathException($path);
}
return Directory::list($path, $filter);
return Directory::list(self::$con, $path, $filter, $recursive);
}
/**
@ -87,11 +97,11 @@ class FtpStorage extends StorageAbstract
*/
public static function set(string $path, string $content) : bool
{
if (\is_dir($path)) {
if (static::getClassType($path) === Directory::class) {
throw new PathException($path);
}
return File::set($path, $content);
return File::set(self::$con, $path, $content);
}
/**
@ -99,11 +109,11 @@ class FtpStorage extends StorageAbstract
*/
public static function append(string $path, string $content) : bool
{
if (\is_dir($path)) {
if (static::getClassType($path) === Directory::class) {
throw new PathException($path);
}
return File::append($path, $content);
return File::append(self::$con, $path, $content);
}
/**
@ -111,11 +121,11 @@ class FtpStorage extends StorageAbstract
*/
public static function prepend(string $path, string $content) : bool
{
if (\is_dir($path)) {
if (static::getClassType($path) === Directory::class) {
throw new PathException($path);
}
return File::prepend($path, $content);
return File::prepend(self::$con, $path, $content);
}
/**
@ -123,10 +133,138 @@ class FtpStorage extends StorageAbstract
*/
public static function extension(string $path) : string
{
if (\is_dir($path)) {
if (static::getClassType($path) === Directory::class) {
throw new PathException($path);
}
return File::extension($path);
}
/**
* {@inheritdoc}
*/
public static function created(string $path) : \DateTime
{
return static::getClassType($path)::created(self::$con, $path);
}
/**
* {@inheritdoc}
*/
public static function changed(string $path) : \DateTime
{
return static::getClassType($path)::changed(self::$con, $path);
}
/**
* {@inheritdoc}
*/
public static function owner(string $path) : int
{
return static::getClassType($path)::owner(self::$con, $path);
}
/**
* {@inheritdoc}
*/
public static function permission(string $path) : int
{
return static::getClassType($path)::permission(self::$con, $path);
}
/**
* {@inheritdoc}
*/
public static function parent(string $path) : string
{
return static::getClassType($path)::parent($path);
}
/**
* {@inheritdoc}
*/
public static function delete(string $path) : bool
{
return static::getClassType($path)::delete(self::$con, $path);
}
/**
* {@inheritdoc}
*/
public static function copy(string $from, string $to, bool $overwrite = false) : bool
{
return static::getClassType($from)::copy(self::$con, $from, $to, $overwrite);
}
/**
* {@inheritdoc}
*/
public static function move(string $from, string $to, bool $overwrite = false) : bool
{
return static::getClassType($from)::move(self::$con, $from, $to, $overwrite);
}
/**
* {@inheritdoc}
*/
public static function size(string $path, bool $recursive = true) : int
{
return static::getClassType($path)::size(self::$con, $path, $recursive);
}
/**
* {@inheritdoc}
*/
public static function exists(string $path) : bool
{
return static::getClassType($path)::exists(self::$con, $path);
}
/**
* {@inheritdoc}
*/
public static function name(string $path) : string
{
return static::getClassType($path)::name($path);
}
/**
* {@inheritdoc}
*/
public static function basename(string $path) : string
{
return static::getClassType($path)::basename($path);
}
/**
* {@inheritdoc}
*/
public static function dirname(string $path) : string
{
return static::getClassType($path)::dirname($path);
}
/**
* {@inheritdoc}
*/
public static function dirpath(string $path) : string
{
return static::getClassType($path)::dirpath($path);
}
/**
* {@inheritdoc}
*/
public static function count(string $path, bool $recursive = true, array $ignore = []) : int
{
return static::getClassType($path)::count(self::$con, $path, $recursive, $ignore);
}
/**
* {@inheritdoc}
*/
public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string
{
return static::getClassType($path)::sanitize($path, $replace);
}
}

View File

@ -156,14 +156,6 @@ abstract class FileAbstract implements ContainerInterface
return $this->path;
}
/**
* {@inheritdoc}
*/
public function parentNode() : Directory
{
return new Directory(Directory::parent($this->path));
}
/**
* {@inheritdoc}
*/

View File

@ -64,13 +64,13 @@ class LocalStorage extends StorageAbstract
/**
* {@inheritdoc}
*/
public static function list(string $path, string $filter = '*') : array
public static function list(string $path, string $filter = '*', bool $recursive = false) : array
{
if (\is_file($path)) {
throw new PathException($path);
}
return Directory::list($path, $filter);
return Directory::list($path, $filter, $recursive);
}
/**
@ -78,7 +78,9 @@ class LocalStorage extends StorageAbstract
*/
public static function create(string $path) : bool
{
return \stripos($path, '.') === false ? Directory::create($path, 0755, true) : File::create($path);
return \stripos($path, '.') === false
? Directory::create($path, 0755, true)
: File::create($path);
}
/**

View File

@ -14,13 +14,41 @@ declare(strict_types=1);
namespace phpOMS\tests\Ai\Ocr;
use phpOMS\Ai\Ocr\BasicOcr;
/**
* @internal
*/
class BasicOcrTest extends \PHPUnit\Framework\TestCase
{
public function testPlaceholder() : void
public function testOcr() : void
{
self::markTestIncomplete();
$ocr = new BasicOcr();
$ocr->trainWith(__DIR__ . '/train-images-idx3-ubyte', __DIR__ . '/train-labels-idx1-ubyte', 1000);
self::assertEquals(
[
['label' => 7, 'prob' => 1], ['label' => 7, 'prob' => 1], ['label' => 7, 'prob' => 1],
['label' => 2, 'prob' => 2 / 3], ['label' => 2, 'prob' => 2 / 3], ['label' => 8, 'prob' => 1 / 3],
['label' => 1, 'prob' => 1], ['label' => 1, 'prob' => 1], ['label' => 1, 'prob' => 1],
['label' => 0, 'prob' => 1], ['label' => 0, 'prob' => 1], ['label' => 0, 'prob' => 1],
['label' => 4, 'prob' => 2 / 3], ['label' => 9, 'prob' => 1 / 3], ['label' => 4, 'prob' => 2 / 3],
],
$ocr->match(__DIR__ . '/t10k-images-idx3-ubyte', 3, 5)
);
}
public function testInvalidImagePath() : void
{
$this->expectException(\phpOMS\System\File\PathException::class);
$ocr = new BasicOcr();
$ocr->trainWith(__DIR__ . '/invalid', __DIR__ . '/train-labels-idx1-ubyte', 1);
}
public function testInvalidLabelPath() : void
{
$this->expectException(\phpOMS\System\File\PathException::class);
$ocr = new BasicOcr();
$ocr->trainWith(__DIR__ . '/train-images-idx3-ubyte', __DIR__ . '/invalid', 1);
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -32,7 +32,7 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
}
/**
* @testdox Mysql drops form a valid query
* @testdox Mysql database drop forms a valid query
* @group framework
*/
public function testMysqlDrop() : void
@ -42,6 +42,17 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
self::assertEquals($sql, $query->dropDatabase('test')->toSql());
}
/**
* @testdox Mysql table drop forms a valid query
* @group framework
*/
public function testMysqlDropTable() : void
{
$query = new Builder($this->con);
$sql = 'DROP TABLE `test`;';
self::assertEquals($sql, $query->dropTable('test')->toSql());
}
/**
* @testdox Mysql show tables form a valid query
* @group framework

View File

@ -89,7 +89,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
{
$model1 = new BaseModel();
$model2 = new BaseModel();
$this->createModel(1, [$model1, $model2], BaseModelMapper::class, '', '127.0.0.1');
$this->createModels(1, [$model1, $model2], BaseModelMapper::class, '', '127.0.0.1');
}
public function update() : void

View File

@ -20,6 +20,7 @@ use phpOMS\Dispatcher\Dispatcher;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Module\ModuleManager;
use phpOMS\Router\WebRouter;
use phpOMS\System\File\Local\Directory;
use phpOMS\Uri\HttpUri;
require_once __DIR__ . '/../Autoloader.php';
@ -244,4 +245,22 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
self::assertFalse($this->moduleManager->isActive('TestModule'));
self::assertFalse($this->moduleManager->isRunning('TestModule'));
}
public function testInvalidModulePath() : void
{
$moduleManager = new ModuleManager($this->app, __DIR__ . '/Testmodule');
self::assertEquals([], $moduleManager->getAllModules());
self::assertEquals([], $moduleManager->getInstalledModules());
}
public function testInvalidModuleInstall() : void
{
self::assertFalse($this->moduleManager->install('Invalid'));
}
public function testInvalidModuleUninstall() : void
{
self::assertFalse($this->moduleManager->uninstall('Invalid'));
}
}

View File

@ -92,7 +92,7 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
Directory::delete(__DIR__ . '/dummyModule');
}
Directory::copy(__DIR__ . '/testModule', __DIR__ . '/dummyModule');
Directory::copy(__DIR__ . '/testModulePackage', __DIR__ . '/dummyModule');
$package = new PackageManager(
__DIR__ . '/testPackage.zip',

View File

@ -0,0 +1,29 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Testmodule\Admin;
use phpOMS\Module\InstallerAbstract;
/**
* Installer class.
*
* @package tests
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class Installer extends InstallerAbstract
{
}

View File

@ -0,0 +1,20 @@
{
"name": {
"id": 1999100000,
"internal": "{APPNAME}",
"external": "{APPNAME}"
},
"category": "Web",
"version": "1.0.0",
"requirements": {
"phpOMS": "1.0.0",
"phpOMS-db": "1.0.0"
},
"creator": {
"name": "Orange Management",
"website": "www.spl1nes.com"
},
"description": "The backend application.",
"directory": "{APPNAME}",
"dependencies": {}
}

View File

@ -0,0 +1,25 @@
{
"name": {
"id": 1999000000,
"internal": "Testmodule",
"external": "Testmodule"
},
"category": "Test",
"version": "1.0.0",
"requirements": {
"phpOMS": "1.0.0",
"phpOMS-db": "1.0.0"
},
"creator": {
"name": "Orange Management",
"website": "www.spl1nes.com"
},
"description": "Testmodule module.",
"directory": "Testmodule",
"dependencies": {
},
"providing": {
},
"load": [
]
}

View File

@ -184,15 +184,16 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
*/
public function testStaticCreatedAt() : void
{
self::markTestSkipped();
$dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create(self::$con, $dirPath));
$now = new \DateTime('now');
$now->setTimestamp(-1);
self::assertEquals($now->format('Y-m-d'), Directory::created(self::$con, $dirPath)->format('Y-m-d'));
\rmdir($dirPath);
Directory::delete(self::$con, $dirPath);
}
/**
@ -202,16 +203,16 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
*/
public function testStaticChangedAt() : void
{
self::markTestSkipped();
$dirPath = __DIR__ . '/test';
self::assertTrue(Directory::create(self::$con, $dirPath));
$now = new \DateTime('now');
$now->setTimestamp(-1);
self::assertEquals($now->format('Y-m-d'), Directory::changed(self::$con, $dirPath)->format('Y-m-d'));
\rmdir($dirPath);
Directory::delete(self::$con, $dirPath);
}
/**
@ -580,7 +581,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
{
$dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con);
self::assertEquals(__DIR__, $dir->parentNode()->getPath());
self::assertEquals(__DIR__, $dir->getParent()->getPath());
}
public function testNodeNext() : void

View File

@ -337,7 +337,7 @@ class FileTest extends \PHPUnit\Framework\TestCase
{
$testFile = __DIR__ . '/test.txt';
self::assertEquals(1, File::count($testFile));
self::assertEquals(1, File::count(self::$con, $testFile));
}
/**
@ -887,7 +887,7 @@ class FileTest extends \PHPUnit\Framework\TestCase
{
$file = new File(new HttpUri(self::BASE . __DIR__ . '/dirtest/test.txt'), self::$con);
self::assertEquals('Local', $file->getParent()->getName());
self::assertEquals('Ftp', $file->getParent()->getName());
}
public function testNodeDirectory() : void

File diff suppressed because it is too large Load Diff

View File

@ -592,7 +592,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
{
$dir = new Directory(__DIR__ . '/dirtest');
self::assertEquals(__DIR__, $dir->parentNode()->getPath());
self::assertEquals(__DIR__, $dir->getParent()->getPath());
}
public function testNodeNext() : void

View File

@ -324,7 +324,7 @@ class LocalStorageTest extends \PHPUnit\Framework\TestCase
public function testStaticListFilesDirectory() : void
{
$dirTestPath = __DIR__ . '/dirtest';
self::assertCount(6, LocalStorage::list($dirTestPath));
self::assertCount(6, LocalStorage::list($dirTestPath, '*', true));
}
/**