6 lines
1.7 KiB
PHP
6 lines
1.7 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/receipt-workspace-guards.json';if(!($s['receiptWorkspace']??false)||is_file($out))throw new LogicException('New receipt workspace required');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++;});$controller=new App\Modules\Purchasing\ReceiptController;$runtime=new App\Modules\Purchasing\ReceiptRuntime;
|
|
$check=function($fn,$status,$name)use(&$checks){try{$fn();throw new RuntimeException('Unexpected acceptance');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==$status)throw $e;}$checks[]=$name;};config(['receipt_qa.enabled'=>false]);$check(fn()=>$controller->catalogue(1,1,new Illuminate\Http\Request,$runtime),404,'disabled catalogue refuses before SQL');$check(fn()=>$controller->history(1,new Illuminate\Http\Request,$runtime),404,'disabled history refuses before SQL');config(['receipt_qa.enabled'=>true]);$app->instance('env','production');$check(fn()=>$controller->catalogue(1,1,new Illuminate\Http\Request,$runtime),403,'production refuses synthetic catalogue before SQL');
|
|
if($queries!==0||App\Shared\Context\ModuleNavigation::owner('api/purchasing-receipts/orders/1/lines/1/catalogue')!=='purchasing')throw new RuntimeException('Guard scope');$checks[]='catalogue belongs to purchasing and guard probes issue zero SQL';file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'database_queries'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." receipt workspace guard checks passed.\n";
|