From 2c2a0502d694be39f51aaeb197c5fd12a0dd79c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 16 Nov 2026 00:53:36 +0100 Subject: [PATCH] refactor(routing): execute published product route binding via Executor --- app/Providers/RouteServiceProvider.php | 7 ++- .../Fo/ProductCharacterizationTest.php | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 0fb46aa6..8d17c7ce 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Providers; +use App\Contracts\Executor; use App\Cqs\Queries\Products\GetPublishedProductWithPricingQuery; use App\Cqs\Queries\Products\GetPublishedProductWithPricingQueryInput; use App\Dto\ProductWithPricingDto; @@ -146,8 +147,10 @@ class RouteServiceProvider extends ServiceProvider throw new NotFoundHttpException(); } - return resolve(GetPublishedProductWithPricingQuery::class)($input) - ?? throw new NotFoundHttpException(); + return $this->app->make(Executor::class)->execute( + $this->app->make(GetPublishedProductWithPricingQuery::class), + $input, + ) ?? throw new NotFoundHttpException(); } /** diff --git a/tests/Feature/App/Http/Controllers/Fo/ProductCharacterizationTest.php b/tests/Feature/App/Http/Controllers/Fo/ProductCharacterizationTest.php index 5bd4f838..66503945 100644 --- a/tests/Feature/App/Http/Controllers/Fo/ProductCharacterizationTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/ProductCharacterizationTest.php @@ -2,6 +2,12 @@ declare(strict_types=1); +use App\Contracts\Action; +use App\Contracts\ActionInput; +use App\Contracts\Executor; +use App\Contracts\Query; +use App\Contracts\QueryInput; +use App\Cqs\Queries\Products\GetPublishedProductWithPricingQuery; use App\Models\Customer; use App\Models\Discount; use App\Models\Page; @@ -23,6 +29,9 @@ use Ramsey\Uuid\Uuid; use Shared\ValueObjects\CrmHashcode; use Tests\TestCase; +use function Pest\Laravel\actingAs; +use function Pest\Laravel\get; + /** * Tests de caractérisation (étape 0 du refactoring Product) : figent le * comportement observable du FO avant de toucher au modèle / DTO / policy. @@ -230,4 +239,46 @@ describe('FO product page (characterization)', function (): void { // THEN $response->assertNotFound(); }); + + it('resolves published product route binding through Executor', function (): void { + // GIVEN + /** @var \Tests\TestCase $this */ + characterizationBootFo($this); + actingAs(characterizationCustomer('executor@example.com'), 'frontend'); + $product = characterizationProduct('Produit Executor'); + + $realExecutor = app(Executor::class); + $executed = []; + $spyExecutor = new class ($realExecutor, $executed) implements Executor + { + /** @var array */ + public array $executedClasses = []; + + /** + * @param array $executedClasses + */ + public function __construct( + private readonly Executor $inner, + array &$executedClasses, + ) { + $this->executedClasses = &$executedClasses; + } + + #[\Override] + public function execute(Action | Query $executable, ActionInput | QueryInput $input): mixed + { + $this->executedClasses[] = $executable::class; + + return $this->inner->execute($executable, $input); + } + }; + app()->instance(Executor::class, $spyExecutor); + + // WHEN + $response = get(route('fo.products.show', ['productWithPricingPublished' => $product->slug])); + + // THEN + $response->assertOk(); + expect($executed)->toContain(GetPublishedProductWithPricingQuery::class); + }); });