Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Eichhorn committed Sep 21, 2023
1 parent cd00e47 commit d5b0b73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
31 changes: 25 additions & 6 deletions Module/ModuleAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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');

Check failure on line 128 in Module/ModuleAbstract.php

View workflow job for this annotation

GitHub Actions / static-tests (8.1)

Using nullsafe property access on non-nullable type phpOMS\Application\ApplicationAbstract. Use -> instead.
self::$auditor = static::$auditor::ID === 0 ? null : self::$auditor;

Check failure on line 129 in Module/ModuleAbstract.php

View workflow job for this annotation

GitHub Actions / static-tests (8.1)

Cannot access constant ID on phpOMS\Module\ModuleAbstract|null.
}
}

/**
Expand Down Expand Up @@ -732,7 +745,8 @@ protected function createModel(int $account, mixed $obj, string | \Closure $mapp
$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);
}

Expand Down Expand Up @@ -777,7 +791,8 @@ protected function createModels(int $account, array $objs, string | \Closure $ma
$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);
}
}
Expand Down Expand Up @@ -823,7 +838,8 @@ protected function updateModel(int $account, mixed $old, mixed $new, string | \C
$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);
}

Expand Down Expand Up @@ -867,7 +883,8 @@ protected function deleteModel(int $account, mixed $obj, string | \Closure $mapp
$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);
}

Expand Down Expand Up @@ -915,7 +932,8 @@ protected function createModelRelation(
$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);
}

Expand Down Expand Up @@ -955,7 +973,8 @@ protected function deleteModelRelation(int $account, mixed $rel1, mixed $rel2, s
$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);
}
}
6 changes: 4 additions & 2 deletions tests/Module/ModuleAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -55,8 +56,9 @@ protected function setUp() : void

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
Expand Down

0 comments on commit d5b0b73

Please sign in to comment.