Files
SGF/scripts/financial-receipt-core.php
2026-11-04 09:37:20 +02:00

5 lines
1.4 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
use Tempo\Finance\Payables\ReceiptReader;
$out=$s['root'].'/financial-receipt-core.json';if(file_exists($out))throw new LogicException('Preserved core proof');$f=json_decode(file_get_contents($s['root'].'/financial-receipt-fixture.json'),true);$checks=0;$ok=function($v)use(&$checks){$checks++;if(!$v)throw new LogicException('Scoped receipt core invariant failed');};DB::beginTransaction();try{DB::statement('SET TRANSACTION READ ONLY');foreach(['tenant_id','company_id','unit_id'] as $key){$other=$scope;$other[$key]+=100;$ok(ReceiptReader::read(DB::connection(),'recognition',$other,$g['actors']['prepare'],$f['key'],static fn()=>null)===null);}$caught=false;try{ReceiptReader::read(DB::connection(),'recognition',$scope,$g['actors']['prepare'],$f['key'],null);}catch(DomainException){$caught=true;}$ok($caught);$caught=false;try{ReceiptReader::read(DB::connection(),'pa_commands;DROP TABLE users',$scope,$g['actors']['prepare'],$f['key'],static fn()=>null);}catch(InvalidArgumentException){$caught=true;}$ok($caught);$ok(DB::table('ps_payments')->count()===0);}finally{DB::rollBack();}file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'foreign_tenant_company_unit_absent'=>true,'missing_read_authorizer_refused'=>true,'domain_whitelist'=>true,'read_only'=>true],JSON_PRETTY_PRINT));echo "Financial receipt core: $checks checks.\n";