refactor(routing): execute published product route binding via Executor

This commit is contained in:
Jérémy Munsch 2026-11-16 00:53:36 +01:00
parent 4bbea5d285
commit 2c2a0502d6
No known key found for this signature in database
GPG key ID: 2AAECDA6B7330F91
2 changed files with 56 additions and 2 deletions

View file

@ -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();
}
/**

View file

@ -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<int, string> */
public array $executedClasses = [];
/**
* @param array<int, string> $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);
});
});