12 lines
2.2 KiB
PHP
12 lines
2.2 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Tempo\Finance\GeneralLedger\PayableJournal;
|
|
$case(function()use($rate,$enter,$f,$scope,$ok){
|
|
$rate();$source=$enter('read')->stock->source('stock.receipt',$f['movements'][0]['id']);$m=$f['movements'][1];$source=array_replace($source,['effect_type'=>'stock.issue','source_id'=>$m['id'],'obligation_id'=>$m['id'],'stock_movement_id'=>$m['id'],'stock_quantity_milli'=>-1000,'principal_minor'=>5000]);
|
|
$fake=function($role)use($enter,$f,$scope,$source){$c=$enter($role);return new PayableJournal(DB::connection(),$scope,$f['actors'][$role],'qa-stock-person-'.$f['actors'][$role],(new ReflectionProperty($c,'authorize'))->getValue($c),(new ReflectionProperty($c,'readAuthorize'))->getValue($c),fn()=>throw new DomainException('No supplier'),null,fn()=>$source);};
|
|
$p=$fake('prepare')->command('effect-prepare',['effect_type'=>'stock.issue','source_id'=>$m['id'],'journal_on'=>'2026-10-29','period_key'=>'QA-2026-10','rule_key'=>'stock.issue','reason'=>'Independent SQL order guard probe, no prior receipt journal.'],(string)Str::uuid());$fake('validate')->command('validate',['proposal_id'=>$p['proposal_id'],'revision'=>$p['revision'],'decision'=>'approved','reason'=>'Adversarial supplied PHP source cannot bypass SQL dependencies.'],(string)Str::uuid());$error=null;
|
|
try{DB::transaction(function()use($fake,$p){$fake('prepare')->command('post',['proposal_id'=>$p['proposal_id'],'revision'=>$p['revision'],'reason'=>'Correct amount but absent predecessor must be refused by SQL.'],(string)Str::uuid());DB::statement('SET CONSTRAINTS gl_stock_journal IMMEDIATE');});}catch(Illuminate\Database\QueryException $e){$error=$e;}
|
|
$ok($error&&($error->errorInfo[0]??null)==='23514'&&str_contains($error->getMessage(),'GL_STOCK_JOURNAL_SOURCE_OR_LINES'),'SQL independently refuses issue before receipt valuation');$ok(DB::table('gl_journals')->count()===0&&DB::table('gl_lines')->count()===0,'failed order guard leaves no partial journal');
|
|
});file_put_contents($s['root'].'/order-guard.json',json_encode(['passed'=>true,'checks'=>$checks,'all_changes_rolled_back'=>true],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." independent SQL predecessor checks passed.\n";
|