mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-09 21:48:41 +00:00
impl. more tests
This commit is contained in:
parent
2f37ad1200
commit
14fcafc9a5
|
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\Ai\Ocr;
|
namespace phpOMS\Ai\Ocr;
|
||||||
|
|
||||||
use phpOMS\Math\Topology\MetricsND;
|
use phpOMS\Math\Topology\MetricsND;
|
||||||
|
use phpOMS\System\File\PathException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic OCR implementation for MNIST data
|
* Basic OCR implementation for MNIST data
|
||||||
|
|
@ -53,164 +54,135 @@ final class BasicOcr
|
||||||
*
|
*
|
||||||
* @param string $dataPath Impage path to read
|
* @param string $dataPath Impage path to read
|
||||||
* @param string $labelPath Label path to read
|
* @param string $labelPath Label path to read
|
||||||
|
* @param string $limit Limit
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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);
|
$Xtrain = $this->readImages($dataPath, $limit);
|
||||||
$ytrain = $this->readLabels($labelPath);
|
$ytrain = $this->readLabels($labelPath, $limit);
|
||||||
|
|
||||||
$this->Xtrain = \array_merge($this->Xtrain, $this->extractFeatures($Xtrain));
|
$this->Xtrain = \array_merge($this->Xtrain, $Xtrain);
|
||||||
$this->ytrain = \array_merge($this->ytrain, $this->extractFeatures($ytrain));
|
$this->ytrain = \array_merge($this->ytrain, $ytrain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reat image from path
|
* Reat image from path
|
||||||
*
|
*
|
||||||
* @param string $path Image to read
|
* @param string $path Image to read
|
||||||
|
* @param string $limit Limit
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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');
|
$fp = \fopen($path, 'r');
|
||||||
if ($fp === false) {
|
if ($fp === false) {
|
||||||
throw new \Exception();
|
throw new PathException($path); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$read = \fread($fp, 4);
|
$read = \fread($fp, 4);
|
||||||
if (!$read) {
|
if ($read === false) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$magicNumber = \unpack('l', $read)[1];
|
$magicNumber = \unpack('N', $read)[1];
|
||||||
|
|
||||||
$read = \fread($fp, 4);
|
$read = \fread($fp, 4);
|
||||||
if (!$read) {
|
if ($read === false) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
$numberOfImages = \unpack('N', $read)[1];
|
||||||
|
|
||||||
|
if ($limit > 0) {
|
||||||
|
$numberOfImages = \min($numberOfImages, $limit);
|
||||||
}
|
}
|
||||||
$numberOfImages = \unpack('l', $read)[1];
|
|
||||||
|
|
||||||
$read = \fread($fp, 4);
|
$read = \fread($fp, 4);
|
||||||
if (!$read) {
|
if ($read === false) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$numberOfRows = \unpack('l', $read)[1];
|
$numberOfRows = \unpack('N', $read)[1];
|
||||||
|
|
||||||
$read = \fread($fp, 4);
|
$read = \fread($fp, 4);
|
||||||
if (!$read) {
|
if ($read === false) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$numberOfColumns = \unpack('l', $read)[1];
|
$numberOfColumns = \unpack('N', $read)[1];
|
||||||
|
|
||||||
$images = [];
|
$images = [];
|
||||||
for ($i = 0; $i < $numberOfImages; ++$i) {
|
for ($i = 0; $i < $numberOfImages; ++$i) {
|
||||||
$image = [];
|
$read = \fread($fp, $numberOfRows * $numberOfColumns);
|
||||||
|
if ($read === false) {
|
||||||
for ($row = 0; $row < $numberOfRows; ++$row) {
|
return []; // @codeCoverageIgnore
|
||||||
$rows = [];
|
|
||||||
|
|
||||||
for ($col = 0; $col < $numberOfColumns; ++$col) {
|
|
||||||
$read = \fread($fp, 1);
|
|
||||||
if (!$read) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
$rows[] = \unpack('l', $read)[1]; //fread($fp, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$image[] = $rows;
|
|
||||||
}
|
}
|
||||||
|
$images[] = \array_values(\unpack('C*', $read));
|
||||||
$images[] = $image;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\fclose($fp);
|
||||||
|
|
||||||
return $images;
|
return $images;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read labels from from path
|
* Read labels from from path
|
||||||
*
|
*
|
||||||
* @param string $path Labels path
|
* @param string $path Labels path
|
||||||
|
* @param string $limit Limit
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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');
|
$fp = \fopen($path, 'r');
|
||||||
if ($fp === false) {
|
if ($fp === false) {
|
||||||
throw new \Exception();
|
throw new PathException($path); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$read = \fread($fp, 4);
|
$read = \fread($fp, 4);
|
||||||
if (!$read) {
|
if ($read === false) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$magicNumber = \unpack('l', $read)[1];
|
$magicNumber = \unpack('N', $read)[1];
|
||||||
|
|
||||||
$read = \fread($fp, 4);
|
$read = \fread($fp, 4);
|
||||||
if (!$read) {
|
if ($read === false) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
$numberOfLabels = \unpack('N', $read)[1];
|
||||||
|
|
||||||
|
if ($limit > 0) {
|
||||||
|
$numberOfLabels = \min($numberOfLabels, $limit);
|
||||||
}
|
}
|
||||||
$numberOfLabels = \unpack('l', $read)[1];
|
|
||||||
|
|
||||||
$labels = [];
|
$labels = [];
|
||||||
for ($i = 0; $i < $numberOfLabels; ++$i) {
|
for ($i = 0; $i < $numberOfLabels; ++$i) {
|
||||||
$read = \fread($fp, 1);
|
$read = \fread($fp, 1);
|
||||||
if (!$read) {
|
if ($read === false) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$labels[] = \unpack('l', $read)[1]; //fread($fp, 1);
|
$labels[] = \unpack('C', $read)[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\fclose($fp);
|
||||||
|
|
||||||
return $labels;
|
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
|
* Find the k-nearest matches for test data
|
||||||
*
|
*
|
||||||
|
|
@ -227,19 +199,22 @@ final class BasicOcr
|
||||||
$distances = $this->getDistances($Xtrain, $sample);
|
$distances = $this->getDistances($Xtrain, $sample);
|
||||||
\asort($distances);
|
\asort($distances);
|
||||||
|
|
||||||
// find possible k-labels for a image
|
$keys = \array_keys($distances);
|
||||||
$kKeys = \array_keys(\array_slice($distances, 0, $k));
|
|
||||||
$candidateLabels = [];
|
|
||||||
|
|
||||||
foreach ($kKeys as $key) {
|
$candidateLabels = [];
|
||||||
$candidateLabels[] = $ytrain[$key];
|
for ($i = 0; $i < $k; ++$i) {
|
||||||
|
$candidateLabels[] = $ytrain[$keys[$i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// find best match
|
// find best match
|
||||||
$countedCandidates = \array_count_values($candidateLabels);
|
$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;
|
return $predictedLabels;
|
||||||
|
|
@ -268,17 +243,19 @@ final class BasicOcr
|
||||||
/**
|
/**
|
||||||
* Categorize an unknown image
|
* 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
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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
|
// @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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,13 +128,13 @@ final class Autoloader
|
||||||
public static function invalidate(string $class) : bool
|
public static function invalidate(string $class) : bool
|
||||||
{
|
{
|
||||||
if (!\extension_loaded('opcache')
|
if (!\extension_loaded('opcache')
|
||||||
|| !\opcache_is_script_cached(__DIR__ . '/../../Models/NewsArticleMapper.php')
|
|| !\opcache_is_script_cached($class)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
\opcache_invalidate(__DIR__ . '/../../Models/NewsArticleMapper.php');
|
\opcache_invalidate($class);
|
||||||
\opcache_compile_file(__DIR__ . '/../../Models/NewsArticleMapper.php');
|
\opcache_compile_file($class);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ abstract class InstallerAbstract
|
||||||
|
|
||||||
$content = \file_get_contents($path);
|
$content = \file_get_contents($path);
|
||||||
if ($content === false) {
|
if ($content === false) {
|
||||||
return;
|
return; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$definitions = \json_decode($content, true);
|
$definitions = \json_decode($content, true);
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,7 @@ final class ModuleManager
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -427,7 +427,7 @@ final class ModuleManager
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -528,10 +528,8 @@ final class ModuleManager
|
||||||
$this->installApplications($module);
|
$this->installApplications($module);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (PathException $e) {
|
} catch (\Throwable $t) {
|
||||||
return false;
|
return false; // @codeCoverageIgnore
|
||||||
} catch (\Exception $e) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -587,9 +585,7 @@ final class ModuleManager
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (PathException $e) {
|
} catch (\Throwable $t) {
|
||||||
return false;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ final class PackageManager
|
||||||
|
|
||||||
$contents = \file_get_contents($this->extractPath . '/' . $file);
|
$contents = \file_get_contents($this->extractPath . '/' . $file);
|
||||||
if ($contents === false) {
|
if ($contents === false) {
|
||||||
throw new \Exception();
|
throw new \Exception(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
\sodium_crypto_generichash_update($state, $contents);
|
\sodium_crypto_generichash_update($state, $contents);
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,11 @@ abstract class UninstallerAbstract
|
||||||
|
|
||||||
$content = \file_get_contents($path);
|
$content = \file_get_contents($path);
|
||||||
if ($content === false) {
|
if ($content === false) {
|
||||||
return;
|
return; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$definitions = \json_decode($content, true);
|
$definitions = \json_decode($content, true);
|
||||||
|
$builder = new SchemaBuilder($dbPool->get('schema'));
|
||||||
$builder = new SchemaBuilder($dbPool->get('schema'));
|
|
||||||
|
|
||||||
foreach ($definitions as $definition) {
|
foreach ($definitions as $definition) {
|
||||||
$builder->dropTable($definition['table'] ?? '');
|
$builder->dropTable($definition['table'] ?? '');
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,20 @@ class File extends FileAbstract implements FileInterface
|
||||||
$this->con = $con ?? self::ftpConnect($this->uri);
|
$this->con = $con ?? self::ftpConnect($this->uri);
|
||||||
|
|
||||||
parent::__construct($uri->getPath());
|
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}
|
* {@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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -377,6 +391,18 @@ class File extends FileAbstract implements FileInterface
|
||||||
return LocalFile::extension($path);
|
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.
|
* Get the parent path of the resource.
|
||||||
*
|
*
|
||||||
|
|
@ -388,12 +414,10 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public function getParent() : ContainerInterface
|
public function getParent() : ContainerInterface
|
||||||
{
|
{
|
||||||
/**
|
$uri = clone $this->uri;
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
$uri->setPath(self::parent($this->path));
|
||||||
* Implement getParent()
|
|
||||||
*/
|
|
||||||
|
|
||||||
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
|
public function copyNode(string $to, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
/**
|
return self::copy($this->con, $this->path, $to, $overwrite);
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
|
||||||
* Implement copyNode()
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -440,12 +459,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public function moveNode(string $to, bool $overwrite = false) : bool
|
public function moveNode(string $to, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
/**
|
return self::move($this->con, $this->path, $to, $overwrite);
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
|
||||||
* Implement moveNode()
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -457,12 +471,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public function deleteNode() : bool
|
public function deleteNode() : bool
|
||||||
{
|
{
|
||||||
/**
|
return self::delete($this->con, $this->path);
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
|
||||||
* Implement deleteNode()
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -477,12 +486,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public function putContent(string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool
|
public function putContent(string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool
|
||||||
{
|
{
|
||||||
/**
|
return self::put($this->con, $this->path, $content, $mode);
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
|
||||||
* Implement putContent()
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -498,12 +502,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public function setContent(string $content) : bool
|
public function setContent(string $content) : bool
|
||||||
{
|
{
|
||||||
/**
|
return $this->putContent($content, ContentPutMode::REPLACE | ContentPutMode::CREATE);
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
|
||||||
* Implement setContent()
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -519,12 +518,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public function appendContent(string $content) : bool
|
public function appendContent(string $content) : bool
|
||||||
{
|
{
|
||||||
/**
|
return $this->putContent($content, ContentPutMode::APPEND);
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
|
||||||
* Implement appendContent()
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -540,12 +534,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public function prependContent(string $content) : bool
|
public function prependContent(string $content) : bool
|
||||||
{
|
{
|
||||||
/**
|
return $this->putContent($content, ContentPutMode::PREPEND);
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
|
||||||
* Implement prependContent()
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -557,12 +546,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public function getContent() : string
|
public function getContent() : string
|
||||||
{
|
{
|
||||||
/**
|
return self::get($this->con, $this->path);
|
||||||
* @todo Orange-Management/phpOMS#??? [p:low] [t:todo] [d:medium]
|
|
||||||
* Implement getContent()
|
|
||||||
*/
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -606,4 +590,12 @@ class File extends FileAbstract implements FileInterface
|
||||||
{
|
{
|
||||||
return \dirname($this->path);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,17 +173,6 @@ abstract class FileAbstract implements ContainerInterface
|
||||||
return $this->path;
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -26,16 +26,24 @@ use phpOMS\System\File\StorageAbstract;
|
||||||
* @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
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
*/
|
||||||
class FtpStorage extends StorageAbstract
|
class FtpStorage extends StorageAbstract
|
||||||
{
|
{
|
||||||
|
private static $con = null;
|
||||||
|
|
||||||
|
public static function with($con)
|
||||||
|
{
|
||||||
|
self::$con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected static function getClassType(string $path) : string
|
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
|
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);
|
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
|
public static function get(string $path) : string
|
||||||
{
|
{
|
||||||
if (\is_dir($path)) {
|
if (static::getClassType($path) === Directory::class) {
|
||||||
throw new PathException($path);
|
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
|
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}
|
* {@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);
|
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
|
public static function set(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
if (\is_dir($path)) {
|
if (static::getClassType($path) === Directory::class) {
|
||||||
throw new PathException($path);
|
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
|
public static function append(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
if (\is_dir($path)) {
|
if (static::getClassType($path) === Directory::class) {
|
||||||
throw new PathException($path);
|
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
|
public static function prepend(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
if (\is_dir($path)) {
|
if (static::getClassType($path) === Directory::class) {
|
||||||
throw new PathException($path);
|
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
|
public static function extension(string $path) : string
|
||||||
{
|
{
|
||||||
if (\is_dir($path)) {
|
if (static::getClassType($path) === Directory::class) {
|
||||||
throw new PathException($path);
|
throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return File::extension($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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,14 +156,6 @@ abstract class FileAbstract implements ContainerInterface
|
||||||
return $this->path;
|
return $this->path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function parentNode() : Directory
|
|
||||||
{
|
|
||||||
return new Directory(Directory::parent($this->path));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,13 @@ class LocalStorage extends StorageAbstract
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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 (\is_file($path)) {
|
||||||
throw new PathException($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
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,41 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\tests\Ai\Ocr;
|
namespace phpOMS\tests\Ai\Ocr;
|
||||||
|
|
||||||
|
use phpOMS\Ai\Ocr\BasicOcr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class BasicOcrTest extends \PHPUnit\Framework\TestCase
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
tests/Ai/Ocr/t10k-images-idx3-ubyte
Normal file
BIN
tests/Ai/Ocr/t10k-images-idx3-ubyte
Normal file
Binary file not shown.
BIN
tests/Ai/Ocr/t10k-labels-idx1-ubyte
Normal file
BIN
tests/Ai/Ocr/t10k-labels-idx1-ubyte
Normal file
Binary file not shown.
BIN
tests/Ai/Ocr/train-images-idx3-ubyte
Normal file
BIN
tests/Ai/Ocr/train-images-idx3-ubyte
Normal file
Binary file not shown.
BIN
tests/Ai/Ocr/train-labels-idx1-ubyte
Normal file
BIN
tests/Ai/Ocr/train-labels-idx1-ubyte
Normal file
Binary file not shown.
|
|
@ -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
|
* @group framework
|
||||||
*/
|
*/
|
||||||
public function testMysqlDrop() : void
|
public function testMysqlDrop() : void
|
||||||
|
|
@ -42,6 +42,17 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals($sql, $query->dropDatabase('test')->toSql());
|
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
|
* @testdox Mysql show tables form a valid query
|
||||||
* @group framework
|
* @group framework
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$model1 = new BaseModel();
|
$model1 = new BaseModel();
|
||||||
$model2 = 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
|
public function update() : void
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ use phpOMS\Dispatcher\Dispatcher;
|
||||||
use phpOMS\Message\Http\HttpRequest;
|
use phpOMS\Message\Http\HttpRequest;
|
||||||
use phpOMS\Module\ModuleManager;
|
use phpOMS\Module\ModuleManager;
|
||||||
use phpOMS\Router\WebRouter;
|
use phpOMS\Router\WebRouter;
|
||||||
|
use phpOMS\System\File\Local\Directory;
|
||||||
use phpOMS\Uri\HttpUri;
|
use phpOMS\Uri\HttpUri;
|
||||||
|
|
||||||
require_once __DIR__ . '/../Autoloader.php';
|
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->isActive('TestModule'));
|
||||||
self::assertFalse($this->moduleManager->isRunning('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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
Directory::delete(__DIR__ . '/dummyModule');
|
Directory::delete(__DIR__ . '/dummyModule');
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory::copy(__DIR__ . '/testModule', __DIR__ . '/dummyModule');
|
Directory::copy(__DIR__ . '/testModulePackage', __DIR__ . '/dummyModule');
|
||||||
|
|
||||||
$package = new PackageManager(
|
$package = new PackageManager(
|
||||||
__DIR__ . '/testPackage.zip',
|
__DIR__ . '/testPackage.zip',
|
||||||
|
|
|
||||||
29
tests/Module/Testmodule/Admin/Installer.php
Normal file
29
tests/Module/Testmodule/Admin/Installer.php
Normal 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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -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": {}
|
||||||
|
}
|
||||||
25
tests/Module/Testmodule/info.json
Normal file
25
tests/Module/Testmodule/info.json
Normal 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": [
|
||||||
|
]
|
||||||
|
}
|
||||||
0
tests/Module/testModulePackage/toMove/sub/b.txt
Normal file
0
tests/Module/testModulePackage/toMove/sub/b.txt
Normal file
|
|
@ -184,15 +184,16 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
public function testStaticCreatedAt() : void
|
public function testStaticCreatedAt() : void
|
||||||
{
|
{
|
||||||
self::markTestSkipped();
|
|
||||||
$dirPath = __DIR__ . '/test';
|
$dirPath = __DIR__ . '/test';
|
||||||
|
|
||||||
self::assertTrue(Directory::create(self::$con, $dirPath));
|
self::assertTrue(Directory::create(self::$con, $dirPath));
|
||||||
|
|
||||||
$now = new \DateTime('now');
|
$now = new \DateTime('now');
|
||||||
|
$now->setTimestamp(-1);
|
||||||
|
|
||||||
self::assertEquals($now->format('Y-m-d'), Directory::created(self::$con, $dirPath)->format('Y-m-d'));
|
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
|
public function testStaticChangedAt() : void
|
||||||
{
|
{
|
||||||
self::markTestSkipped();
|
|
||||||
|
|
||||||
$dirPath = __DIR__ . '/test';
|
$dirPath = __DIR__ . '/test';
|
||||||
|
|
||||||
self::assertTrue(Directory::create(self::$con, $dirPath));
|
self::assertTrue(Directory::create(self::$con, $dirPath));
|
||||||
|
|
||||||
$now = new \DateTime('now');
|
$now = new \DateTime('now');
|
||||||
|
$now->setTimestamp(-1);
|
||||||
|
|
||||||
self::assertEquals($now->format('Y-m-d'), Directory::changed(self::$con, $dirPath)->format('Y-m-d'));
|
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);
|
$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
|
public function testNodeNext() : void
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ class FileTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$testFile = __DIR__ . '/test.txt';
|
$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);
|
$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
|
public function testNodeDirectory() : void
|
||||||
|
|
|
||||||
1101
tests/System/File/Ftp/FtpStorageTest.php
Normal file
1101
tests/System/File/Ftp/FtpStorageTest.php
Normal file
File diff suppressed because it is too large
Load Diff
|
|
@ -592,7 +592,7 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$dir = new Directory(__DIR__ . '/dirtest');
|
$dir = new Directory(__DIR__ . '/dirtest');
|
||||||
|
|
||||||
self::assertEquals(__DIR__, $dir->parentNode()->getPath());
|
self::assertEquals(__DIR__, $dir->getParent()->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNodeNext() : void
|
public function testNodeNext() : void
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,7 @@ class LocalStorageTest extends \PHPUnit\Framework\TestCase
|
||||||
public function testStaticListFilesDirectory() : void
|
public function testStaticListFilesDirectory() : void
|
||||||
{
|
{
|
||||||
$dirTestPath = __DIR__ . '/dirtest';
|
$dirTestPath = __DIR__ . '/dirtest';
|
||||||
self::assertCount(6, LocalStorage::list($dirTestPath));
|
self::assertCount(6, LocalStorage::list($dirTestPath, '*', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user