test fixes + new test data

This commit is contained in:
Dennis Eichhorn 2023-05-19 02:37:35 +00:00
parent 475b52e67c
commit 4d9f4aa241
77 changed files with 2393 additions and 886 deletions

View File

@ -24,4 +24,11 @@ namespace phpOMS\Account;
*/
final class NullAccount extends Account
{
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -87,7 +87,7 @@ final class TesseractOcr
*/
public function parseImage(string $image, array $languages = ['eng'], int $psm = 3, int $oem = 3) : string
{
$temp = \tempnam(\sys_get_temp_dir(), 'ocr_');
$temp = \tempnam(\sys_get_temp_dir(), 'oms_ocr_');
if ($temp === false) {
return '';
}
@ -107,15 +107,24 @@ final class TesseractOcr
: $temp;
if (!\is_file($filepath)) {
// @codeCoverageIgnoreStart
\unlink($temp);
return '';
// @codeCoverageIgnoreEnd
}
$parsed = \file_get_contents($filepath);
if ($parsed === false) {
// @codeCoverageIgnoreStart
\unlink($temp);
return '';
// @codeCoverageIgnoreEnd
}
\unlink($filepath);
\unlink($temp);
return \trim($parsed);
}

View File

@ -194,16 +194,8 @@ abstract class GrammarAbstract
foreach ($elements as $key => $element) {
if (\is_string($element)) {
// @note: Replaced $this->compileSystem with $element
// This causes problems for tables or columns which use keywords such as count,
// but they are rare and should be handled somewhere else if it actually is such a case
if (\in_array($element, ['group', 'id', 'where', 'order'])) {
$expression .= $this->compileSystem($element)
. (\is_string($key) ? ' as ' . $key : '') . ', ';
} else {
$expression .= $element
. (\is_string($key) ? ' as ' . $key : '') . ', ';
}
} elseif ($element instanceof \Closure) {
$expression .= $element() . (\is_string($key) ? ' as ' . $key : '') . ', ';
} elseif ($element instanceof BuilderAbstract) {

View File

@ -258,13 +258,13 @@ final class WriteMapper extends DataMapperAbstract
*/
private function createHasMany(\ReflectionClass $refClass, object $obj, mixed $objId) : void
{
foreach ($this->mapper::HAS_MANY as $propertyName => $rel) {
foreach ($this->mapper::HAS_MANY as $propertyName => $_) {
if (!isset($this->mapper::HAS_MANY[$propertyName]['mapper'])) {
throw new InvalidMapperException(); // @codeCoverageIgnore
}
$property = $refClass->getProperty($propertyName);
if (!($isPublic = $property->isPublic())) {
if (!$property->isPublic()) {
$values = $property->getValue($obj);
} else {
$values = $obj->{$propertyName};

View File

@ -280,6 +280,7 @@ class Grammar extends GrammarAbstract
}
if (\is_string($element['column'])) {
// @todo: check if column contains special name which needs to be escaped
$expression .= $this->compileSystem($element['column']);
} elseif ($element['column'] instanceof \Closure) {
$expression .= $element['column']();
@ -311,7 +312,7 @@ class Grammar extends GrammarAbstract
*/
protected function compileWhereQuery(Where $where) : string
{
return $where->toSql()[0];
return $where->toSql();
}
/**
@ -325,7 +326,7 @@ class Grammar extends GrammarAbstract
*/
protected function compileFromQuery(From $from) : string
{
return $from->toSql()[0];
return $from->toSql();
}
/**
@ -478,7 +479,8 @@ class Grammar extends GrammarAbstract
$expression = '';
foreach ($groups as $group) {
$expression .= $this->compileSystem($group) . ', ';
// @todo: check special names
$expression .= $group . ', ';
}
$expression = \rtrim($expression, ', ');
@ -570,6 +572,8 @@ class Grammar extends GrammarAbstract
return '';
}
// @todo: check special names
$cols = '(';
for ($i = 0; $i < $count; ++$i) {
$cols .= $this->compileSystem($columns[$i]) . ', ';

View File

@ -124,11 +124,11 @@ final class Kernel
}
}
$newR = \max(0, \min(255, $newR));
$newG = \max(0, \min(255, $newG));
$newB = \max(0, \min(255, $newB));
$newR = (int) \max(0, \min(255, $newR));
$newG = (int) \max(0, \min(255, $newG));
$newB = (int) \max(0, \min(255, $newB));
\imagesetpixel($im, $x, $y, (int) (($newR << 16) + ($newG << 8) | $newB));
\imagesetpixel($im, $x, $y, (int) (($newR << 16) | ($newG << 8) | $newB));
}
}
}

View File

@ -99,6 +99,7 @@ class BaseStringL11n implements \JsonSerializable
$this->content = $content;
$this->language = $language;
$this->country = $country;
$this->type = new NullBaseStringL11nType();
}
/**

View File

@ -527,4 +527,6 @@ class ISO3166NameEnum extends Enum
public const _XXK = 'Kosovo';
public const _XXX = 'XXX';
use ISO3166RegionTrait;
}

View File

@ -38,6 +38,8 @@ trait ISO639CountryTrait
switch (\strtoupper($country)) {
case ISO3166TwoEnum::_AFG:
return [self::_PS, self::_UZ, self::_TK];
case ISO3166TwoEnum::_ATA:
return [self::_RU, self::_EN];
case ISO3166TwoEnum::_ALA:
return [self::_SV];
case ISO3166TwoEnum::_ALB:
@ -95,7 +97,7 @@ trait ISO639CountryTrait
case ISO3166TwoEnum::_BWA:
return [self::_EN, self::_TN];
case ISO3166TwoEnum::_BVT:
return [];
return [self::_NO];
case ISO3166TwoEnum::_BRA:
return [self::_PT];
case ISO3166TwoEnum::_IOT:
@ -308,6 +310,8 @@ trait ISO639CountryTrait
return [self::_FR];
case ISO3166TwoEnum::_MLT:
return [self::_MT, self::_EN];
case ISO3166TwoEnum::_MKD:
return [self::_MK];
case ISO3166TwoEnum::_MHL:
return [self::_MH, self::_EN];
case ISO3166TwoEnum::_MTQ:

View File

@ -100,7 +100,7 @@ final class FileLogger implements LoggerInterface
*/
public function __construct(string $lpath = '', bool $verbose = false)
{
$path = \realpath(empty($lpath) ? __DIR__ . '/../../' : $lpath);
$path = \realpath(empty($lpath) ? __DIR__ . '/../../Logs/' : $lpath);
$this->verbose = $verbose;
$this->path = \is_dir($lpath) || \strpos($lpath, '.') === false

View File

@ -277,831 +277,206 @@ final class HttpHeader extends HeaderAbstract
{
switch ($code) {
case RequestStatusCode::R_100:
$this->generate100();
break;
case RequestStatusCode::R_102:
$this->generate102();
break;
case RequestStatusCode::R_200:
$this->generate200();
break;
case RequestStatusCode::R_201:
$this->generate201();
break;
case RequestStatusCode::R_202:
$this->generate202();
break;
case RequestStatusCode::R_204:
$this->generate204();
break;
case RequestStatusCode::R_205:
$this->generate205();
break;
case RequestStatusCode::R_206:
$this->generate206();
break;
case RequestStatusCode::R_301:
$this->generate301();
break;
case RequestStatusCode::R_302:
$this->generate302();
break;
case RequestStatusCode::R_303:
$this->generate303();
break;
case RequestStatusCode::R_304:
$this->generate304();
break;
case RequestStatusCode::R_307:
$this->generate307();
break;
case RequestStatusCode::R_308:
$this->generate308();
break;
case RequestStatusCode::R_400:
$this->generate400();
break;
case RequestStatusCode::R_401:
$this->generate401();
break;
case RequestStatusCode::R_402:
$this->generate402();
break;
case RequestStatusCode::R_403:
$this->generate403();
break;
case RequestStatusCode::R_404:
$this->generate404();
break;
case RequestStatusCode::R_405:
$this->generate405();
break;
case RequestStatusCode::R_406:
$this->generate406();
break;
case RequestStatusCode::R_407:
$this->generate407();
break;
case RequestStatusCode::R_408:
$this->generate408();
break;
case RequestStatusCode::R_409:
$this->generate409();
break;
case RequestStatusCode::R_410:
$this->generate410();
break;
case RequestStatusCode::R_411:
$this->generate411();
break;
case RequestStatusCode::R_412:
$this->generate412();
break;
case RequestStatusCode::R_413:
$this->generate413();
break;
case RequestStatusCode::R_414:
$this->generate414();
break;
case RequestStatusCode::R_415:
$this->generate415();
break;
case RequestStatusCode::R_416:
$this->generate416();
break;
case RequestStatusCode::R_417:
$this->generate417();
break;
case RequestStatusCode::R_421:
$this->generate421();
break;
case RequestStatusCode::R_422:
$this->generate422();
break;
case RequestStatusCode::R_423:
$this->generate423();
break;
case RequestStatusCode::R_424:
$this->generate424();
break;
case RequestStatusCode::R_426:
$this->generate426();
break;
case RequestStatusCode::R_428:
$this->generate428();
break;
case RequestStatusCode::R_429:
$this->generate429();
break;
case RequestStatusCode::R_431:
$this->generate431();
break;
case RequestStatusCode::R_451:
$this->generate451();
break;
case RequestStatusCode::R_500:
$this->generate500();
break;
case RequestStatusCode::R_501:
$this->generate501();
break;
case RequestStatusCode::R_502:
$this->generate502();
break;
case RequestStatusCode::R_503:
$this->generate503();
break;
case RequestStatusCode::R_504:
$this->generate504();
break;
case RequestStatusCode::R_507:
$this->generate507();
break;
case RequestStatusCode::R_508:
$this->generate508();
break;
case RequestStatusCode::R_511:
$this->generate511();
break;
default:
$this->generate500();
}
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate100() : void
{
$this->set('', 'HTTP/1.0 100 Continue');
$this->set('Status', '100 Continue');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate102() : void
{
break;
case RequestStatusCode::R_102:
$this->set('', 'HTTP/1.0 102 Processing');
$this->set('Status', '102 Processing');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate200() : void
{
break;
case RequestStatusCode::R_200:
$this->set('', 'HTTP/1.0 200 OK');
$this->set('Status', '200 OK');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate201() : void
{
break;
case RequestStatusCode::R_201:
$this->set('', 'HTTP/1.0 201 Created');
$this->set('Status', '201 Created');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate202() : void
{
break;
case RequestStatusCode::R_202:
$this->set('', 'HTTP/1.0 202 Accepted');
$this->set('Status', '202 Accepted');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate204() : void
{
break;
case RequestStatusCode::R_204:
$this->set('', 'HTTP/1.0 204 No Content');
$this->set('Status', '204 No Content');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate205() : void
{
break;
case RequestStatusCode::R_205:
$this->set('', 'HTTP/1.0 205 Reset Content');
$this->set('Status', '205 Reset Content');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate206() : void
{
break;
case RequestStatusCode::R_206:
$this->set('', 'HTTP/1.0 206 Partial Content');
$this->set('Status', '206 Partial Content');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate301() : void
{
break;
case RequestStatusCode::R_301:
$this->set('', 'HTTP/1.0 301 Moved Permanently');
$this->set('Status', '301 Moved Permanently');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate302() : void
{
break;
case RequestStatusCode::R_302:
$this->set('', 'HTTP/1.0 302 Found');
$this->set('Status', '302 Found');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate303() : void
{
break;
case RequestStatusCode::R_303:
$this->set('', 'HTTP/1.0 303 See Other');
$this->set('Status', '303 See Other');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate304() : void
{
break;
case RequestStatusCode::R_304:
$this->set('', 'HTTP/1.0 304 Not Modified');
$this->set('Status', '304 Not Modified');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate307() : void
{
break;
case RequestStatusCode::R_307:
$this->set('', 'HTTP/1.0 307 Temporary Redirect');
$this->set('Status', '307 Temporary Redirect');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate308() : void
{
break;
case RequestStatusCode::R_308:
$this->set('', 'HTTP/1.0 308 Permanent Redirect');
$this->set('Status', '308 Permanent Redirect');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate400() : void
{
break;
case RequestStatusCode::R_400:
$this->set('', 'HTTP/1.0 400 Bad Request');
$this->set('Status', '400 Bad Request');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate401() : void
{
break;
case RequestStatusCode::R_401:
$this->set('', 'HTTP/1.0 401 Unauthorized');
$this->set('Status', '401 Unauthorized');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate402() : void
{
break;
case RequestStatusCode::R_402:
$this->set('', 'HTTP/1.0 402 Payment Required');
$this->set('Status', '402 Payment Required');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate403() : void
{
break;
case RequestStatusCode::R_403:
$this->set('', 'HTTP/1.0 403 Forbidden');
$this->set('Status', '403 Forbidden');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate404() : void
{
break;
case RequestStatusCode::R_404:
$this->set('', 'HTTP/1.0 404 Not Found');
$this->set('Status', '404 Not Found');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate405() : void
{
break;
case RequestStatusCode::R_405:
$this->set('', 'HTTP/1.0 405 Method Not Allowed');
$this->set('Status', '405 Method Not Allowed');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate406() : void
{
break;
case RequestStatusCode::R_406:
$this->set('', 'HTTP/1.0 406 Not acceptable');
$this->set('Status', '406 Not acceptable');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate407() : void
{
break;
case RequestStatusCode::R_407:
$this->set('', 'HTTP/1.0 407 Proxy Authentication Required');
$this->set('Status', '407 Proxy Authentication Required');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate408() : void
{
break;
case RequestStatusCode::R_408:
$this->set('', 'HTTP/1.0 408 Request Timeout');
$this->set('Status', '408 Request Timeout');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate409() : void
{
break;
case RequestStatusCode::R_409:
$this->set('', 'HTTP/1.0 409 Conflict');
$this->set('Status', '409 Conflict');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate410() : void
{
break;
case RequestStatusCode::R_410:
$this->set('', 'HTTP/1.0 410 Gone');
$this->set('Status', '410 Gone');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate411() : void
{
break;
case RequestStatusCode::R_411:
$this->set('', 'HTTP/1.0 411 Length Required');
$this->set('Status', '411 Length Required');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate412() : void
{
break;
case RequestStatusCode::R_412:
$this->set('', 'HTTP/1.0 412 Precondition Failed');
$this->set('Status', '412 Precondition Failed');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate413() : void
{
break;
case RequestStatusCode::R_413:
$this->set('', 'HTTP/1.0 413 Request Entity Too Large');
$this->set('Status', '413 Request Entity Too Large');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate414() : void
{
break;
case RequestStatusCode::R_414:
$this->set('', 'HTTP/1.0 414 Request-URI Too Long');
$this->set('Status', '414 Request-URI Too Long');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate415() : void
{
break;
case RequestStatusCode::R_415:
$this->set('', 'HTTP/1.0 415 Unsupported Media Type');
$this->set('Status', '415 Unsupported Media Type');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate416() : void
{
break;
case RequestStatusCode::R_416:
$this->set('', 'HTTP/1.0 416 Requested Range Not Satisfiable');
$this->set('Status', '416 Requested Range Not Satisfiable');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate417() : void
{
break;
case RequestStatusCode::R_417:
$this->set('', 'HTTP/1.0 417 Expectation Failed');
$this->set('Status', '417 Expectation Failed');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate421() : void
{
break;
case RequestStatusCode::R_421:
$this->set('', 'HTTP/1.0 421 Misdirected Request');
$this->set('Status', '421 Misdirected Request');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate422() : void
{
break;
case RequestStatusCode::R_422:
$this->set('', 'HTTP/1.0 422 Unprocessable Entity');
$this->set('Status', '422 Unprocessable Entity');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate423() : void
{
break;
case RequestStatusCode::R_423:
$this->set('', 'HTTP/1.0 423 Locked');
$this->set('Status', '423 Locked');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate424() : void
{
break;
case RequestStatusCode::R_424:
$this->set('', 'HTTP/1.0 424 Failed Dependency');
$this->set('Status', '424 Failed Dependency');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate425() : void
{
break;
case RequestStatusCode::R_425:
$this->set('', 'HTTP/1.0 425 Too Early');
$this->set('Status', '425 Too Early');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate426() : void
{
break;
case RequestStatusCode::R_426:
$this->set('', 'HTTP/1.0 426 Upgrade Required');
$this->set('Status', '426 Upgrade Required');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate428() : void
{
break;
case RequestStatusCode::R_428:
$this->set('', 'HTTP/1.0 428 Precondition Required');
$this->set('Status', '428 Precondition Required');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate429() : void
{
break;
case RequestStatusCode::R_429:
$this->set('', 'HTTP/1.0 429 Too Many Requests');
$this->set('Status', '429 Too Many Requests');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate431() : void
{
break;
case RequestStatusCode::R_431:
$this->set('', 'HTTP/1.0 431 Request Header Fields Too Large');
$this->set('Status', '431 Request Header Fields Too Large');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate451() : void
{
break;
case RequestStatusCode::R_451:
$this->set('', 'HTTP/1.0 451 Unavailable For Legal Reasons');
$this->set('Status', '451 Unavailable For Legal Reasons');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate500() : void
{
$this->set('', 'HTTP/1.0 500 Internal Server Error');
$this->set('Status', '500 Internal Server Error');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate501() : void
{
break;
case RequestStatusCode::R_501:
$this->set('', 'HTTP/1.0 501 Not Implemented');
$this->set('Status', '501 Not Implemented');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate502() : void
{
break;
case RequestStatusCode::R_502:
$this->set('', 'HTTP/1.0 502 Bad Gateway');
$this->set('Status', '502 Bad Gateway');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate503() : void
{
break;
case RequestStatusCode::R_503:
$this->set('', 'HTTP/1.0 503 Service Temporarily Unavailable');
$this->set('Status', '503 Service Temporarily Unavailable');
$this->set('Retry-After', 'Retry-After: 300');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate504() : void
{
break;
case RequestStatusCode::R_504:
$this->set('', 'HTTP/1.0 504 Gateway Timeout');
$this->set('Status', '504 Gateway Timeout');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate507() : void
{
break;
case RequestStatusCode::R_507:
$this->set('', 'HTTP/1.0 507 Insufficient Storage');
$this->set('Status', '507 Insufficient Storage');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate508() : void
{
break;
case RequestStatusCode::R_508:
$this->set('', 'HTTP/1.0 508 Loop Detected');
$this->set('Status', '508 Loop Detected');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate511() : void
{
break;
case RequestStatusCode::R_511:
$this->set('', 'HTTP/1.0 511 Network Authentication Required');
$this->set('Status', '511 Network Authentication Required');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate598() : void
{
$this->set('', 'HTTP/1.0 598 Network read timeout error');
$this->set('Status', '598 Network read timeout error');
}
/**
* Generate predefined header.
*
* @return void
*
* @since 1.0.0
*/
private function generate599() : void
{
$this->set('', 'HTTP/1.0 599 Network connect timeout error');
$this->set('Status', '599 Network connect timeout error');
break;
case RequestStatusCode::R_500:
default:
$this->set('', 'HTTP/1.0 500 Internal Server Error');
$this->set('Status', '500 Internal Server Error');
}
}
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace phpOMS\Model\Message;
use phpOMS\Contract\SerializableInterface;
use phpOMS\Message\NotificationLevel;
/**
* Notify class.
@ -72,7 +73,7 @@ final class Notify implements \JsonSerializable, SerializableInterface
* @var string
* @since 1.0.0
*/
public string $level = NotifyType::INFO;
public string $level = NotificationLevel::INFO;
/**
* Constructor.
@ -82,7 +83,7 @@ final class Notify implements \JsonSerializable, SerializableInterface
*
* @since 1.0.0
*/
public function __construct(string $msg = '', string $level = NotifyType::INFO)
public function __construct(string $msg = '', string $level = NotificationLevel::INFO)
{
$this->message = $msg;
$this->level = $level;

View File

@ -70,8 +70,8 @@ final class EncryptionHelper
public static function encryptFile(string $in, string $out, string $keyHex) : bool
{
$fpSource = \fopen($in, 'r+');
$fpEncoded = \fopen($out . '.tmp', 'w');
$fpSource = \fopen($in, 'rb');
$fpEncoded = \fopen($out . '.tmp', 'wb');
if ($fpSource === false || $fpEncoded === false) {
return false;
@ -80,10 +80,13 @@ final class EncryptionHelper
$secretKey = \sodium_hex2bin($keyHex);
$nonce = \random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
while (($buffer = \fgets($fpSource, 4096)) !== false) {
$ciphertext = \sodium_crypto_secretbox($buffer, $nonce, $keyHex);
\fwrite($fpEncoded, $nonce);
\fwrite($fpEncoded, $ciphertext);
while (!\feof($fpSource)) {
$buffer = \fread($fpSource, 4096);
$ciphertext = \sodium_crypto_secretbox($buffer, $nonce, $secretKey);
fwrite($fpEncoded, $ciphertext);
}
\fclose($fpSource);
@ -144,22 +147,26 @@ final class EncryptionHelper
public static function decryptFile(string $in, string $out, string $keyHex) : bool
{
$fpSource = \fopen($in, 'r+');
$fpDecoded = \fopen($out . '.tmp', 'w');
$fpSource = \fopen($in, 'rb');
$fpDecoded = \fopen($out . '.tmp', 'wb');
if ($fpSource === false || $fpDecoded === false) {
return false;
}
$secretKey = \sodium_hex2bin($keyHex);
$nonce = \fread($fpSource, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
while (($buffer = \fgets($fpSource, 4096)) !== false) {
$ciphertext = \sodium_base642bin($buffer, SODIUM_BASE64_VARIANT_ORIGINAL);
$nonce = \mb_substr($ciphertext, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
$ciphertext = \mb_substr($ciphertext, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
while (!\feof($fpSource)) {
$buffer = \fread($fpSource, 4096);
$ciphertext = \mb_substr($buffer, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
$plaintext = \sodium_crypto_secretbox_open($ciphertext, $nonce, $secretKey);
if ($plaintext === false) {
return false;
}
\fwrite($fpDecoded, $plaintext);
}

View File

@ -38,7 +38,7 @@ class Graph
* @var bool
* @since 1.0.0
*/
protected bool $isDirected = false;
public bool $isDirected = false;
/**
* Set node to graph.
@ -628,6 +628,9 @@ class Graph
foreach ($this->nodes as $node) {
$visited[$node->getId()] = false;
}
foreach ($this->nodes as $node) {
$this->longestPathDfs($node, $visited, $path, $longestPath);
}
@ -875,21 +878,18 @@ class Graph
*/
public function getDiameter() : int
{
$diameter = 0;
$paths = $this->getFloydWarshallShortestPath();
$count = [];
foreach ($this->nodes as $node1) {
foreach ($this->nodes as $node2) {
if ($node1 === $node2) {
continue;
if (empty($paths)) {
return 0;
}
/** @var int $diameter */
$diameter = \max($diameter, $this->getFloydWarshallShortestPath());
}
foreach ($paths as $path) {
$count[] = \count($path);
}
/** @var int $diameter */
return $diameter;
return \max($count);
}
/**
@ -994,7 +994,7 @@ class Graph
: $edge->node1;
}
if ($next->isEqual($previous)) {
if ($previous !== null && $next->isEqual($previous)) {
continue;
}
@ -1197,20 +1197,13 @@ class Graph
*
* @since 1.0.0
*/
public function isBipartite(int | string | Node $node1) : bool
public function isBipartite() : bool
{
if (!($node1 instanceof Node)) {
$node1 = $this->getNode($node1);
}
if ($node1 === null) {
return true;
}
foreach ($this->nodes as $node) {
$colors[$node->getId()] = 0;
}
$node1 = \reset($this->nodes);
$colors[$node1->getId()] = 1;
$stack = [];

View File

@ -115,10 +115,10 @@ abstract class TwoDAbstract extends CodeAbstract
$matrixDimension = \max(\count($codeArray), \count(\reset($codeArray)));
$imageDimension = \max($this->dimension['width'], $this->dimension['width']);
$multiplier = (int) ($imageDimension - 2 * $this->margin) / $matrixDimension;
$multiplier = (int) (($imageDimension - 2 * $this->margin) / $matrixDimension);
$dimensions['width'] = $matrixDimension * $multiplier + 2 * $this->margin;
$dimensions['height'] = $matrixDimension * $multiplier + 2 * $this->margin;
$dimensions['width'] = (int) ($matrixDimension * $multiplier + 2 * $this->margin);
$dimensions['height'] = (int) ($matrixDimension * $multiplier + 2 * $this->margin);
return $dimensions;
}

View File

@ -80,7 +80,7 @@ final class Currency
$to = \strtoupper($to);
if (!isset($currencies[$to])) {
throw new \InvalidArgumentException('Currency doesn\'t exists');
return -1.0;
}
return $value * $currencies[$to];
@ -147,7 +147,7 @@ final class Currency
$from = \strtoupper($from);
if (!isset($currencies[$from])) {
throw new \InvalidArgumentException('Currency doesn\'t exists');
return -1.0;
}
return $value / $currencies[$from];
@ -172,8 +172,10 @@ final class Currency
$from = \strtoupper($from);
$to = \strtoupper($to);
if ((!isset($currencies[$from]) && $from !== ISO4217CharEnum::_EUR) || (!isset($currencies[$to]) && $to !== ISO4217CharEnum::_EUR)) {
throw new \InvalidArgumentException('Currency doesn\'t exists');
if ((!isset($currencies[$from]) && $from !== ISO4217CharEnum::_EUR)
|| (!isset($currencies[$to]) && $to !== ISO4217CharEnum::_EUR)
) {
return -1.0;
}
if ($from !== ISO4217CharEnum::_EUR) {

View File

@ -30,7 +30,7 @@ class Commit
* @var string
* @since 1.0.0
*/
private string $id = '';
public string $id = '';
/**
* Author.

View File

@ -119,9 +119,7 @@ final class ImageUtils
/** @var array $imageDim */
$imageDim = \getimagesize($srcPath);
if ((($imageDim[0] ?? -1) >= $width && ($imageDim[1] ?? -1) >= $height)
|| ($imageDim[0] === 0 || $imageDim[1] === 0)
) {
if ($imageDim[0] === 0 || $imageDim[1] === 0) {
return;
}
@ -155,6 +153,13 @@ final class ImageUtils
throw new \InvalidArgumentException();
}
if (\stripos($srcPath, '.png')) {
\imagealphablending($dst, false);
$transparent = \imagecolorallocatealpha($dst, 0, 0, 0, 127);
\imagefill($dst, 0, 0, $transparent);
\imagesavealpha($dst, true);
}
\imagecopyresampled($dst, $src, 0, 0, 0, 0, $width, $height, $imageDim[0], $imageDim[1]);
if (\stripos($srcPath, '.jpg') || \stripos($srcPath, '.jpeg')) {
@ -211,7 +216,7 @@ final class ImageUtils
$newDim = [\max($imageDim1[0], $imageDim2[0]), \max($imageDim1[1], $imageDim2[1])];
$diff = empty($out) ? -1 : $out;
$diff = empty($out) ? -1 : $diff;
$dst = false;
$red = 0;
@ -243,10 +248,12 @@ final class ImageUtils
}
}
$diffArea = 5;
$difference = 0;
for ($i = 0; $i < $newDim[0]; ++$i) {
for ($j = 0; $j < $newDim[1]; ++$j) {
// Dimension difference
if ($i >= $imageDim1[0] || $j >= $imageDim1[1]) {
if ($diff === 0) {
/** @var \GdImage $dst */
@ -271,6 +278,7 @@ final class ImageUtils
continue;
}
// Dimension difference
if ($i >= $imageDim2[0] || $j >= $imageDim2[1]) {
if ($diff === 0) {
/** @var \GdImage $dst */
@ -295,10 +303,14 @@ final class ImageUtils
continue;
}
// Get average color at current pixel position with a 10 pixel area
$color1Avg = self::getAverageColor($src1, $i, $j, $imageDim2[0], $imageDim2[1], $diffArea);
$color2Avg = self::getAverageColor($src2, $i, $j, $newDim[0], $newDim[1], $diffArea);
$color1 = \imagecolorat($src1, $i, $j);
$color2 = \imagecolorat($src2, $i, $j);
if ($color1 !== $color2 && $color1 !== false && $color2 !== false) {
if (\abs($color1Avg - $color2Avg) / $color1Avg > 0.05 && $color1Avg > 0 && $color2Avg > 0) {
++$difference;
if ($diff === 0) {
@ -329,4 +341,27 @@ final class ImageUtils
return $difference;
}
private static function getAverageColor($src, $x, $y, $width, $height, $area = 10) : int
{
$colors = [];
for ($i = $x - $area; $i < $x + $area; ++$i) {
for ($j = $y - $area; $j < $y + $area; ++$j) {
if ($i < 0 || $j < 0 || $i >= $width || $j >= $height) {
continue;
}
$color = \imagecolorat($src, $i, $j);
if ($color === false) {
continue;
}
$colors[] = $color;
}
}
return (int) (\array_sum($colors) / \count($colors));
}
}

View File

@ -58,7 +58,7 @@ class PdfParser
$text = '';
$tmpDir = \sys_get_temp_dir();
$out = \tempnam($tmpDir, 'pdf_');
$out = \tempnam($tmpDir, 'oms_pdf_');
if ($out === false) {
return '';
}
@ -79,7 +79,7 @@ class PdfParser
}
if (\strlen($text) < 256) {
$out = \tempnam($tmpDir, 'pdf_');
$out = \tempnam($tmpDir, 'oms_pdf_');
if ($out === false) {
return '';
}
@ -95,6 +95,8 @@ class PdfParser
$files = \glob($out . '*');
if ($files === false) {
\unlink($out);
return $text === false ? '' : $text;
}
@ -124,6 +126,8 @@ class PdfParser
\unlink($file);
}
\unlink($out);
}
return $text;

View File

@ -38,6 +38,8 @@ class Cron extends SchedulerAbstract
}
if (!empty($this->getAllByName($task->getId()))) {
\unlink($path);
return;
}

View File

@ -30,7 +30,7 @@ abstract class TaskAbstract
* @var string
* @since 1.0.0
*/
protected string $id = '';
public string $id = '';
/**
* Command used for creating the task

View File

@ -58,7 +58,6 @@ final class EUVat extends ValidatorAbstract
'SWE' => '/^(SE)([0-9]{10}[0-9]{2})$/i',
'SVN' => '/^(SI)([0-9]{8})$/',
'SVK' => '/^(SK)([0-9][10])$/',
'HRV' => '/^(HR)([0-9][11])$/',
];
/**

View File

@ -222,6 +222,18 @@ final class AccountTest extends \PHPUnit\Framework\TestCase
self::assertTrue($account->hasPermission(PermissionType::NONE));
}
public function testGroupPmerissionExists() : void
{
$account = new Account();
$group = new NullGroup(2);
$perm = new class() extends PermissionAbstract {};
$perm->addPermission(PermissionType::CREATE);
$group->addPermission($perm);
$account->hasPermission(PermissionType::READ);
}
/**
* @testdox Account permissions can be removed
* @covers phpOMS\Account\Account<extended>

View File

@ -44,4 +44,10 @@ final class NullAccountTest extends \PHPUnit\Framework\TestCase
$null = new NullAccount(2);
self::assertEquals(2, $null->getId());
}
public function testJsonSerialization() : void
{
$null = new NullAccount(2);
self::assertEquals(['id' => 2], $null->jsonSerialize());
}
}

View File

@ -44,4 +44,10 @@ final class NullGroupTest extends \PHPUnit\Framework\TestCase
$null = new NullGroup(2);
self::assertEquals(2, $null->getId());
}
public function testJsonSerialization() : void
{
$null = new NullGroup(2);
self::assertEquals(['id' => 2], $null->jsonSerialize());
}
}

View File

@ -188,6 +188,26 @@ final class PermissionAbstractTest extends \PHPUnit\Framework\TestCase
self::assertFalse($perm1->isEqual($perm2));
}
public function testFullPermissions() : void
{
$perm = new class() extends PermissionAbstract {};
$perm->addPermission(PermissionType::READ);
$perm->addPermission(PermissionType::CREATE);
$perm->addPermission(PermissionType::MODIFY);
$perm->addPermission(PermissionType::DELETE);
$perm->addPermission(PermissionType::PERMISSION);
self::assertEquals(
PermissionType::READ
| PermissionType::CREATE
| PermissionType::MODIFY
| PermissionType::DELETE
| PermissionType::PERMISSION,
$perm->getPermission()
);
}
/**
* @testdox Correct permissions are validated
* @covers phpOMS\Account\PermissionAbstract

BIN
tests/Ai/Ocr/3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -42,6 +42,27 @@ final class BasicOcrTest extends \PHPUnit\Framework\TestCase
);
}
public function testCustomMnistFiles() : void
{
$ocr = new BasicOcr();
$ocr->trainWith(__DIR__ . '/train-images-idx3-ubyte', __DIR__ . '/train-labels-idx1-ubyte', 1000);
if (\is_file(__DIR__ . '/test-image-ubyte')) {
\unlink(__DIR__ . '/test-image-ubyte');
\unlink(__DIR__ . '/test-label-ubyte');
}
BasicOcr::imagesToMNIST([__DIR__ . '/3.jpg'], __DIR__ . '/test-image-ubyte', 28);
BasicOcr::labelsToMNIST(['3'], __DIR__ . '/test-label-ubyte');
self::assertEquals(3, $ocr->matchImage(__DIR__ . '/test-image-ubyte', 3, 5)[0]['label']);
if (\is_file(__DIR__ . '/test-image-ubyte')) {
\unlink(__DIR__ . '/test-image-ubyte');
\unlink(__DIR__ . '/test-label-ubyte');
}
}
/**
* @covers phpOMS\Ai\Ocr\BasicOcr
* @group framework

View File

@ -18,6 +18,7 @@ use phpOMS\Ai\Ocr\Tesseract\TesseractOcr;
use phpOMS\Image\Kernel;
use phpOMS\Image\Skew;
use phpOMS\Image\Thresholding;
use phpOMS\System\File\PathException;
/**
* @internal
@ -67,6 +68,13 @@ final class TesseractOcrTest extends \PHPUnit\Framework\TestCase
self::assertGreaterThan(0.5, $m2);
}
public function testInvalidOcrPath() : void
{
$this->expectException(PathException::class);
$ocr = new TesseractOcr('/invalid/path');
}
/**
* @covers phpOMS\Ai\Ocr\Tesseract\TesseractOcr
* @group framework

View File

@ -35,4 +35,12 @@ final class EUVATBffOnlineTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $status['status']);
self::assertEquals('B', $status['vat']);
}
public function testValidateQualifiedInvalidId() : void
{
$status = EUVATBffOnline::validateQualified('DE123456789', 'DE123456789', 'TestName', 'TestStreet', 'TestCity', 'TestPostcode');
self::assertEquals(0, $status['status']);
self::assertEquals('B', $status['vat']);
}
}

View File

@ -35,4 +35,12 @@ final class EUVATViesTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $status['status']);
self::assertEquals('B', $status['vat']);
}
public function testValidateQualifiedInvalidId() : void
{
$status = EUVATVies::validateQualified('DE123456789', 'DE123456789', 'TestName', 'TestStreet', 'TestCity', 'TestPostcode');
self::assertEquals(0, $status['status']);
self::assertEquals('B', $status['vat']);
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\tests\Business\Finance;
use phpOMS\Business\Finance\Forensics;
/**
* @testdox phpOMS\tests\Business\Finance\ForensicsTest: Forensics formulas
*
* @internal
*/
final class ForensicsTest extends \PHPUnit\Framework\TestCase
{
public function testBenfordAnalysis() : void
{
$surface = [];
$fp = \fopen(__DIR__ . '/lakes.txt', 'r');
while (($line = \fgets($fp)) !== false) {
$surface[] = (int) $line;
}
$analysis = Forensics::benfordAnalysis($surface);
\ksort($analysis);
self::assertEqualsWithDelta(31.81, $analysis[1], 0.01);
self::assertEqualsWithDelta(20.55, $analysis[2], 0.01);
self::assertEqualsWithDelta(12.51, $analysis[3], 0.01);
self::assertEqualsWithDelta(9.29, $analysis[4], 0.01);
self::assertEqualsWithDelta(6.61, $analysis[5], 0.01);
self::assertEqualsWithDelta(6.17, $analysis[6], 0.01);
self::assertEqualsWithDelta(5.00, $analysis[7], 0.01);
self::assertEqualsWithDelta(4.47, $analysis[8], 0.01);
self::assertEqualsWithDelta(3.57, $analysis[9], 0.01);
}
public function testExpectedBenfordDistribution() : void
{
$dist = Forensics::expectedBenfordDistribution();
self::assertEqualsWithDelta(30.1, $dist[1], 0.01);
self::assertEqualsWithDelta(17.61, $dist[2], 0.01);
self::assertEqualsWithDelta(12.49, $dist[3], 0.01);
self::assertEqualsWithDelta(9.69, $dist[4], 0.01);
self::assertEqualsWithDelta(7.92, $dist[5], 0.01);
self::assertEqualsWithDelta(6.69, $dist[6], 0.01);
self::assertEqualsWithDelta(5.80, $dist[7], 0.01);
self::assertEqualsWithDelta(5.12, $dist[8], 0.01);
self::assertEqualsWithDelta(4.58, $dist[9], 0.01);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -298,6 +298,29 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
self::assertEquals($model3->string, \end($found)->string);
}
public function testFind2() : void
{
$model1 = clone $this->model;
$model2 = clone $this->model;
$model3 = clone $this->model;
$model1->string = 'abc';
$model2->string = 'abcdef';
$model3->string = 'zyx';
BaseModelMapper::create()->execute($model1);
BaseModelMapper::create()->execute($model2);
BaseModelMapper::create()->execute($model3);
$list = BaseModelMapper::find(
search: 'abc',
mapper: BaseModelMapper::getAll(),
searchFields: ['string']
);
self::assertEquals(2, \count($list));
}
/**
* @covers phpOMS\DataStorage\Database\Mapper\DataMapperAbstract
* @covers phpOMS\DataStorage\Database\Mapper\DataMapperFactory

View File

@ -117,8 +117,12 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
{
$con = new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin']);
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'SELECT `a`.`test` FROM `a` as b WHERE `a`.`test` = 1 ORDER BY \rand() LIMIT 1;';
$sql = 'SELECT [a].[test] FROM [a] as b WHERE [a].[test] = 1 ORDER BY \rand() LIMIT 1;';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql());
}
@ -126,8 +130,12 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
{
$con = new PostgresConnection($GLOBALS['CONFIG']['db']['core']['postgresql']['admin']);
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'SELECT "a"."test" FROM "a" as b ORDER BY RANDOM() LIMIT 1;';
$sql = 'SELECT [a].[test] FROM [a] as b ORDER BY RANDOM() LIMIT 1;';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql());
}
@ -135,8 +143,12 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
{
$con = new SQLiteConnection($GLOBALS['CONFIG']['db']['core']['sqlite']['admin']);
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'SELECT `a`.`test` FROM `a` as b ORDER BY RANDOM() LIMIT 1;';
$sql = 'SELECT [a].[test] FROM [a] as b ORDER BY RANDOM() LIMIT 1;';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql());
}
@ -144,8 +156,12 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
{
$con = new SqlServerConnection($GLOBALS['CONFIG']['db']['core']['mssql']['admin']);
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'SELECT TOP 1 [a].[test] FROM [a] as b ORDER BY IDX FETCH FIRST 1 ROWS ONLY;';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql());
}

View File

@ -15,6 +15,9 @@ declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Schema;
use phpOMS\DataStorage\Database\Connection\MysqlConnection;
use phpOMS\DataStorage\Database\Connection\PostgresConnection;
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
use phpOMS\DataStorage\Database\Connection\SqlServerConnection;
use phpOMS\DataStorage\Database\Schema\Builder;
/**
@ -24,68 +27,130 @@ use phpOMS\DataStorage\Database\Schema\Builder;
*/
final class BuilderTest extends \PHPUnit\Framework\TestCase
{
protected MysqlConnection $con;
/**
* {@inheritdoc}
*/
protected function setUp() : void
public function dbConnectionProvider() : array
{
$this->con = new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin']);
$cons = [
[new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin'])],
[new PostgresConnection($GLOBALS['CONFIG']['db']['core']['postgresql']['admin'])],
[new SQLiteConnection($GLOBALS['CONFIG']['db']['core']['sqlite']['admin'])],
[new SqlServerConnection($GLOBALS['CONFIG']['db']['core']['mssql']['admin'])],
];
$cons[0][0]->connect();
$cons[1][0]->connect();
$cons[2][0]->connect();
$cons[3][0]->connect();
return $cons;
}
/**
* @testdox Mysql database drop forms a valid query
* @group framework
* @dataProvider dbConnectionProvider
*/
public function testMysqlDrop() : void
public function testMysqlDrop($con) : void
{
$query = new Builder($this->con);
$sql = 'DROP DATABASE `test`;';
if (!$con->isInitialized()) {
self::markTestSkipped();
return;
}
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'DROP DATABASE [test];';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals($sql, $query->dropDatabase('test')->toSql());
}
/**
* @testdox Mysql table drop forms a valid query
* @group framework
* @dataProvider dbConnectionProvider
*/
public function testMysqlDropTable() : void
public function testMysqlDropTable($con) : void
{
$query = new Builder($this->con);
$sql = 'DROP TABLE `test`;';
if (!$con->isInitialized()) {
self::markTestSkipped();
return;
}
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'DROP TABLE [test];';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals($sql, $query->dropTable('test')->toSql());
}
/**
* @testdox Mysql show tables form a valid query
* @group framework
* @dataProvider dbConnectionProvider
*/
public function testMysqlShowTables() : void
public function testMysqlShowTables($con) : void
{
$query = new Builder($this->con);
$sql = 'SELECT `table_name` FROM `information_schema`.`tables` WHERE `table_schema` = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\';';
if (!$con->isInitialized()) {
self::markTestSkipped();
return;
}
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\';';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals($sql, $query->selectTables()->toSql());
}
/**
* @testdox Mysql show fields form a valid query
* @group framework
* @dataProvider dbConnectionProvider
*/
public function testMysqlShowFields() : void
public function testMysqlShowFields($con) : void
{
$query = new Builder($this->con);
$sql = 'SELECT * FROM `information_schema`.`columns` WHERE `table_schema` = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND `table_name` = \'test\';';
if (!$con->isInitialized()) {
self::markTestSkipped();
return;
}
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND table_name = \'test\';';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals($sql, $query->selectFields('test')->toSql());
}
/**
* @testdox Mysql create tables form a valid query
* @group framework
* @dataProvider dbConnectionProvider
*/
public function testMysqlCreateTable() : void
public function testMysqlCreateTable($con) : void
{
$query = new Builder($this->con);
$sql = 'CREATE TABLE IF NOT EXISTS `user_roles` (`user_id` INT AUTO_INCREMENT, `role_id` VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (`user_id`), FOREIGN KEY (`user_id`) REFERENCES `users` (`ext1_id`), FOREIGN KEY (`role_id`) REFERENCES `roles` (`ext2_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;';
if (!$con->isInitialized()) {
self::markTestSkipped();
return;
}
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'CREATE TABLE IF NOT EXISTS [user_roles] (user_id INT AUTO_INCREMENT, role_id VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (user_id), FOREIGN KEY (user_id) REFERENCES users (ext1_id), FOREIGN KEY (role_id) REFERENCES roles (ext2_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals(
$sql,
$query->createTable('user_roles')
@ -95,28 +160,51 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
);
}
public function testMysqlAlter() : void
{/*
$query = new Builder($this->con);
$sql = 'CREATE TABLE IF NOT EXISTS `user_roles` (`user_id` INT NOT NULL AUTO_INCREMENT, `role_id` VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (`user_id`), FOREIGN KEY (`user_id`) REFERENCES `users` (`ext1_id`), FOREIGN KEY (`role_id`) REFERENCES `roles` (`ext2_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;';
/*
public function testMysqlAlter($con) : void
{
if (!$con->isInitialized()) {
self::markTestSkipped();
return;
}
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'CREATE TABLE IF NOT EXISTS user_roles (user_id INT NOT NULL AUTO_INCREMENT, role_id VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (user_id), FOREIGN KEY (user_id) REFERENCES users (ext1_id), FOREIGN KEY (role_id) REFERENCES roles (ext2_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals(
$sql,
$query->createTable('user_roles')
->field('user_id', 'INT', null, false, true, false, true, 'users', 'ext1_id')
->field('role_id', 'VARCHAR(10)', '1', true, false, false, false, 'roles', 'ext2_id')
->toSql()
);*/
);
}
*/
/**
* @testdox The grammar correctly deletes a table
* @covers phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar<extended>
* @group framework
* @dataProvider dbConnectionProvider
*/
public function testMysqlCreateFromSchema() : void
public function testMysqlCreateFromSchema($con) : void
{
$query = new Builder($this->con);
$sql = 'DROP TABLE `test`, `test_foreign`;';
if (!$con->isInitialized()) {
self::markTestSkipped();
return;
}
$iS = $con->getGrammar()->systemIdentifierStart;
$iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con);
$sql = 'DROP TABLE [test], [test_foreign];';
$sql = \str_replace(['[', ']'], [$iS, $iE], $sql);
self::assertEquals(
$sql,

View File

@ -27,6 +27,7 @@ final class KernelTest extends \PHPUnit\Framework\TestCase
/**
* @testdox The kernel can be applied to an image which is then stored in a new file
* @group framework
* @group slow
* @covers phpOMS\Image\Kernel
*/
public function testKernel() : void
@ -34,9 +35,11 @@ final class KernelTest extends \PHPUnit\Framework\TestCase
Kernel::convolve(__DIR__ . '/img1.png', __DIR__ . '/test_img1_sharpen.png', Kernel::KERNEL_SHARPEN);
Kernel::convolve(__DIR__ . '/img1.png', __DIR__ . '/test_img1_blur.png', Kernel::KERNEL_GAUSSUAN_BLUR_3);
Kernel::convolve(__DIR__ . '/img1.png', __DIR__ . '/test_img1_emboss.png', Kernel::KERNEL_EMBOSS);
Kernel::convolve(__DIR__ . '/img1.png', __DIR__ . '/test_img1_unsharpen.png', Kernel::KERNEL_UNSHARP_MASKING);
self::assertTrue(\is_file(__DIR__ . '/test_img1_sharpen.png'));
self::assertTrue(\is_file(__DIR__ . '/test_img1_blur.png'));
self::assertTrue(\is_file(__DIR__ . '/test_img1_emboss.png'));
self::assertTrue(\is_file(__DIR__ . '/test_img1_unsharpen.png'));
}
}

View File

@ -27,21 +27,19 @@ final class SkewTest extends \PHPUnit\Framework\TestCase
/**
* @testdox A image can be automatically unskewed
* @group framework
* @group slow
* @covers phpOMS\Image\Skew
*/
public function testSkew() : void
{
/* Disabled because of very slow performance (244 seconds) */
self::markTestSkipped();
Skew::autoRotate(
__DIR__ . '/binary_tilted.png',
__DIR__ . '/test_binary_untilted.png',
__DIR__ . '/tilted.jpg',
__DIR__ . '/test_binary_untilted.jpg',
10,
[150, 75],
[1700, 900]
);
self::assertTrue(\is_file(__DIR__ . '/test_binary_untilted.png'));
self::assertTrue(\is_file(__DIR__ . '/test_binary_untilted.jpg'));
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

BIN
tests/Image/tilted.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

View File

@ -39,7 +39,6 @@ final class CountryTest extends \PHPUnit\Framework\TestCase
self::assertEquals('', $obj->getCode3());
self::assertEquals(0, $obj->getNumeric());
self::assertEquals('', $obj->getSubdevision());
self::assertEquals('', $obj->getRegion());
self::assertFalse($obj->isDeveloped());
}
}

View File

@ -54,4 +54,20 @@ final class ISO3166CharEnumTest extends \PHPUnit\Framework\TestCase
{
self::assertEquals(ISO3166CharEnum::getConstants(), \array_unique(ISO3166CharEnum::getConstants()));
}
public function testRegion() : void
{
$regions = [
'europe', 'asia', 'america', 'oceania', 'africa', 'eu', 'euro',
'north-europe', 'south-europe', 'east-europe', 'west-europe',
'middle-east', 'south-america', 'north-america', 'central-asia',
'south-asia', 'southeast-asia', 'east-asia', 'west-asia',
'central-africa', 'east-africa', 'north-africa', 'south-africa',
'west-africe', 'australia', 'polynesia', 'melanesia', 'antarctica',
];
foreach ($regions as $region) {
self::assertGreaterThan(0, \count(ISO3166CharEnum::getRegion($region)));
}
}
}

View File

@ -34,4 +34,20 @@ final class ISO3166NameEnumTest extends \PHPUnit\Framework\TestCase
$enum = ISO3166NameEnum::getConstants();
self::assertEquals(\count($enum), \count(\array_unique($enum)));
}
public function testRegion() : void
{
$regions = [
'europe', 'asia', 'america', 'oceania', 'africa', 'eu', 'euro',
'north-europe', 'south-europe', 'east-europe', 'west-europe',
'middle-east', 'south-america', 'north-america', 'central-asia',
'south-asia', 'southeast-asia', 'east-asia', 'west-asia',
'central-africa', 'east-africa', 'north-africa', 'south-africa',
'west-africe', 'australia', 'polynesia', 'melanesia', 'antarctica',
];
foreach ($regions as $region) {
self::assertGreaterThan(0, \count(ISO3166NameEnum::getRegion($region)));
}
}
}

View File

@ -44,4 +44,20 @@ final class ISO3166NumEnumTest extends \PHPUnit\Framework\TestCase
self::assertTrue($ok);
}
public function testRegion() : void
{
$regions = [
'europe', 'asia', 'america', 'oceania', 'africa', 'eu', 'euro',
'north-europe', 'south-europe', 'east-europe', 'west-europe',
'middle-east', 'south-america', 'north-america', 'central-asia',
'south-asia', 'southeast-asia', 'east-asia', 'west-asia',
'central-africa', 'east-africa', 'north-africa', 'south-africa',
'west-africe', 'australia', 'polynesia', 'melanesia', 'antarctica',
];
foreach ($regions as $region) {
self::assertGreaterThan(0, \count(ISO3166NumEnum::getRegion($region)));
}
}
}

View File

@ -54,4 +54,20 @@ final class ISO3166TwoEnumTest extends \PHPUnit\Framework\TestCase
{
self::assertEquals(ISO3166TwoEnum::getConstants(), \array_unique(ISO3166TwoEnum::getConstants()));
}
public function testRegion() : void
{
$regions = [
'europe', 'asia', 'america', 'oceania', 'africa', 'eu', 'euro',
'north-europe', 'south-europe', 'east-europe', 'west-europe',
'middle-east', 'south-america', 'north-america', 'central-asia',
'south-asia', 'southeast-asia', 'east-asia', 'west-asia',
'central-africa', 'east-africa', 'north-africa', 'south-africa',
'west-africe', 'australia', 'polynesia', 'melanesia', 'antarctica',
];
foreach ($regions as $region) {
self::assertGreaterThan(0, \count(ISO3166TwoEnum::getRegion($region)));
}
}
}

View File

@ -16,6 +16,7 @@ namespace phpOMS\tests\Localization;
require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639Enum;
/**
@ -34,4 +35,13 @@ final class ISO639EnumTest extends \PHPUnit\Framework\TestCase
$enum = ISO639Enum::getConstants();
self::assertEquals(\count($enum), \count(\array_unique($enum)));
}
public function testLanguage() : void
{
$enum = ISO3166TwoEnum::getConstants();
foreach ($enum as $code) {
self::assertGreaterThan(0, \count(ISO639Enum::languageFromCountry($code)), 'Failed for code: ' . $code);
}
}
}

View File

@ -16,6 +16,7 @@ namespace phpOMS\tests\Localization;
require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x1Enum;
/**
@ -54,4 +55,13 @@ final class ISO639x1EnumTest extends \PHPUnit\Framework\TestCase
{
self::assertEquals(ISO639x1Enum::getConstants(), \array_unique(ISO639x1Enum::getConstants()));
}
public function testLanguage() : void
{
$enum = ISO3166TwoEnum::getConstants();
foreach ($enum as $code) {
self::assertGreaterThan(0, \count(ISO639x1Enum::languageFromCountry($code)), 'Failed for code: ' . $code);
}
}
}

View File

@ -16,6 +16,7 @@ namespace phpOMS\tests\Localization;
require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x2Enum;
/**
@ -54,4 +55,13 @@ final class ISO639x2EnumTest extends \PHPUnit\Framework\TestCase
{
self::assertEquals(ISO639x2Enum::getConstants(), \array_unique(ISO639x2Enum::getConstants()));
}
public function testLanguage() : void
{
$enum = ISO3166TwoEnum::getConstants();
foreach ($enum as $code) {
self::assertGreaterThan(0, \count(ISO639x2Enum::languageFromCountry($code)), 'Failed for code: ' . $code);
}
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\tests\Localization\LanguageDetection;
require_once __DIR__ . '/../../Autoloader.php';
use phpOMS\Localization\LanguageDetection\Language;
/**
* @testdox phpOMS\tests\Localization\LanguageDetection\LanguageTest: Language detection
* @internal
*/
final class LanguageTest extends \PHPUnit\Framework\TestCase
{
public function testDetection() : void
{
$detector = new Language();
$files = \scandir(__DIR__ . '/languages');
foreach ($files as $file) {
if ($file === '.' || $file === '..') {
continue;
}
$language = \explode('.', $file)[0];
$content = \file_get_contents(__DIR__ . '/languages/' . $file);
$detected = $detector->detect($content)->bestResults()->close();
self::assertEquals($language, \array_keys($detected)[0] ?? '');
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -189,23 +189,11 @@ final class HttpHeaderTest extends \PHPUnit\Framework\TestCase
*/
public function testHeaderGeneration() : void
{
$this->header->generate(RequestStatusCode::R_403);
self::assertEquals(403, \http_response_code());
$this->header->generate(RequestStatusCode::R_404);
self::assertEquals(404, \http_response_code());
$this->header->generate(RequestStatusCode::R_406);
self::assertEquals(406, \http_response_code());
$this->header->generate(RequestStatusCode::R_407);
self::assertEquals(407, \http_response_code());
$this->header->generate(RequestStatusCode::R_503);
self::assertEquals(503, \http_response_code());
$this->header->generate(RequestStatusCode::R_500);
self::assertEquals(500, \http_response_code());
$consts = RequestStatusCode::getConstants();
foreach ($consts as $status) {
$this->header->generate($status);
self::assertTrue(\stripos($this->header->get('status')[0], (string) $status) !== false);
}
}
public function testGetAllHeaders() : void
@ -215,11 +203,11 @@ final class HttpHeaderTest extends \PHPUnit\Framework\TestCase
$tmp = $_SERVER;
$_SERVER = \json_decode($dummyHeaders, true);
self::assertEquals('127.0.0.1', $this->header->getAllHeaders()['Host']);
self::assertEquals('127.0.0.1', $this->header->getAllHeaders()['host'] ?? '');
// If headers are loaded once, only the cached version is used!
$_SERVER = \json_decode('{"HTTP_HOST": "invalid"}', true);
self::assertEquals('127.0.0.1', $this->header->getAllHeaders()['Host']);
self::assertEquals('127.0.0.1', $this->header->getAllHeaders()['host'] ?? '');
$_SERVER = $tmp;
}

View File

@ -0,0 +1,83 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\tests\Security;
require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Security\EncryptionHelper;
/**
* @testdox phpOMS\tests\Security\EncryptionHelperTest: Basic php source code security inspection
*
* @internal
*/
final class EncryptionHelperTest extends \PHPUnit\Framework\TestCase
{
public function testSharedKey() : void
{
$plain = 'This is a test message.';
$key = EncryptionHelper::createSharedKey();
$encrypted = EncryptionHelper::encryptShared($plain, $key);
self::assertNotEquals($plain, $encrypted);
self::assertEquals($plain, EncryptionHelper::decryptShared($encrypted, $key));
}
public function testPairedKey() : void
{
$plain = 'This is a test message.';
$keys = EncryptionHelper::createPairedKey();
$encrypted = EncryptionHelper::encryptSecret($plain, $keys['alicePrivate'], $keys['bobPublic']);
self::assertNotEquals($plain, $encrypted);
self::assertEquals($plain, EncryptionHelper::decryptSecret($encrypted, $keys['bobPrivate'], $keys['alicePublic']));
}
public function testFileEncryption() : void
{
if (\is_file(__DIR__ . '/encrytped.txt')) {
\unlink(__DIR__ . '/encrytped.txt');
}
if (\is_file(__DIR__ . '/decrypted.txt')) {
\unlink(__DIR__ . '/decrypted.txt');
}
$key = EncryptionHelper::createSharedKey();
self::assertTrue(EncryptionHelper::encryptFile(__DIR__ . '/plain.txt', __DIR__ . '/encrytped.txt', $key));
self::assertNotEquals(
\file_get_contents(__DIR__ . '/plain.txt'),
\file_get_contents(__DIR__ . '/encrytped.txt')
);
self::assertTrue( EncryptionHelper::decryptFile(__DIR__ . '/encrytped.txt', __DIR__ . '/decrypted.txt', $key));
self::assertEquals(
\file_get_contents(__DIR__ . '/plain.txt'),
\file_get_contents(__DIR__ . '/decrypted.txt')
);
if (\is_file(__DIR__ . '/encrytped.txt')) {
\unlink(__DIR__ . '/encrytped.txt');
}
if (\is_file(__DIR__ . '/decrypted.txt')) {
\unlink(__DIR__ . '/decrypted.txt');
}
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\tests\Security;
require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Security\Guard;
/**
* @testdox phpOMS\tests\Security\GuardTest: Basic php source code security inspection
*
* @internal
*/
final class GuardTest extends \PHPUnit\Framework\TestCase
{
public function testSafePath() : void
{
self::assertTrue(Guard::isSafePath(__DIR__));
self::assertFalse(Guard::isSafePath('/etc'));
}
public function testUnslash() : void
{
self::assertEquals(
[
'a' => "O'reilly",
'c' => [
'd' => 2,
'f' => [
'g' => "O'reilly",
],
],
],
Guard::unslash(
[
'a' => "O\'reilly",
'c' => [
'd' => 2,
'f' => [
'g' => "O\'reilly",
],
],
]
)
);
}
}

View File

View File

@ -0,0 +1 @@
ì ÎÅÅ'M”«ã§„F&A„ª“jŠ4ñÚ{,ðý<C3B0>ëe=¼uáÖQþ[G‰#HƒX

1
tests/Security/plain.txt Normal file
View File

@ -0,0 +1 @@
This is a test.

View File

@ -74,7 +74,16 @@ final class GraphTest extends \PHPUnit\Framework\TestCase
*/
public function testDirectedOutput() : void
{
self::assertFalse($this->graph->isDirected());
$node0 = new Node('0');
$node1 = new Node('1');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$node0->setNodeRelative($node1, isDirected: true);
$this->graph->isDirected = false;
self::assertTrue($this->graph->isDirected());
}
/**
@ -320,6 +329,8 @@ final class GraphTest extends \PHPUnit\Framework\TestCase
$this->graph->setNodeRelative($node2, $node3, true);
$this->graph->setNodeRelative($node1, $node3, true);
$this->graph->isDirected = true;
self::assertFalse($this->graph->hasCycle());
$node3->setNodeRelative($node1);
@ -592,6 +603,86 @@ final class GraphTest extends \PHPUnit\Framework\TestCase
self::assertCount(3, $path);
}
/**
* 1 - 3 - 5
* / |\ /
* 0 | \ /
* \ | \ /
* 2 4 6
*
* @covers phpOMS\Stdlib\Graph\Graph
* @group framework
*/
public function testShortestPathFloydWarshall() : void
{
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
$node3 = new Node('3');
$node4 = new Node('4');
$node5 = new Node('5');
$node6 = new Node('6');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$this->graph->setNode($node2);
$this->graph->setNode($node3);
$this->graph->setNode($node4);
$this->graph->setNode($node5);
$this->graph->setNode($node6);
$node0->setNodeRelative($node1);
$node0->setNodeRelative($node2);
$node1->setNodeRelative($node2);
$node1->setNodeRelative($node3);
$node1->setNodeRelative($node4);
$node3->setNodeRelative($node5);
$node4->setNodeRelative($node5);
$paths = $this->graph->getFloydWarshallShortestPath($node0, $node5);
self::assertGreaterThan(1, $paths);
}
/**
* 1 - 3 - 5
* / |\ /
* 0 | \ /
* \ | \ /
* 2 4 6
*
* @covers phpOMS\Stdlib\Graph\Graph
* @group framework
*/
public function testLongestPathsDfs() : void
{
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
$node3 = new Node('3');
$node4 = new Node('4');
$node5 = new Node('5');
$node6 = new Node('6');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$this->graph->setNode($node2);
$this->graph->setNode($node3);
$this->graph->setNode($node4);
$this->graph->setNode($node5);
$this->graph->setNode($node6);
$node0->setNodeRelative($node1);
$node0->setNodeRelative($node2);
$node1->setNodeRelative($node2);
$node1->setNodeRelative($node3);
$node1->setNodeRelative($node4);
$node3->setNodeRelative($node5);
$node4->setNodeRelative($node5);
$paths = $this->graph->longestPath($node0, $node5);
self::assertGreaterThan(1, $paths);
}
/**
* 1 - 3 - 5
* / |\ /
@ -680,8 +771,6 @@ final class GraphTest extends \PHPUnit\Framework\TestCase
*/
public function testDiameter() : void
{
self::markTestIncomplete();
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
@ -704,6 +793,213 @@ final class GraphTest extends \PHPUnit\Framework\TestCase
$node3->setNodeRelative($node5);
$node4->setNodeRelative($node5);
self::assertEquals(0, $this->graph->getDiameter());
self::assertGreaterThan(3, $this->graph->getDiameter());
}
/**
* 1 - 3 - 5
* / |\ /
* 0 | \ /
* \ | \ /
* 2 4
*
* @covers phpOMS\Stdlib\Graph\Graph
* @group framework
*/
public function testGirth() : void
{
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
$node3 = new Node('3');
$node4 = new Node('4');
$node5 = new Node('5');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$this->graph->setNode($node2);
$this->graph->setNode($node3);
$this->graph->setNode($node4);
$this->graph->setNode($node5);
$node0->setNodeRelative($node1);
$node0->setNodeRelative($node2);
$node1->setNodeRelative($node2);
$node1->setNodeRelative($node3);
$node1->setNodeRelative($node4);
$node3->setNodeRelative($node5);
$node4->setNodeRelative($node5);
self::assertGreaterThan(3, $this->graph->getGirth());
}
/**
* 1 - 3 - 5
* / |\ /
* 0 | \ /
* \ | \ /
* 2 4
*
* @covers phpOMS\Stdlib\Graph\Graph
* @group framework
*/
public function testCircuitRank() : void
{
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
$node3 = new Node('3');
$node4 = new Node('4');
$node5 = new Node('5');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$this->graph->setNode($node2);
$this->graph->setNode($node3);
$this->graph->setNode($node4);
$this->graph->setNode($node5);
$node0->setNodeRelative($node1);
$node0->setNodeRelative($node2);
$node1->setNodeRelative($node2);
$node1->setNodeRelative($node3);
$node1->setNodeRelative($node4);
$node3->setNodeRelative($node5);
$node4->setNodeRelative($node5);
self::assertGreaterThan(2, $this->graph->getCircuitRank());
}
/**
* 1 - 3 - 5
* / |\ /
* 0 | \ /
* \ | \ /
* 2 4
*
* @covers phpOMS\Stdlib\Graph\Graph
* @group framework
*/
public function testStronglyConnected() : void
{
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
$node3 = new Node('3');
$node4 = new Node('4');
$node5 = new Node('5');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$this->graph->setNode($node2);
$this->graph->setNode($node3);
$this->graph->setNode($node4);
$this->graph->setNode($node5);
$node0->setNodeRelative($node1);
$node0->setNodeRelative($node2);
$node1->setNodeRelative($node2);
$node1->setNodeRelative($node3);
$node1->setNodeRelative($node4);
$node3->setNodeRelative($node5);
$node4->setNodeRelative($node5);
self::assertTrue($this->graph->isStronglyConnected());
}
/**
* 0 - 1 - 2
*
* @covers phpOMS\Stdlib\Graph\Graph
* @group framework
*/
public function testInvalidStronglyConnected() : void
{
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$this->graph->setNode($node2);
$node0->setNodeRelative($node1);
$node1->setNodeRelative($node2);
self::assertFalse($this->graph->isStronglyConnected());
}
/**
* 1 - 3 - 5
* / |\ /
* 0 | \ /
* \ | \ /
* 2 4
*
* @covers phpOMS\Stdlib\Graph\Graph
* @group framework
*/
public function testBipartite() : void
{
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
$node3 = new Node('3');
$node4 = new Node('4');
$node5 = new Node('5');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$this->graph->setNode($node2);
$this->graph->setNode($node3);
$this->graph->setNode($node4);
$this->graph->setNode($node5);
$node0->setNodeRelative($node1);
$node0->setNodeRelative($node2);
$node1->setNodeRelative($node2);
$node1->setNodeRelative($node3);
$node1->setNodeRelative($node4);
$node3->setNodeRelative($node5);
$node4->setNodeRelative($node5);
self::assertTrue($this->graph->isBipartite());
}
/**
* 1 - 3 - 5
* / |\ /
* 0 | \ /
* \ | \ /
* 2 4
*
* @covers phpOMS\Stdlib\Graph\Graph
* @group framework
*/
public function testTriangles() : void
{
$node0 = new Node('0');
$node1 = new Node('1');
$node2 = new Node('2');
$node3 = new Node('3');
$node4 = new Node('4');
$node5 = new Node('5');
$this->graph->setNode($node0);
$this->graph->setNode($node1);
$this->graph->setNode($node2);
$this->graph->setNode($node3);
$this->graph->setNode($node4);
$this->graph->setNode($node5);
$node0->setNodeRelative($node1);
$node0->setNodeRelative($node2);
$node1->setNodeRelative($node2);
$node1->setNodeRelative($node3);
$node1->setNodeRelative($node4);
$node3->setNodeRelative($node5);
$node4->setNodeRelative($node5);
self::assertTrue($this->graph->hasTriangles());
}
}

View File

@ -242,8 +242,8 @@ final class ArrayUtilsTest extends \PHPUnit\Framework\TestCase
*/
public function testArgHas() : void
{
if (ArrayUtils::getArg('--configuration', $_SERVER['argv'] ?? null) !== null) {
self::assertGreaterThan(0, ArrayUtils::hasArg('--configuration', $_SERVER['argv'] ?? null));
if (ArrayUtils::getArg('--configuration', $_SERVER['argv'] ?? []) !== null) {
self::assertGreaterThan(0, ArrayUtils::hasArg('--configuration', $_SERVER['argv'] ?? []));
}
}
@ -254,7 +254,7 @@ final class ArrayUtilsTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidArgHas() : void
{
self::assertEquals(-1, ArrayUtils::hasArg('--testNull', $_SERVER['argv'] ?? null));
self::assertEquals(-1, ArrayUtils::hasArg('--testNull', $_SERVER['argv'] ?? []));
}
/**
@ -264,8 +264,8 @@ final class ArrayUtilsTest extends \PHPUnit\Framework\TestCase
*/
public function testArgGet() : void
{
if (ArrayUtils::getArg('--configuration', $_SERVER['argv'] ?? null) !== null) {
self::assertTrue(\stripos(ArrayUtils::getArg('--configuration', $_SERVER['argv'] ?? null), '.xml') !== false);
if (ArrayUtils::getArg('--configuration', $_SERVER['argv'] ?? []) !== null) {
self::assertTrue(\stripos(ArrayUtils::getArg('--configuration', $_SERVER['argv'] ?? []), '.xml') !== false);
}
}
@ -276,7 +276,7 @@ final class ArrayUtilsTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidArgGet() : void
{
self::assertNull(ArrayUtils::getArg('--testNull', $_SERVER['argv'] ?? null));
self::assertNull(ArrayUtils::getArg('--testNull', $_SERVER['argv'] ?? []));
}
/**

View File

@ -14,13 +14,53 @@ declare(strict_types=1);
namespace phpOMS\tests\Utils\Barcode;
use phpOMS\Utils\Barcode\Datamatrix;
/**
* @internal
*/
final class DatamatrixTest extends \PHPUnit\Framework\TestCase
{
public function testPlaceholder() : void
protected function setUp() : void
{
self::markTestIncomplete();
if (!\extension_loaded('gd')) {
$this->markTestSkipped(
'The GD extension is not available.'
);
}
}
/**
* @covers phpOMS\Utils\Barcode\Datamatrix<extended>
* @group framework
*/
public function testImagePng() : void
{
$path = __DIR__ . '/datamatrix.png';
if (\is_file($path)) {
\unlink($path);
}
$img = new Datamatrix('https://jingga.app', 200, 50);
$img->saveToPngFile($path);
self::assertFileExists($path);
}
/**
* @covers phpOMS\Utils\Barcode\Datamatrix<extended>
* @group framework
*/
public function testImageJpg() : void
{
$path = __DIR__ . '/datamatrix.jpg';
if (\is_file($path)) {
\unlink($path);
}
$img = new Datamatrix('https://jingga.app', 200, 50);
$img->saveToJpgFile($path);
self::assertFileExists($path);
}
}

View File

@ -14,13 +14,53 @@ declare(strict_types=1);
namespace phpOMS\tests\Utils\Barcode;
use phpOMS\Utils\Barcode\QR;
/**
* @internal
*/
final class QRTest extends \PHPUnit\Framework\TestCase
{
public function testPlaceholder() : void
protected function setUp() : void
{
self::markTestIncomplete();
if (!\extension_loaded('gd')) {
$this->markTestSkipped(
'The GD extension is not available.'
);
}
}
/**
* @covers phpOMS\Utils\Barcode\QR<extended>
* @group framework
*/
public function testImagePng() : void
{
$path = __DIR__ . '/qr.png';
if (\is_file($path)) {
\unlink($path);
}
$img = new QR('https://jingga.app', 200, 200);
$img->saveToPngFile($path);
self::assertFileExists($path);
}
/**
* @covers phpOMS\Utils\Barcode\QR<extended>
* @group framework
*/
public function testImageJpg() : void
{
$path = __DIR__ . '/qr.jpg';
if (\is_file($path)) {
\unlink($path);
}
$img = new QR('https://jingga.app', 200, 200);
$img->saveToJpgFile($path);
self::assertFileExists($path);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

BIN
tests/Utils/Barcode/qr.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
tests/Utils/Barcode/qr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

View File

@ -92,9 +92,7 @@ final class CurrencyTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidFromEur() : void
{
$this->expectException(\InvalidArgumentException::class);
Currency::fromEurTo(1, 'ERROR');
self::assertLessThan(0, Currency::fromEurTo(1, 'ERROR'));
}
/**
@ -104,9 +102,7 @@ final class CurrencyTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidToEur() : void
{
$this->expectException(\InvalidArgumentException::class);
Currency::fromToEur(1, 'ERROR');
self::assertLessThan(0, Currency::fromToEur(1, 'ERROR'));
}
/**
@ -116,8 +112,6 @@ final class CurrencyTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidConvert() : void
{
$this->expectException(\InvalidArgumentException::class);
Currency::convertCurrency(1, 'ERROR', 'TEST');
self::assertLessThan(0, Currency::convertCurrency(1, 'ERROR', 'TEST'));
}
}

View File

@ -25,6 +25,32 @@ use phpOMS\Utils\ImageUtils;
*/
final class ImageUtilsTest extends \PHPUnit\Framework\TestCase
{
public function testLightness() : void
{
self::assertEquals(0.0, ImageUtils::lightness(0));
self::assertEquals(1.0, ImageUtils::lightness(16777216));
}
public function testLightnessFromRgb() : void
{
self::assertEquals(0.0, ImageUtils::lightnessFromRgb(0, 0, 0));
self::assertEquals(1.0, ImageUtils::lightnessFromRgb(255, 255, 255));
}
public function testResize() : void
{
ImageUtils::resize(__DIR__ . '/logo.png', __DIR__ . '/logo_resized.png', 256, 256);
self::assertTrue(\is_file(__DIR__ . '/logo_resized.png'));
}
public function testDifference() : void
{
$diff = ImageUtils::difference(__DIR__ . '/img1.png', __DIR__ . '/img2.png', __DIR__ . '/diff1.png', 0);
$diff = ImageUtils::difference(__DIR__ . '/img1.png', __DIR__ . '/img2.png', __DIR__ . '/diff2.png', 1);
self::assertGreaterThan(0, $diff);
}
/**
* @testdox Base64 image data can be decoded to an image
* @covers phpOMS\Utils\ImageUtils

BIN
tests/Utils/diff1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
tests/Utils/diff2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 481 KiB

BIN
tests/Utils/img1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 KiB

BIN
tests/Utils/img2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -15,6 +15,7 @@
<directory>*Testapp*</directory>
<directory>./vendor</directory>
<directory>../vendor</directory>
<directory>../Localization/LanguageDetection/resources</directory>
</exclude>
</coverage>
<testsuites>
@ -32,6 +33,7 @@
<exclude>
<group>volume</group>
<group>maybe</group>
<group>slow</group>
</exclude>
</groups>
<php>