5 lines
2.1 KiB
PHP
5 lines
2.1 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/geography-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($call,$expected,$name)use(&$queries,&$checks){$before=$queries;try{$call();throw new RuntimeException('Guard accepted unexpectedly');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==$expected||$queries!==$before)throw new RuntimeException($name);$checks[]=$name;}};config(['geography.enabled'=>false]);$probe(fn()=>App\Shared\Geography\Catalogue::guard(),404,'disabled catalogue refuses before SQL');$probe(fn()=>(new App\Shared\Geography\GeographyController)->preview('company',1,new Illuminate\Http\Request,new App\Shared\Geography\Locations),404,'disabled preview refuses before validation and SQL');$probe(fn()=>App\Shared\Geography\Segments::page('client',[]),404,'disabled segmentation refuses before SQL');config(['geography.enabled'=>true]);$app->instance('env','production');$probe(fn()=>App\Shared\Geography\Catalogue::guard(),403,'production refuses synthetic geography before SQL');
|
|
foreach(['geography/company/1'=>null,'geography/unit/1'=>null,'api/geography/catalogue'=>null,'geography/client/1'=>'commercial','api/geography/segments/client'=>'commercial','geography/supplier/1'=>'purchasing','api/geography/entities/supplier/1/confirm'=>'purchasing','api/geography/segments/supplier'=>'purchasing']as$path=>$owner){if(App\Shared\Context\ModuleNavigation::owner($path)!==$owner)throw new RuntimeException('Wrong module owner');$checks[]='correct module owner: '.$path;}file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'database_queries'=>0,'public_rights_changed'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." geography guard checks passed.\n";
|