Files
compras/tests/Feature/BudgetDistributionRuntimeGuardTest.php
T
nala 36dcfdf00c
tests / ci (push) Canceled after 0s
commit melhorias compras4
2026-11-22 16:28:03 +02:00

49 lines
2.3 KiB
PHP

<?php
use App\Enums\PurchasingRole;
use App\Models\User;
use App\Services\CommonBudget;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Tempo\Finance\Budget\BudgetControl;
require_once __DIR__.'/../Support/ReceiptFixture.php';
require_once __DIR__.'/../Support/BudgetDistributionSchema.php';
test('old pinned runtime refuses partial optional schema even when its source table is absent', function () {
if (method_exists(BudgetControl::class, 'recordDistribution')) {
$this->markTestSkipped('Recovery boundary requires the unchanged installed artifact.');
}
$f = receiptFixture();
budgetDistributionFixtureSchema();
DB::connection()->getSchemaBuilder()->drop('budget_distributions');
$actor = User::factory()->create(['tenant_id' => $f['tenant']->id, 'purchasing_role' => PurchasingRole::Finance]);
$this->actingAs($actor);
try {
app(CommonBudget::class)->for($actor);
$this->fail('Partial optional schema cannot silently become a legacy balance.');
} catch (HttpException $error) {
expect($error->getStatusCode())->toBe(503);
}
expect(DB::table('budget_entries')->count())->toBe(0);
});
test('old pinned runtime refuses to ignore a distributed origin instead of presenting a false available balance', function () {
if (method_exists(BudgetControl::class, 'recordDistribution')) {
$this->markTestSkipped('This recovery boundary exercises the unchanged installed artifact.');
}
$f = receiptFixture();
budgetDistributionFixtureSchema();
$actor = User::factory()->create(['tenant_id' => $f['tenant']->id, 'purchasing_role' => PurchasingRole::Finance]);
$this->actingAs($actor);
DB::table('budget_distributions')->insert(['tenant_id' => $actor->tenant_id, 'requisition_id' => $f['r']->id,
'phase' => 'reserve', 'snapshot' => '{}', 'created_by' => $actor->id, 'created_at' => now(), 'updated_at' => now()]);
try {
app(CommonBudget::class)->for($actor);
$this->fail('An incompatible runtime must fail closed.');
} catch (HttpException $error) {
expect($error->getStatusCode())->toBe(503);
}
expect(DB::table('budget_entries')->count())->toBe(0)->and(DB::table('budget_consumptions')->count())->toBe(0);
});