fix(tests): Bus::fake partial + session mock — close quirk #72

CsvReconcileJobTest used Bus::fake() (all jobs), silencing dispatch_sync of
RefreshSupplierSessionJob when a parallel afterEach wiped supplier:session.
Now: Bus::fake([RouteSupplierLeadJob::class]) + anonymous mock that re-puts
the session in handle(), making race-window recovery deterministic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Дмитрий
2026-05-14 05:35:06 +03:00
parent 9a45346205
commit 08605cf640
@@ -5,6 +5,7 @@ declare(strict_types=1);
use App\Exceptions\Supplier\SupplierTransientException;
use App\Jobs\RouteSupplierLeadJob;
use App\Jobs\Supplier\CsvReconcileJob;
use App\Jobs\Supplier\RefreshSupplierSessionJob;
use App\Mail\CsvDriftAlertMail;
use App\Models\SupplierLead;
use App\Models\SupplierProject;
@@ -47,7 +48,18 @@ function putSupplierSession(): void
beforeEach(function () {
Mail::fake();
Bus::fake();
// Partial fake: only RouteSupplierLeadJob is intercepted (what we assert on).
// RefreshSupplierSessionJob must NOT be faked — it must run our mock below
// so that loadSession() can recover if a concurrent afterEach wipes the session.
Bus::fake([RouteSupplierLeadJob::class]);
// Bind a mock that re-puts the session when dispatch_sync triggers it during a race.
app()->bind(RefreshSupplierSessionJob::class, fn () => new class
{
public function handle(): void
{
putSupplierSession();
}
});
// NB: NOT Cache::store('redis')->flush() — flush wipes session keys belonging to
// OTHER parallel tests (cross-pollution). Just forget our reserved keys + re-put.
Cache::store('redis')->forget('supplier:csv_reconcile');