2026-03-04 15:56:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Tests\Domain\Taxonomy;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\Domain\Taxonomy\MailLogStatus;
|
|
|
|
|
use MintyPHP\Domain\Taxonomy\ScheduledJobRunStatus;
|
|
|
|
|
use MintyPHP\Domain\Taxonomy\ScheduledJobStatus;
|
|
|
|
|
use MintyPHP\Domain\Taxonomy\ScheduledJobTriggerType;
|
|
|
|
|
use MintyPHP\Domain\Taxonomy\SchedulerRuntimeResult;
|
|
|
|
|
use MintyPHP\Domain\Taxonomy\TenantStatus;
|
refactor(audit): extract audit domain into self-contained module
Move the entire audit subsystem (system audit, API audit, import audit,
user lifecycle audit, frontend telemetry) from core into modules/audit/.
Core decoupling via interface-based injection:
- AuditRecorderInterface replaces SystemAuditService in 10+ core services
- UserLifecycleAuditInterface / ImportAuditInterface for specialized flows
- NullAuditRecorder fallback when audit module is disabled
- ApiBootstrap/ApiResponse use null-safe callable resolvers
Module structure (modules/audit/):
- Manifest with routes, permissions, scheduler jobs, authorization policy
- 9 services, 8 repositories, 6 domain enums, 4 job handlers
- 33 page files, 4 JS files, 8 test files, migration scripts, i18n
Core cleanup:
- OperationsAuthorizationPolicy, UiCapabilityMap, PermissionService
surgically cleaned of audit-specific constants
- Sidebar template cleared of hardcoded audit navigation
- AuditModuleIsolationContractTest ensures no future core→module coupling
All quality gates pass: 1346 tests (19,276 assertions), PHPStan level 5
clean, architecture contracts verified.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 21:12:49 +01:00
|
|
|
use MintyPHP\Module\Audit\Domain\ImportAuditStatus;
|
|
|
|
|
use MintyPHP\Module\Audit\Domain\SystemAuditChannel;
|
|
|
|
|
use MintyPHP\Module\Audit\Domain\SystemAuditOutcome;
|
|
|
|
|
use MintyPHP\Module\Audit\Domain\UserLifecycleAction;
|
|
|
|
|
use MintyPHP\Module\Audit\Domain\UserLifecycleStatus;
|
|
|
|
|
use MintyPHP\Module\Audit\Domain\UserLifecycleTriggerType;
|
2026-03-04 15:56:58 +01:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
class TaxonomyEnumContractTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @return iterable<string, array{0: class-string<\BackedEnum>, 1: list<string>}>
|
|
|
|
|
*/
|
|
|
|
|
public static function enumProvider(): iterable
|
|
|
|
|
{
|
|
|
|
|
yield 'SystemAuditOutcome' => [SystemAuditOutcome::class, ['success', 'failed', 'denied']];
|
|
|
|
|
yield 'SystemAuditChannel' => [SystemAuditChannel::class, ['web', 'api', 'scheduler', 'cli']];
|
|
|
|
|
yield 'UserLifecycleAction' => [UserLifecycleAction::class, ['deactivate', 'delete', 'restore']];
|
|
|
|
|
yield 'UserLifecycleTriggerType' => [UserLifecycleTriggerType::class, ['manual', 'cron', 'system']];
|
|
|
|
|
yield 'UserLifecycleStatus' => [UserLifecycleStatus::class, ['success', 'skipped', 'failed']];
|
|
|
|
|
yield 'ImportAuditStatus' => [ImportAuditStatus::class, ['running', 'success', 'partial', 'failed']];
|
|
|
|
|
yield 'ScheduledJobStatus' => [ScheduledJobStatus::class, ['running', 'success', 'failed', 'skipped']];
|
|
|
|
|
yield 'ScheduledJobRunStatus' => [ScheduledJobRunStatus::class, ['success', 'failed', 'skipped']];
|
|
|
|
|
yield 'ScheduledJobTriggerType' => [ScheduledJobTriggerType::class, ['scheduler', 'manual']];
|
|
|
|
|
yield 'MailLogStatus' => [MailLogStatus::class, ['queued', 'sent', 'failed']];
|
|
|
|
|
yield 'TenantStatus' => [TenantStatus::class, ['active', 'inactive']];
|
|
|
|
|
yield 'SchedulerRuntimeResult' => [SchedulerRuntimeResult::class, ['ok', 'lock_not_acquired', 'unexpected_error']];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[DataProvider('enumProvider')]
|
|
|
|
|
public function testValuesReturnExpectedList(string $enumClass, array $expectedValues): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertSame($expectedValues, $enumClass::values());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[DataProvider('enumProvider')]
|
|
|
|
|
public function testTryNormalizeAndNormalizeOr(string $enumClass, array $expectedValues): void
|
|
|
|
|
{
|
|
|
|
|
$firstValue = $expectedValues[0];
|
|
|
|
|
$firstCase = $enumClass::from($firstValue);
|
|
|
|
|
|
|
|
|
|
$this->assertSame($firstValue, $enumClass::tryNormalize($firstValue)?->value);
|
|
|
|
|
$this->assertSame($firstValue, $enumClass::tryNormalize(strtoupper($firstValue))?->value);
|
|
|
|
|
$this->assertSame($firstValue, $enumClass::tryNormalize(' ' . strtoupper($firstValue) . ' ')?->value);
|
|
|
|
|
$this->assertNull($enumClass::tryNormalize(''));
|
|
|
|
|
$this->assertNull($enumClass::tryNormalize('not-valid'));
|
|
|
|
|
|
|
|
|
|
$this->assertSame($firstValue, $enumClass::normalizeOr('not-valid', $firstCase)->value);
|
|
|
|
|
$this->assertSame($firstValue, $enumClass::normalizeOr($firstValue, $firstCase)->value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[DataProvider('enumProvider')]
|
|
|
|
|
public function testBadgeVariantAndLabelTokenAreDefined(string $enumClass, array $expectedValues): void
|
|
|
|
|
{
|
|
|
|
|
foreach ($expectedValues as $value) {
|
|
|
|
|
$case = $enumClass::from($value);
|
|
|
|
|
|
|
|
|
|
$labelToken = $case->labelToken();
|
|
|
|
|
$badgeVariant = $case->badgeVariant();
|
|
|
|
|
|
|
|
|
|
$this->assertIsString($labelToken);
|
|
|
|
|
$this->assertNotSame('', trim($labelToken));
|
|
|
|
|
$this->assertIsString($badgeVariant);
|
|
|
|
|
$this->assertNotSame('', trim($badgeVariant));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|