Files
compras/tests/Unit/LandedQaReceiptsTest.php
T
nala dc73540558
tests / ci (push) Waiting to run
commit melhorias compras6
2026-11-23 06:37:16 +02:00

46 lines
3.2 KiB
PHP

<?php
require_once __DIR__.'/../Support/LandedQaReceipts.php';
test('separate Pest kernels cannot reuse one disposable database with persistent migration functions', function () {
$pest = ['php', 'vendor/bin/pest', 'tests/Feature/ImportTariffCodesTest.php'];
expect(landedQaCommandIsolationVerified([$pest]))->toBeTrue();
expect(landedQaCommandIsolationVerified([['php', 'worker.php', 'db', 'migrate'], $pest]))->toBeTrue();
expect(landedQaCommandIsolationVerified([$pest, $pest]))->toBeFalse();
});
test('the worker mode follows the database argument and a Laravel console exception is never a passing proof', function () {
$command = ['php', 'tests/Concurrency/quotation-exchange-worker.php', 'compras_receipts_test_000000000001', 'migrate'];
expect(landedQaReceiptsVerified($command, "{\"isolated_schema_prepared\":true}\n"))->toBeTrue();
expect(landedQaReceiptsVerified($command, 'In Connection.php line 864: synthetic missing table'))->toBeFalse();
expect(landedQaReceiptsVerified(['php', 'worker.php', 'compras_receipts_test_000000000001', 'landed-costs'], "{\"isolated_schema_prepared\":true}\n"))->toBeFalse();
});
test('a contention proof requires all three distinct blocked-writer scenarios and the incompatible-runtime refusal', function () {
$command = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'race'];
$records = [];
foreach (['same_operation', 'conflicting_plan_version', 'same_source_different_plan'] as $scenario) {
$records[] = ['scenario' => $scenario, 'statuses' => $scenario === 'same_operation' ? [200, 200] : [200, 409],
'blocked_writers_observed' => 2, 'commands' => 1, 'audits' => 1];
}
$encode = fn ($rows) => implode("\n", array_map(fn ($row) => json_encode($row, JSON_THROW_ON_ERROR), $rows));
expect(landedQaReceiptsVerified($command, $encode($records)))->toBeFalse();
$records[] = ['old_runtime_rejected_before_balance' => true, 'status' => 503];
expect(landedQaReceiptsVerified($command, $encode($records)))->toBeTrue();
$records[2] = $records[0];
expect(landedQaReceiptsVerified($command, $encode($records)))->toBeFalse();
});
test('restore completion requires the restored replay original snapshot and database cleanup', function () {
$command = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'landed-costs'];
$proof = json_encode(['post_extension_restore_all_tables_equal' => true, 'recovered_operation_replay_no_effects' => true,
'pre_extension_schema_data_balance_restored' => true], JSON_THROW_ON_ERROR);
expect(landedQaReceiptsVerified($command, $proof))->toBeFalse();
$databaseOnly = $proof."\n".json_encode(['isolated_restore_removed' => true], JSON_THROW_ON_ERROR);
expect(landedQaReceiptsVerified($command, $databaseOnly))->toBeFalse();
$privateFiles = ['private_original_versions_restored' => 2, 'source_loss_detected' => true,
'separate_private_root_restored' => true, 'native_authorized_evidence_resolved' => true];
expect(landedQaReceiptsVerified($command, $databaseOnly."\n".json_encode($privateFiles, JSON_THROW_ON_ERROR)))->toBeTrue();
expect(landedQaReceiptsVerified(['php', 'vendor/bin/pest', '--compact'], '{"tool":"pest","result":"passed","tests":1,"passed":0,"skipped":1}'))->toBeFalse();
});