Files
portal/app/tests/Feature/Audit/VerifyAuditChainsTest.php
T
Дмитрий 720697ae43 style(audit): pint auto-fix на shared config + rebuild rewrite
Task 6 Step 4 плана 2026-05-29-audit-rebuild-per-tenant-fix.md.
Pint auto-fix purely cosmetic (unary_operator_spaces, phpdoc_align,
ordered_imports, fully_qualified_strict_types, no_blank_lines_after_phpdoc).
Никаких semantic-изменений.

Larastan analyse --level=max на 3 файла: 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-29 18:14:41 +03:00

66 lines
2.4 KiB
PHP

<?php
// Tests for audit:verify-chains command — regression guard for Task 2 refactor.
// Verifies that the command uses AuditChainConfig::TABLES (shared config)
// and that AuditChainConfig::rowExpression() works for all registered tables.
declare(strict_types=1);
use App\Console\Commands\VerifyAuditChains;
use App\Services\Audit\AuditChainConfig;
/**
* Regression tests for VerifyAuditChains → AuditChainConfig refactor (ADR-018 Task 2).
*
* These tests do NOT require a DB connection — they verify the static config
* integrity used by both VerifyAuditChains and AuditRebuildChain.
*/
it('AuditChainConfig::TABLES registers all six expected audit tables', function (): void {
$tables = array_keys(AuditChainConfig::TABLES);
expect($tables)->toContain('auth_log')
->toContain('activity_log')
->toContain('tenant_operations_log')
->toContain('balance_transactions')
->toContain('pd_processing_log')
->toContain('saas_admin_audit_log');
expect(count($tables))->toBe(6);
});
it('AuditChainConfig::rowExpression builds ROW expression with NULL::bytea at log_hash position', function (): void {
$expr = AuditChainConfig::rowExpression('auth_log');
expect($expr)->toStartWith('ROW(')
->toContain('NULL::bytea')
->not->toContain('t.__log_hash__');
});
it('AuditChainConfig::rowExpression produces same result for all six tables', function (): void {
foreach (array_keys(AuditChainConfig::TABLES) as $table) {
$expr = AuditChainConfig::rowExpression($table);
expect($expr)
->toStartWith('ROW(')
->toContain('NULL::bytea')
->not->toContain('t.__log_hash__');
}
});
it('AuditChainConfig::rowExpression throws for unknown table', function (): void {
AuditChainConfig::rowExpression('nonexistent_table');
})->throws(InvalidArgumentException::class);
it('VerifyAuditChains command class exists and is registered', function (): void {
expect(class_exists(VerifyAuditChains::class))->toBeTrue();
});
it('VerifyAuditChains does not have private TABLE_CONFIG const after ADR-018 refactor', function (): void {
$reflection = new ReflectionClass(VerifyAuditChains::class);
$constants = $reflection->getReflectionConstants();
$names = array_map(fn ($c) => $c->getName(), $constants);
// After Task 2 refactor, TABLE_CONFIG should be removed (delegated to AuditChainConfig::TABLES)
expect($names)->not->toContain('TABLE_CONFIG');
});