refactor(audit): remove factory chain and repository interfaces
Remove AuditRepositoryFactory and AuditServicesFactory — two-layer factory chain replaced by direct DI container wiring. Delete 4 single-consumer repository interfaces. Register all 4 repositories and SystemAuditRedactionService directly in container. Update all service constructors to type-hint concrete classes. Fix architecture test and documentation references to deleted factories. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,12 +12,15 @@ use MintyPHP\Module\Audit\Handler\SystemAuditPurgeJobHandler;
|
||||
use MintyPHP\Module\Audit\Handler\UserLifecycleAuditPurgeJobHandler;
|
||||
use MintyPHP\Module\Audit\Http\ApiSystemAuditReporter;
|
||||
use MintyPHP\Module\Audit\Providers\AuditLayoutProvider;
|
||||
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepository;
|
||||
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepository;
|
||||
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepository;
|
||||
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepository;
|
||||
use MintyPHP\Module\Audit\Service\ApiAuditService;
|
||||
use MintyPHP\Module\Audit\Service\AuditMetadataEnricher;
|
||||
use MintyPHP\Module\Audit\Service\AuditRepositoryFactory;
|
||||
use MintyPHP\Module\Audit\Service\AuditServicesFactory;
|
||||
use MintyPHP\Module\Audit\Service\FrontendTelemetryIngestService;
|
||||
use MintyPHP\Module\Audit\Service\ImportAuditService;
|
||||
use MintyPHP\Module\Audit\Service\SystemAuditRedactionService;
|
||||
use MintyPHP\Module\Audit\Service\SystemAuditService;
|
||||
use MintyPHP\Module\Audit\Service\UserLifecycleAuditService;
|
||||
use MintyPHP\Repository\User\UserReadRepository;
|
||||
@@ -27,30 +30,38 @@ use MintyPHP\Service\Audit\AuditRecorderInterface;
|
||||
use MintyPHP\Service\Audit\ImportAuditInterface;
|
||||
use MintyPHP\Service\Audit\UserLifecycleAuditInterface;
|
||||
use MintyPHP\Service\Security\RateLimiterService;
|
||||
use MintyPHP\Service\Settings\SettingServicesFactory;
|
||||
use MintyPHP\Service\Settings\SettingsFrontendTelemetryGateway;
|
||||
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
|
||||
|
||||
final class AuditContainerRegistrar implements ContainerRegistrar
|
||||
{
|
||||
public function register(AppContainer $container): void
|
||||
{
|
||||
// Repository factory
|
||||
$container->set(AuditRepositoryFactory::class, static fn (): AuditRepositoryFactory => new AuditRepositoryFactory());
|
||||
// Repositories
|
||||
$container->set(SystemAuditLogRepository::class, static fn (): SystemAuditLogRepository => new SystemAuditLogRepository());
|
||||
$container->set(ApiAuditLogRepository::class, static fn (): ApiAuditLogRepository => new ApiAuditLogRepository());
|
||||
$container->set(UserLifecycleAuditRepository::class, static fn (): UserLifecycleAuditRepository => new UserLifecycleAuditRepository());
|
||||
$container->set(ImportAuditRunRepository::class, static fn (): ImportAuditRunRepository => new ImportAuditRunRepository());
|
||||
|
||||
// Services factory
|
||||
$container->set(AuditServicesFactory::class, static fn (AppContainer $c): AuditServicesFactory => new AuditServicesFactory(
|
||||
$c->get(AuditRepositoryFactory::class),
|
||||
$c->get(SettingServicesFactory::class)->createSettingsSystemAuditGateway(),
|
||||
$c->get(RequestRuntimeInterface::class),
|
||||
$c->get(SessionStoreInterface::class)
|
||||
));
|
||||
// Redaction
|
||||
$container->set(SystemAuditRedactionService::class, static fn (): SystemAuditRedactionService => new SystemAuditRedactionService());
|
||||
|
||||
// Concrete audit services
|
||||
$container->set(SystemAuditService::class, static fn (AppContainer $c): SystemAuditService => $c->get(AuditServicesFactory::class)->createSystemAuditService());
|
||||
$container->set(ApiAuditService::class, static fn (AppContainer $c): ApiAuditService => $c->get(AuditServicesFactory::class)->createApiAuditService());
|
||||
$container->set(UserLifecycleAuditService::class, static fn (AppContainer $c): UserLifecycleAuditService => $c->get(AuditServicesFactory::class)->createUserLifecycleAuditService());
|
||||
$container->set(SystemAuditService::class, static fn (AppContainer $c): SystemAuditService => new SystemAuditService(
|
||||
$c->get(SystemAuditLogRepository::class),
|
||||
$c->get(SystemAuditRedactionService::class),
|
||||
$c->get(SettingsSystemAuditGateway::class),
|
||||
$c->get(SessionStoreInterface::class)
|
||||
));
|
||||
$container->set(ApiAuditService::class, static fn (AppContainer $c): ApiAuditService => new ApiAuditService(
|
||||
$c->get(ApiAuditLogRepository::class),
|
||||
$c->get(RequestRuntimeInterface::class)
|
||||
));
|
||||
$container->set(UserLifecycleAuditService::class, static fn (AppContainer $c): UserLifecycleAuditService => new UserLifecycleAuditService(
|
||||
$c->get(UserLifecycleAuditRepository::class)
|
||||
));
|
||||
$container->set(ImportAuditService::class, static fn (AppContainer $c): ImportAuditService => new ImportAuditService(
|
||||
$c->get(AuditRepositoryFactory::class)->createImportAuditRunRepository()
|
||||
$c->get(ImportAuditRunRepository::class)
|
||||
));
|
||||
|
||||
// Core interface bindings — override null implementations
|
||||
|
||||
@@ -7,7 +7,7 @@ use MintyPHP\Repository\Support\RepoQuery;
|
||||
use MintyPHP\Repository\Support\RepositoryArrayHelper;
|
||||
|
||||
/** Records API request/response audit entries with status codes, timing, and error details. */
|
||||
class ApiAuditLogRepository implements ApiAuditLogRepositoryInterface
|
||||
class ApiAuditLogRepository
|
||||
{
|
||||
private const FILTER_OPTIONS_LIMIT_MAX = 200;
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Audit\Repository;
|
||||
|
||||
/** Contract for API request audit log creation, pagination, and retention purge. */
|
||||
interface ApiAuditLogRepositoryInterface
|
||||
{
|
||||
public function create(array $data): int|false;
|
||||
|
||||
public function listPaged(array $filters): array;
|
||||
|
||||
public function listFilterOptions(int $limit = 200): array;
|
||||
|
||||
public function find(int $id): ?array;
|
||||
|
||||
public function purgeOlderThanDays(int $days): int;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use MintyPHP\Repository\Support\RepoQuery;
|
||||
use MintyPHP\Repository\Support\RepositoryArrayHelper;
|
||||
|
||||
/** Tracks CSV import runs including source file, row counts, status, and completion metadata. */
|
||||
class ImportAuditRunRepository implements ImportAuditRunRepositoryInterface
|
||||
class ImportAuditRunRepository
|
||||
{
|
||||
private const FILTER_OPTIONS_LIMIT_MAX = 200;
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Audit\Repository;
|
||||
|
||||
/** Contract for CSV import run audit trail creation, completion, and purge. */
|
||||
interface ImportAuditRunRepositoryInterface
|
||||
{
|
||||
public function createRunning(array $data): int|false;
|
||||
|
||||
public function finishById(int $id, array $data): bool;
|
||||
|
||||
public function listPaged(array $filters): array;
|
||||
|
||||
public function listFilterOptions(int $limit = 200): array;
|
||||
|
||||
public function find(int $id): ?array;
|
||||
|
||||
public function purgeOlderThanDays(int $days): int;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use MintyPHP\Repository\Support\RepoQuery;
|
||||
use MintyPHP\Repository\Support\RepositoryArrayHelper;
|
||||
|
||||
/** Persists system audit events with actor, target, outcome, channel, and hashed request metadata. */
|
||||
class SystemAuditLogRepository implements SystemAuditLogRepositoryInterface
|
||||
class SystemAuditLogRepository
|
||||
{
|
||||
private const FILTER_OPTIONS_LIMIT_MAX = 200;
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Audit\Repository;
|
||||
|
||||
/** Contract for system-wide security event logging with channel and outcome filtering. */
|
||||
interface SystemAuditLogRepositoryInterface
|
||||
{
|
||||
public function create(array $data): int|false;
|
||||
|
||||
public function listPaged(array $filters): array;
|
||||
|
||||
public function listFilterOptions(int $limit = 200): array;
|
||||
|
||||
public function find(int $id): ?array;
|
||||
|
||||
public function purgeOlderThanDays(int $days): int;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use MintyPHP\Repository\Support\RepoQuery;
|
||||
use MintyPHP\Repository\Support\RepositoryArrayHelper;
|
||||
|
||||
/** Records user lifecycle transitions (deactivation, deletion, restore) with reason codes and snapshots. */
|
||||
class UserLifecycleAuditRepository implements UserLifecycleAuditRepositoryInterface
|
||||
class UserLifecycleAuditRepository
|
||||
{
|
||||
private const FILTER_OPTIONS_LIMIT_MAX = 200;
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Audit\Repository;
|
||||
|
||||
/** Contract for tracking user deactivation/deletion lifecycle events and restore eligibility. */
|
||||
interface UserLifecycleAuditRepositoryInterface
|
||||
{
|
||||
public function create(array $row): int|false;
|
||||
|
||||
public function updateStatus(int $id, string $status, ?string $reasonCode = null): bool;
|
||||
|
||||
public function listPaged(array $filters): array;
|
||||
|
||||
public function listFilterOptions(int $limit = 200): array;
|
||||
|
||||
public function find(int $id): ?array;
|
||||
|
||||
public function findDeleteEventForRestore(int $id, bool $forUpdate = false): ?array;
|
||||
|
||||
public function markRestored(int $id, int $restoredBy, int $restoredUserId): bool;
|
||||
|
||||
public function purgeOlderThanDays(int $days): int;
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace MintyPHP\Module\Audit\Service;
|
||||
use MintyPHP\Http\ApiAuth;
|
||||
use MintyPHP\Http\RequestContext;
|
||||
use MintyPHP\Http\RequestRuntimeInterface;
|
||||
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepository;
|
||||
|
||||
class ApiAuditService
|
||||
{
|
||||
@@ -17,7 +17,7 @@ class ApiAuditService
|
||||
private ?array $context = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiAuditLogRepositoryInterface $apiAuditLogRepository,
|
||||
private readonly ApiAuditLogRepository $apiAuditLogRepository,
|
||||
private readonly RequestRuntimeInterface $requestRuntime
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Audit\Service;
|
||||
|
||||
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepository;
|
||||
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepository;
|
||||
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepository;
|
||||
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepository;
|
||||
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepositoryInterface;
|
||||
|
||||
class AuditRepositoryFactory
|
||||
{
|
||||
private ?ApiAuditLogRepository $apiAuditLogRepository = null;
|
||||
private ?ImportAuditRunRepository $importAuditRunRepository = null;
|
||||
private ?UserLifecycleAuditRepository $userLifecycleAuditRepository = null;
|
||||
private ?SystemAuditLogRepository $systemAuditLogRepository = null;
|
||||
|
||||
public function createApiAuditLogRepository(): ApiAuditLogRepositoryInterface
|
||||
{
|
||||
return $this->apiAuditLogRepository ??= new ApiAuditLogRepository();
|
||||
}
|
||||
|
||||
public function createUserLifecycleAuditRepository(): UserLifecycleAuditRepositoryInterface
|
||||
{
|
||||
return $this->userLifecycleAuditRepository ??= new UserLifecycleAuditRepository();
|
||||
}
|
||||
|
||||
public function createSystemAuditLogRepository(): SystemAuditLogRepositoryInterface
|
||||
{
|
||||
return $this->systemAuditLogRepository ??= new SystemAuditLogRepository();
|
||||
}
|
||||
|
||||
public function createImportAuditRunRepository(): ImportAuditRunRepositoryInterface
|
||||
{
|
||||
return $this->importAuditRunRepository ??= new ImportAuditRunRepository();
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Audit\Service;
|
||||
|
||||
use MintyPHP\Http\RequestRuntimeInterface;
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepositoryInterface;
|
||||
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
|
||||
|
||||
class AuditServicesFactory
|
||||
{
|
||||
private ?ApiAuditService $apiAuditService = null;
|
||||
private ?UserLifecycleAuditService $userLifecycleAuditService = null;
|
||||
private ?SystemAuditRedactionService $systemAuditRedactionService = null;
|
||||
private ?SystemAuditService $systemAuditService = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly AuditRepositoryFactory $auditRepositoryFactory,
|
||||
private readonly SettingsSystemAuditGateway $settingsSystemAuditGateway,
|
||||
private readonly RequestRuntimeInterface $requestRuntime,
|
||||
private readonly SessionStoreInterface $sessionStore
|
||||
) {
|
||||
}
|
||||
|
||||
public function createApiAuditLogRepository(): ApiAuditLogRepositoryInterface
|
||||
{
|
||||
return $this->auditRepositoryFactory->createApiAuditLogRepository();
|
||||
}
|
||||
|
||||
public function createUserLifecycleAuditRepository(): UserLifecycleAuditRepositoryInterface
|
||||
{
|
||||
return $this->auditRepositoryFactory->createUserLifecycleAuditRepository();
|
||||
}
|
||||
|
||||
public function createSystemAuditLogRepository(): SystemAuditLogRepositoryInterface
|
||||
{
|
||||
return $this->auditRepositoryFactory->createSystemAuditLogRepository();
|
||||
}
|
||||
|
||||
public function createApiAuditService(): ApiAuditService
|
||||
{
|
||||
return $this->apiAuditService ??= new ApiAuditService(
|
||||
$this->createApiAuditLogRepository(),
|
||||
$this->requestRuntime
|
||||
);
|
||||
}
|
||||
|
||||
public function createUserLifecycleAuditService(): UserLifecycleAuditService
|
||||
{
|
||||
return $this->userLifecycleAuditService ??= new UserLifecycleAuditService(
|
||||
$this->createUserLifecycleAuditRepository()
|
||||
);
|
||||
}
|
||||
|
||||
public function createSystemAuditRedactionService(): SystemAuditRedactionService
|
||||
{
|
||||
return $this->systemAuditRedactionService ??= new SystemAuditRedactionService();
|
||||
}
|
||||
|
||||
public function createSystemAuditService(): SystemAuditService
|
||||
{
|
||||
return $this->systemAuditService ??= new SystemAuditService(
|
||||
$this->createSystemAuditLogRepository(),
|
||||
$this->createSystemAuditRedactionService(),
|
||||
$this->settingsSystemAuditGateway,
|
||||
$this->sessionStore
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@ namespace MintyPHP\Module\Audit\Service;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
|
||||
use MintyPHP\Http\RequestContext;
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
|
||||
use MintyPHP\Service\Security\RateLimiterService;
|
||||
use MintyPHP\Service\Settings\SettingsFrontendTelemetryGateway;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace MintyPHP\Module\Audit\Service;
|
||||
|
||||
use MintyPHP\Module\Audit\Domain\ImportAuditStatus;
|
||||
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\ImportAuditRunRepository;
|
||||
use MintyPHP\Repository\Support\RepoQuery;
|
||||
use MintyPHP\Service\Audit\ImportAuditInterface;
|
||||
|
||||
@@ -16,7 +16,7 @@ class ImportAuditService implements ImportAuditInterface
|
||||
*/
|
||||
private array $startedAtByRunId = [];
|
||||
|
||||
public function __construct(private readonly ImportAuditRunRepositoryInterface $importAuditRunRepository)
|
||||
public function __construct(private readonly ImportAuditRunRepository $importAuditRunRepository)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace MintyPHP\Module\Audit\Service;
|
||||
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditChannel;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
|
||||
use MintyPHP\Http\ApiAuth;
|
||||
use MintyPHP\Http\RequestContext;
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditChannel;
|
||||
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
|
||||
use MintyPHP\Module\Audit\Repository\SystemAuditLogRepository;
|
||||
use MintyPHP\Repository\Support\RepoQuery;
|
||||
use MintyPHP\Service\Audit\AuditRecorderInterface;
|
||||
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
|
||||
@@ -19,7 +19,7 @@ class SystemAuditService implements AuditRecorderInterface
|
||||
private const RETENTION_DAYS_FALLBACK = 365;
|
||||
|
||||
public function __construct(
|
||||
private readonly SystemAuditLogRepositoryInterface $systemAuditLogRepository,
|
||||
private readonly SystemAuditLogRepository $systemAuditLogRepository,
|
||||
private readonly SystemAuditRedactionService $systemAuditRedactionService,
|
||||
private readonly SettingsSystemAuditGateway $settingsSystemAuditGateway,
|
||||
private readonly SessionStoreInterface $sessionStore
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace MintyPHP\Module\Audit\Service;
|
||||
use MintyPHP\Module\Audit\Domain\UserLifecycleAction;
|
||||
use MintyPHP\Module\Audit\Domain\UserLifecycleStatus;
|
||||
use MintyPHP\Module\Audit\Domain\UserLifecycleTriggerType;
|
||||
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepository;
|
||||
use MintyPHP\Service\Audit\UserLifecycleAuditInterface;
|
||||
use MintyPHP\Support\Crypto;
|
||||
|
||||
@@ -43,7 +43,7 @@ class UserLifecycleAuditService implements UserLifecycleAuditInterface
|
||||
'active_changed_at',
|
||||
];
|
||||
|
||||
public function __construct(private readonly UserLifecycleAuditRepositoryInterface $userLifecycleAuditRepository)
|
||||
public function __construct(private readonly UserLifecycleAuditRepository $userLifecycleAuditRepository)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
use MintyPHP\Http\RequestContext;
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Module\Audit\Service\FrontendTelemetryIngestService;
|
||||
use MintyPHP\Router;
|
||||
use MintyPHP\Session;
|
||||
|
||||
if ((requestInput()->method()) !== 'POST') {
|
||||
|
||||
@@ -4,7 +4,6 @@ use MintyPHP\Buffer;
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Module\Audit\AuditAuthorizationPolicy;
|
||||
use MintyPHP\Module\Audit\Service\SystemAuditService;
|
||||
use MintyPHP\Service\Access\SettingsAuthorizationPolicy;
|
||||
use MintyPHP\Service\Access\UiAccessService;
|
||||
use MintyPHP\Support\Guard;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace MintyPHP\Tests\Module\Audit\Service;
|
||||
|
||||
use MintyPHP\Http\RequestContext;
|
||||
use MintyPHP\Http\RequestRuntime;
|
||||
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\ApiAuditLogRepository;
|
||||
use MintyPHP\Module\Audit\Service\ApiAuditService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -30,7 +30,7 @@ class ApiAuditServiceTest extends TestCase
|
||||
public function testCurrentRequestIdIsNullBeforeStart(): void
|
||||
{
|
||||
$service = new ApiAuditService(
|
||||
$this->createMock(ApiAuditLogRepositoryInterface::class),
|
||||
$this->createMock(ApiAuditLogRepository::class),
|
||||
new RequestRuntime()
|
||||
);
|
||||
$this->assertNull($service->currentRequestId());
|
||||
@@ -43,7 +43,7 @@ class ApiAuditServiceTest extends TestCase
|
||||
$_GET = ['x' => '1'];
|
||||
|
||||
$service = new ApiAuditService(
|
||||
$this->createMock(ApiAuditLogRepositoryInterface::class),
|
||||
$this->createMock(ApiAuditLogRepository::class),
|
||||
new RequestRuntime()
|
||||
);
|
||||
$service->startRequestContext();
|
||||
@@ -66,7 +66,7 @@ class ApiAuditServiceTest extends TestCase
|
||||
$_GET = [];
|
||||
|
||||
$service = new ApiAuditService(
|
||||
$this->createMock(ApiAuditLogRepositoryInterface::class),
|
||||
$this->createMock(ApiAuditLogRepository::class),
|
||||
new RequestRuntime()
|
||||
);
|
||||
$service->startRequestContext();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace MintyPHP\Tests\Module\Audit\Service;
|
||||
|
||||
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepositoryInterface;
|
||||
use MintyPHP\Module\Audit\Repository\UserLifecycleAuditRepository;
|
||||
use MintyPHP\Module\Audit\Service\UserLifecycleAuditService;
|
||||
use MintyPHP\Support\Crypto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -52,7 +52,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testLogDeactivateCallsRepoCreateWithCorrectRow(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row): bool {
|
||||
@@ -87,7 +87,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testLogDeactivateReturnsFalseOnRepoException(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->method('create')->willThrowException(new \RuntimeException('db error'));
|
||||
|
||||
$service = new UserLifecycleAuditService($repo);
|
||||
@@ -98,7 +98,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testLogDeactivateReturnsFalseWhenRepoReturnsFalse(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->method('create')->willReturn(false);
|
||||
|
||||
$service = new UserLifecycleAuditService($repo);
|
||||
@@ -122,7 +122,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
$targetUser['id'] = 5;
|
||||
$targetUser['extra_field'] = 'should_be_excluded';
|
||||
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row): bool {
|
||||
@@ -149,7 +149,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
$targetUser = ['id' => 5, 'uuid' => 'u5', 'email' => 'e@example.com', 'extra' => 'no'];
|
||||
|
||||
$capturedRow = null;
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row) use (&$capturedRow): bool {
|
||||
@@ -176,7 +176,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
// cause the try/catch to fire. We cannot easily override static Crypto, but we
|
||||
// know that if APP_CRYPTO_KEY were missing, encryptString would throw.
|
||||
// Since we defined a valid key, let's test the repo exception path instead.
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->method('create')->willThrowException(new \RuntimeException('db error'));
|
||||
|
||||
$service = new UserLifecycleAuditService($repo);
|
||||
@@ -189,7 +189,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testLogRestoreCallsRepoWithRestoreAction(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row): bool {
|
||||
@@ -207,7 +207,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testLogRestoreReturnsFalseOnException(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->method('create')->willThrowException(new \RuntimeException('fail'));
|
||||
|
||||
$service = new UserLifecycleAuditService($repo);
|
||||
@@ -227,7 +227,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
$original = ['uuid' => 'test-uuid', 'email' => 'test@example.com'];
|
||||
$encrypted = Crypto::encryptString(json_encode($original));
|
||||
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$service = new UserLifecycleAuditService($repo);
|
||||
|
||||
$result = $service->decryptSnapshot(['snapshot_enc' => $encrypted]);
|
||||
@@ -236,7 +236,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testDecryptSnapshotReturnsNullForEmptyPayload(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$service = new UserLifecycleAuditService($repo);
|
||||
|
||||
$this->assertNull($service->decryptSnapshot([]));
|
||||
@@ -246,7 +246,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testDecryptSnapshotReturnsNullForInvalidPayload(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$service = new UserLifecycleAuditService($repo);
|
||||
|
||||
$result = $service->decryptSnapshot(['snapshot_enc' => 'not-valid-encrypted-data']);
|
||||
@@ -257,7 +257,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testMarkDeleteEventRestoredDelegatesToRepo(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('markRestored')
|
||||
->with(1, 99, 200)
|
||||
@@ -269,7 +269,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testMarkDeleteEventRestoredReturnsFalseOnException(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->method('markRestored')->willThrowException(new \RuntimeException('fail'));
|
||||
|
||||
$service = new UserLifecycleAuditService($repo);
|
||||
@@ -280,7 +280,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testPurgeExpiredDelegatesToRepoWith365Days(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('purgeOlderThanDays')
|
||||
->with(365)
|
||||
@@ -294,7 +294,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testBuildBaseRowNormalizesInvalidTriggerTypeToDefault(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row): bool {
|
||||
@@ -308,7 +308,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testBuildBaseRowNormalizesInvalidStatusToFailed(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row): bool {
|
||||
@@ -322,7 +322,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testBuildBaseRowNormalizesNullActorToNull(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row): bool {
|
||||
@@ -336,7 +336,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testBuildBaseRowNormalizesZeroActorToNull(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row): bool {
|
||||
@@ -350,7 +350,7 @@ class UserLifecycleAuditServiceTest extends TestCase
|
||||
|
||||
public function testBuildBaseRowSetsNegativePolicyDaysToZero(): void
|
||||
{
|
||||
$repo = $this->createMock(UserLifecycleAuditRepositoryInterface::class);
|
||||
$repo = $this->createMock(UserLifecycleAuditRepository::class);
|
||||
$repo->expects($this->once())
|
||||
->method('create')
|
||||
->with($this->callback(static function (array $row): bool {
|
||||
|
||||
Reference in New Issue
Block a user