From d5b0b73f2a7e5e1e4f5da61473d35242a9b2c796 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 21 Sep 2023 14:44:14 +0000 Subject: [PATCH] fix tests --- Module/ModuleAbstract.php | 31 +++++++++++++++++++++++------ tests/Module/ModuleAbstractTest.php | 6 ++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 3a7a7e40f..61e189d73 100755 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -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); } } diff --git a/tests/Module/ModuleAbstractTest.php b/tests/Module/ModuleAbstractTest.php index 1d0841f56..ff14928a7 100755 --- a/tests/Module/ModuleAbstractTest.php +++ b/tests/Module/ModuleAbstractTest.php @@ -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