Tornar a suite de testes portável e alinhada com o código
- sgfTempoPath(): substitui caminhos C:/laragon fixos (SGF_TEMPO_ROOT, por omissão a pasta irmã sgf-tempo, igual ao Laragon). - skipUnlessIsolatedPostgres(): testes que exigem a base QA PostgreSQL isolada passam a ser ignorados com motivo em SQLite em vez de rebentar. - Artefacto de distribuição orçamental gerado localmente: ignorado se ausente. - Páginas públicas /consulta e /proposta: testes alinhados com os redireccionamentos para os módulos reais (decisão de 29/11). - Impressão da ordem: texto do aviso orçamental actualizado. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\{ConflictGuard,ReceiptStockMovement};
|
||||
use App\Services\ConflictGuard;
|
||||
use App\Services\ReceiptStockMovement;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -10,15 +12,27 @@ final class ReceiptAdapterReplayTest extends TestCase
|
||||
{
|
||||
public function test_final_adapter_reuses_existing_movement_without_a_second_effect(): void
|
||||
{
|
||||
$i=DB::selectOne("SELECT current_database() AS name,current_user AS role,current_setting('cluster_name') AS cluster");
|
||||
$this->assertMatchesRegularExpression('/^compras_receipts_test_([a-f0-9]{12})$/D',$i->name);
|
||||
$this->assertSame('stock_receipt_qa_'.substr($i->name,-12),$i->role);$this->assertSame('sgf_modular_regression_'.getenv('SGF_ISOLATED_REGRESSION_RUN'),$i->cluster);
|
||||
$root=realpath((string)getenv('STOCK_RECEIPT_ROOT'));$this->assertNotFalse($root);
|
||||
$proof=json_decode(file_get_contents($root.'/receipt-results.json'),true,512,JSON_THROW_ON_ERROR);
|
||||
$row=DB::table('stock_movements')->where('tenant_id',$proof['link']['tenant'])->where('id',$proof['link']['movement'])->first();$this->assertNotNull($row);
|
||||
$actor=User::findOrFail($row->moved_by);$this->actingAs($actor);$count=DB::table('stock_movements')->count();
|
||||
$hash=json_decode($row->snapshot,true)['inventory_source_hash'];
|
||||
$result=DB::transaction(function()use($actor,$row,$hash){app(ConflictGuard::class)->lockCompany($actor);return app(ReceiptStockMovement::class)->for($actor)->write($row->goods_receipt_item_id,$hash);});
|
||||
$this->assertTrue($result['replayed']);$this->assertSame((int)$row->id,$result['movement_id']);$this->assertSame($count,DB::table('stock_movements')->count());
|
||||
skipUnlessIsolatedPostgres($this);
|
||||
$i = DB::selectOne("SELECT current_database() AS name,current_user AS role,current_setting('cluster_name') AS cluster");
|
||||
$this->assertMatchesRegularExpression('/^compras_receipts_test_([a-f0-9]{12})$/D', $i->name);
|
||||
$this->assertSame('stock_receipt_qa_'.substr($i->name, -12), $i->role);
|
||||
$this->assertSame('sgf_modular_regression_'.getenv('SGF_ISOLATED_REGRESSION_RUN'), $i->cluster);
|
||||
$root = realpath((string) getenv('STOCK_RECEIPT_ROOT'));
|
||||
$this->assertNotFalse($root);
|
||||
$proof = json_decode(file_get_contents($root.'/receipt-results.json'), true, 512, JSON_THROW_ON_ERROR);
|
||||
$row = DB::table('stock_movements')->where('tenant_id', $proof['link']['tenant'])->where('id', $proof['link']['movement'])->first();
|
||||
$this->assertNotNull($row);
|
||||
$actor = User::findOrFail($row->moved_by);
|
||||
$this->actingAs($actor);
|
||||
$count = DB::table('stock_movements')->count();
|
||||
$hash = json_decode($row->snapshot, true)['inventory_source_hash'];
|
||||
$result = DB::transaction(function () use ($actor, $row, $hash) {
|
||||
app(ConflictGuard::class)->lockCompany($actor);
|
||||
|
||||
return app(ReceiptStockMovement::class)->for($actor)->write($row->goods_receipt_item_id, $hash);
|
||||
});
|
||||
$this->assertTrue($result['replayed']);
|
||||
$this->assertSame((int) $row->id, $result['movement_id']);
|
||||
$this->assertSame($count, DB::table('stock_movements')->count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user