fix tests

This commit is contained in:
Dennis Eichhorn 2023-09-21 14:44:14 +00:00
parent cd00e471b9
commit d5b0b73f2a
2 changed files with 29 additions and 8 deletions

View File

@ -105,6 +105,14 @@ abstract class ModuleAbstract
*/
public bool $active = true;
/**
* Auditor for logging.
*
* @var null|ModuleAbstract
* @since 1.0.0
*/
public static ?ModuleAbstract $auditor = null;
/**
* Constructor.
*
@ -115,6 +123,11 @@ abstract class ModuleAbstract
public function __construct(ApplicationAbstract $app = null)
{
$this->app = $app ?? new class() extends ApplicationAbstract {};
if (self::$auditor === null && static::ID !== 1006200000) {
self::$auditor = $this->app?->moduleManager->get('Auditor', 'Api');
self::$auditor = static::$auditor::ID === 0 ? null : self::$auditor;
}
}
/**
@ -732,7 +745,8 @@ abstract class ModuleAbstract
$ip,
];
$this->app->moduleManager->get('Auditor', 'Api')->eventLogCreate(...$data);
/** @phpstan-ignore-next-line */
self::$auditor?->eventLogCreate(...$data);
$this->app->eventManager->triggerSimilar('POST:Module:' . $trigger, '', $data);
}
@ -777,7 +791,8 @@ abstract class ModuleAbstract
$ip,
];
$this->app->moduleManager->get('Auditor', 'Api')->eventLogCreate(...$data);
/** @phpstan-ignore-next-line */
self::$auditor?->eventLogCreate(...$data);
$this->app->eventManager->triggerSimilar('POST:Module:' . $trigger, '', $data);
}
}
@ -823,7 +838,8 @@ abstract class ModuleAbstract
$ip,
];
$this->app->moduleManager->get('Auditor', 'Api')->eventLogUpdate(...$data);
/** @phpstan-ignore-next-line */
self::$auditor?->eventLogUpdate(...$data);
$this->app->eventManager->triggerSimilar('POST:Module:' . $trigger, '', $data);
}
@ -867,7 +883,8 @@ abstract class ModuleAbstract
$ip,
];
$this->app->moduleManager->get('Auditor', 'Api')->eventLogDelete(...$data);
/** @phpstan-ignore-next-line */
self::$auditor?->eventLogDelete(...$data);
$this->app->eventManager->triggerSimilar('POST:Module:' . $trigger, '', $data);
}
@ -915,7 +932,8 @@ abstract class ModuleAbstract
$ip,
];
$this->app->moduleManager->get('Auditor', 'Api')->eventLogRelationCreate(...$data);
/** @phpstan-ignore-next-line */
self::$auditor?->eventLogRelationCreate(...$data);
$this->app->eventManager->triggerSimilar('POST:Module:' . $trigger, '', $data);
}
@ -955,7 +973,8 @@ abstract class ModuleAbstract
$ip,
];
$this->app->moduleManager->get('Auditor', 'Api')->eventLogRelationDelete(...$data);
/** @phpstan-ignore-next-line */
self::$auditor?->eventLogRelationDelete(...$data);
$this->app->eventManager->triggerSimilar('POST:Module:' . $trigger, '', $data);
}
}

View File

@ -21,6 +21,7 @@ use phpOMS\Event\EventManager;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Module\ModuleAbstract;
use phpOMS\Module\ModuleManager;
use phpOMS\tests\DataStorage\Database\TestModel\BaseModel;
use phpOMS\tests\DataStorage\Database\TestModel\BaseModelMapper;
use phpOMS\tests\DataStorage\Database\TestModel\ManyToManyRelModel;
@ -55,8 +56,9 @@ final class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
public function __construct()
{
$this->app = new class() extends ApplicationAbstract {};
$this->app->eventManager = new EventManager();
$this->app = new class() extends ApplicationAbstract {};
$this->app->eventManager = new EventManager();
$this->app->moduleManager = new ModuleManager($this->app, __DIR__);
}
public function fillJson(HttpRequest $request, HttpResponse $response, string $status, string $title, string $message, array $data) : void