Files
SGF/scripts/invoice-guard-proof.php
T
2026-11-04 09:37:20 +02:00

4 lines
1.8 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/invoice-guards.json';if(is_file($out))throw new LogicException('Proof preserved');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$queries=0;$checks=[];DB::listen(function()use(&$queries){$queries++;});$probe=function($fn,$status,$name)use(&$checks,&$queries){$before=$queries;try{$fn();throw new RuntimeException('Guard unexpectedly accepted');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==$status||$queries!==$before)throw new RuntimeException($name);$checks[]=$name;}};config(['receipt_qa.invoices_enabled'=>false]);$rt=new App\Modules\Purchasing\ReceiptRuntime;$probe(fn()=>$rt->run('purchasing_invoices.prepare',fn()=>true),404,'disabled invoice runtime refuses before SQL');$probe(fn()=>(new App\Modules\Purchasing\InvoiceController)->preview(1,new Illuminate\Http\Request,$rt),404,'disabled invoice preview refuses before validation and SQL');config(['receipt_qa.invoices_enabled'=>true]);$app->instance('env','production');$probe(fn()=>$rt->run('purchasing_invoices.prepare',fn()=>true),403,'production refuses synthetic invoice workflow');foreach(['purchasing/invoices','api/purchasing-invoices','api/purchasing-invoices/orders/1/confirm']as$path){if(App\Shared\Context\ModuleNavigation::owner($path)!=='purchasing')throw new RuntimeException('Wrong module owner');$checks[]='invoice route remains in purchasing: '.$path;}file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'database_queries'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." invoice guard checks passed.\n";