phpcs, static and unit test fixes

This commit is contained in:
Dennis Eichhorn 2021-10-03 09:16:47 +02:00
parent d209c16831
commit 0d63731697
13 changed files with 104 additions and 32 deletions

View File

@ -160,8 +160,6 @@ final class ApplicationManager
*
* @return void
*
* @throws InvalidModuleException Throws this exception in case the installer doesn't exist
*
* @since 1.0.0
*/
public function reInit(string $appPath) : void
@ -216,7 +214,7 @@ final class ApplicationManager
* @param bool $useCache Use Cache
* @param string $basePath Base path for the applications
*
* @return array<string, ModuleInfo>
* @return array<string, ApplicationInfo>
*
* @since 1.0.0
*/

View File

@ -29,6 +29,12 @@ use phpOMS\System\File\Local\Directory;
*/
abstract class InstallerAbstract
{
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = '';
/**

View File

@ -31,6 +31,12 @@ use phpOMS\Utils\Parser\Php\ArrayParser;
*/
abstract class StatusAbstract
{
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = '';
/**

View File

@ -28,6 +28,14 @@ use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder;
*/
abstract class UninstallerAbstract
{
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = '';
/**
* Install module.
*

View File

@ -29,6 +29,14 @@ use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder;
*/
abstract class InstallerAbstract
{
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = '';
/**
* Install module.
*
@ -58,7 +66,7 @@ abstract class InstallerAbstract
*/
protected static function createTables(DatabasePool $dbPool, ModuleInfo $info) : void
{
$path = \dirname($info->getPath()) . '/Admin/Install/db.json';
$path = static::PATH . '/Install/db.json';
if (!\is_file($path)) {
return;
}
@ -86,8 +94,10 @@ abstract class InstallerAbstract
*/
protected static function activate(DatabasePool $dbPool, ModuleInfo $info) : void
{
/** @var StatusAbstract $class */
$class = '\Modules\\' . $info->getDirectory() . '\Admin\Status';
$classPath = \substr(\realpath(static::PATH) . '/Status', \strlen(\realpath(__DIR__ . '/../../')));
/** @var StatusAbstract $class */
$class = \str_replace('/', '\\', $classPath);
$class::activate($dbPool, $info);
}
@ -103,7 +113,10 @@ abstract class InstallerAbstract
*/
public static function reInit(ModuleInfo $info, ApplicationInfo $appInfo = null) : void
{
$class = '\Modules\\' . $info->getDirectory() . '\Admin\Status';
$classPath = \substr(\realpath(static::PATH) . '/Status', \strlen(\realpath(__DIR__ . '/../../')));
/** @var StatusAbstract $class */
$class = \str_replace('/', '\\', $classPath);
$class::activateRoutes($info, $appInfo);
$class::activateHooks($info, $appInfo);
}

View File

@ -35,6 +35,14 @@ use phpOMS\Utils\Parser\Php\ArrayParser;
*/
abstract class StatusAbstract
{
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = '';
/**
* Deactivate module.
*
@ -65,7 +73,7 @@ abstract class StatusAbstract
*/
public static function activateRoutes(ModuleInfo $info, ApplicationInfo $appInfo = null) : void
{
$directories = new Directory(\dirname($info->getPath()) . '/Admin/Routes');
$directories = new Directory(static::PATH . '/Routes');
/** @var Directory|File $child */
foreach ($directories as $child) {
@ -145,7 +153,7 @@ abstract class StatusAbstract
*/
public static function activateHooks(ModuleInfo $info, ApplicationInfo $appInfo = null) : void
{
$directories = new Directory(\dirname($info->getPath()) . '/Admin/Hooks');
$directories = new Directory(static::PATH . '/Hooks');
/** @var Directory|File $child */
foreach ($directories as $child) {
@ -199,7 +207,7 @@ abstract class StatusAbstract
*/
public static function deactivateRoutes(ModuleInfo $info, ApplicationInfo $appInfo = null) : void
{
$directories = new Directory(\dirname($info->getPath()) . '/Admin/Routes');
$directories = new Directory(static::PATH . '/Routes');
/** @var Directory|File $child */
foreach ($directories as $child) {
@ -275,7 +283,7 @@ abstract class StatusAbstract
*/
public static function deactivateHooks(ModuleInfo $info, ApplicationInfo $appInfo = null) : void
{
$directories = new Directory(\dirname($info->getPath()) . '/Admin/Hooks');
$directories = new Directory(static::PATH . '/Hooks');
/** @var Directory|File $child */
foreach ($directories as $child) {

View File

@ -28,6 +28,14 @@ use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder;
*/
abstract class UninstallerAbstract
{
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = '';
/**
* Install module.
*
@ -58,7 +66,10 @@ abstract class UninstallerAbstract
protected static function deactivate(DatabasePool $dbPool, ModuleInfo $info) : void
{
/** @var StatusAbstract $class */
$class = '\Modules\\' . $info->getDirectory() . '\Admin\Status';
$classPath = \substr(\realpath(static::PATH) . '/Status', \strlen(\realpath(__DIR__ . '/../../')));
/** @var StatusAbstract $class */
$class = \str_replace('/', '\\', $classPath);
$class::deactivate($dbPool, $info);
}
@ -74,8 +85,7 @@ abstract class UninstallerAbstract
*/
public static function dropTables(DatabasePool $dbPool, ModuleInfo $info) : void
{
$path = \dirname($info->getPath()) . '/Admin/Install/db.json';
$path = static::PATH . '/Install/db.json';
if (!\is_file($path)) {
return;
}

View File

@ -555,13 +555,13 @@ class Graph
$cNode = \array_pop($stack);
$nodes[] = $cNode;
if (!isset($visited[$cNode->getId()]) || !$visited[$cNode->getId()]) {
if (!isset($visited[$cNode->getId()]) || $visited[$cNode->getId()] === false) {
$visited[$cNode->getId()] = true;
}
$neighbors = $cNode->getNeighbors();
foreach ($neighbors as $neighbor) {
if (!isset($visited[$cNode->getId()]) || !$visited[$cNode->getId()]) {
if (!isset($visited[$cNode->getId()]) || $visited[$cNode->getId()] === false) {
$stack[] = $neighbor;
}
}

View File

@ -26,5 +26,11 @@ use phpOMS\Application\InstallerAbstract;
*/
final class Installer extends InstallerAbstract
{
public const PATH = __DIR__;
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = __DIR__;
}

View File

@ -24,7 +24,13 @@ use phpOMS\Application\UninstallerAbstract;
* @link https://orange-management.org
* @since 1.0.0
*/
final class Uninstaller extends UninstallerAbstract
final class Installer extends InstallerAbstract
{
public const PATH = __DIR__;
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = __DIR__;
}

View File

@ -150,7 +150,11 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase
{
$this->cache->set('key1', 'testVal1');
$this->cache->set('key2', 'testVal2');
self::assertEquals(['testVal1', 'testVal2'], $this->cache->getLike('key\d'));
$result = $this->cache->getLike('key\d');
self::assertEquals(2, \count($result));
self::assertTrue(\in_array('testVal1', $result))
self::assertTrue(\in_array('testVal2', $result))
}
public function testExpiredGetLike() : void

View File

@ -41,12 +41,12 @@ class MailHandlerTest extends \PHPUnit\Framework\TestCase
public function testSendTextWithMail() : void
{
if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) {
$this->handler->setMailer(SubmitType::MAIL);
if (!\file_exists($this->handler->mailerTool)) {
self::markTestSkipped();
}
$this->handler->setMailer(SubmitType::MAIL);
$mail = new Email();
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
@ -62,12 +62,12 @@ class MailHandlerTest extends \PHPUnit\Framework\TestCase
public function testSendTextWithSendmail() : void
{
if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) {
$this->handler->setMailer(SubmitType::SENDMAIL);
if (!\file_exists($this->handler->mailerTool)) {
self::markTestSkipped();
}
$this->handler->setMailer(SubmitType::SENDMAIL);
$mail = new Email();
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
@ -83,12 +83,12 @@ class MailHandlerTest extends \PHPUnit\Framework\TestCase
public function testSendHtmlWithMail() : void
{
if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) {
$this->handler->setMailer(SubmitType::MAIL);
if (!\file_exists($this->handler->mailerTool)) {
self::markTestSkipped();
}
$this->handler->setMailer(SubmitType::MAIL);
$mail = new Email();
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
@ -109,12 +109,12 @@ class MailHandlerTest extends \PHPUnit\Framework\TestCase
public function testSendHtmlWithSendmail() : void
{
if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) {
$this->handler->setMailer(SubmitType::SENDMAIL);
if (!\file_exists($this->handler->mailerTool)) {
self::markTestSkipped();
}
$this->handler->setMailer(SubmitType::SENDMAIL);
$mail = new Email();
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');

View File

@ -26,4 +26,11 @@ use phpOMS\Module\InstallerAbstract;
*/
final class Installer extends InstallerAbstract
{
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = __DIR__;
}