Compare commits
3 Commits
step/02-co
...
step/05-ha
| Author | SHA1 | Date | |
|---|---|---|---|
| b356033f7b | |||
| 129ea58dae | |||
| f8be8166b7 |
@@ -10,6 +10,9 @@ services:
|
|||||||
MiniShop\Shared\Technical\Clock:
|
MiniShop\Shared\Technical\Clock:
|
||||||
alias: MiniShop\Shared\Technical\SystemClock
|
alias: MiniShop\Shared\Technical\SystemClock
|
||||||
|
|
||||||
|
MiniShop\Shared\Technical\IdempotencyStore:
|
||||||
|
alias: MiniShop\Shared\Technical\InMemoryIdempotencyStore
|
||||||
|
|
||||||
# --- Sales ---
|
# --- Sales ---
|
||||||
MiniShop\Sales\Application\:
|
MiniShop\Sales\Application\:
|
||||||
resource: '%kernel.project_dir%/src/Sales/Application/'
|
resource: '%kernel.project_dir%/src/Sales/Application/'
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ final readonly class OrderCancelled
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $orderId,
|
public string $orderId,
|
||||||
|
public string $correlationId = '',
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,6 @@ final readonly class OrderConfirmed
|
|||||||
public int $totalInCents,
|
public int $totalInCents,
|
||||||
public string $currency,
|
public string $currency,
|
||||||
public array $lines,
|
public array $lines,
|
||||||
|
public string $correlationId = '',
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,6 @@ final readonly class OrderPlaced
|
|||||||
public string $currency,
|
public string $currency,
|
||||||
public string $placedAt,
|
public string $placedAt,
|
||||||
public array $lines,
|
public array $lines,
|
||||||
|
public string $correlationId = '',
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,21 +7,42 @@ namespace MiniShop\Invoicing\Interfaces\Messaging;
|
|||||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrder;
|
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrder;
|
||||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
||||||
|
use MiniShop\Shared\Technical\IdempotencyStore;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conformist : Invoicing consomme le contrat sales.v1.OrderConfirmed tel quel,
|
* Conformist + Idempotent : consomme sales.v1.OrderConfirmed tel quel.
|
||||||
* sans traduction. La dependance upstream est explicite.
|
* Garde d'idempotence pour eviter les doublons en cas de re-delivery.
|
||||||
*/
|
*/
|
||||||
#[AsMessageHandler]
|
#[AsMessageHandler]
|
||||||
final readonly class WhenOrderConfirmed
|
final readonly class WhenOrderConfirmed
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private IssueInvoiceForExternalOrderHandler $handler,
|
private IssueInvoiceForExternalOrderHandler $handler,
|
||||||
|
private IdempotencyStore $idempotencyStore,
|
||||||
|
private LoggerInterface $logger = new NullLogger(),
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function __invoke(OrderConfirmed $message): void
|
public function __invoke(OrderConfirmed $message): void
|
||||||
{
|
{
|
||||||
|
$idempotencyKey = 'invoicing:order-confirmed:' . $message->orderId;
|
||||||
|
|
||||||
|
if ($this->idempotencyStore->isDuplicate($idempotencyKey)) {
|
||||||
|
$this->logger->info('Duplicate OrderConfirmed ignored.', [
|
||||||
|
'orderId' => $message->orderId,
|
||||||
|
'correlationId' => $message->correlationId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logger->info('Processing OrderConfirmed.', [
|
||||||
|
'orderId' => $message->orderId,
|
||||||
|
'correlationId' => $message->correlationId,
|
||||||
|
]);
|
||||||
|
|
||||||
($this->handler)(new IssueInvoiceForExternalOrder(
|
($this->handler)(new IssueInvoiceForExternalOrder(
|
||||||
externalOrderId: $message->orderId,
|
externalOrderId: $message->orderId,
|
||||||
customerName: 'Customer ' . $message->customerId,
|
customerName: 'Customer ' . $message->customerId,
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modele legacy : champs abreges et codifications imposees par le systeme d'expedition historique.
|
||||||
|
* Ce format ne doit jamais fuiter en dehors de l'ACL.
|
||||||
|
*/
|
||||||
|
final readonly class LegacyCreateShipmentCommand
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $ord_ref, // reference commande (format legacy: prefixe LEG-)
|
||||||
|
public string $rcpt_nm, // nom destinataire (tronque a 35 chars)
|
||||||
|
public string $rcpt_addr, // adresse sur une ligne
|
||||||
|
public string $rcpt_zip, // code postal
|
||||||
|
public string $rcpt_cty, // code pays ISO 2
|
||||||
|
public int $wgt_g, // poids en grammes
|
||||||
|
public string $desc, // description colis
|
||||||
|
public string $req_dt, // date demande format legacy YYYYMMDD
|
||||||
|
public string $sts, // statut: NEW, DIS (dispatched)
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption;
|
||||||
|
|
||||||
|
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anti-Corruption Layer : traduit le Published Language sales.v1 vers le modele
|
||||||
|
* legacy d'expedition. Isole toutes les bizarreries du format legacy.
|
||||||
|
*
|
||||||
|
* @see §13.2 du boilerplate spec
|
||||||
|
*/
|
||||||
|
final class LegacyShipmentAcl
|
||||||
|
{
|
||||||
|
private const int MAX_RECIPIENT_LENGTH = 35;
|
||||||
|
|
||||||
|
public function fromSalesOrderConfirmed(OrderConfirmed $message): LegacyCreateShipmentCommand
|
||||||
|
{
|
||||||
|
$recipientName = mb_substr('Customer ' . $message->customerId, 0, self::MAX_RECIPIENT_LENGTH);
|
||||||
|
|
||||||
|
$totalWeight = max(100, count($message->lines) * 500);
|
||||||
|
|
||||||
|
$description = sprintf(
|
||||||
|
'CMD-%s/%d articles',
|
||||||
|
mb_substr($message->orderId, 0, 8),
|
||||||
|
count($message->lines),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new LegacyCreateShipmentCommand(
|
||||||
|
ord_ref: 'LEG-' . $message->orderId,
|
||||||
|
rcpt_nm: $recipientName,
|
||||||
|
rcpt_addr: 'N/A',
|
||||||
|
rcpt_zip: '00000',
|
||||||
|
rcpt_cty: 'FR',
|
||||||
|
wgt_g: $totalWeight,
|
||||||
|
desc: $description,
|
||||||
|
req_dt: date('Ymd'),
|
||||||
|
sts: 'NEW',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\LegacyFulfillment\Interfaces\Messaging;
|
||||||
|
|
||||||
|
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||||
|
use MiniShop\LegacyFulfillment\Application\Command\RequestShipmentFromSalesOrder;
|
||||||
|
use MiniShop\LegacyFulfillment\Application\Command\RequestShipmentFromSalesOrderHandler;
|
||||||
|
use MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption\LegacyShipmentAcl;
|
||||||
|
use MiniShop\Shared\Technical\IdempotencyStore;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consumer ACL + Idempotent : passe par l'Anti-Corruption Layer avec
|
||||||
|
* garde d'idempotence pour eviter les doublons.
|
||||||
|
*/
|
||||||
|
#[AsMessageHandler]
|
||||||
|
final readonly class WhenOrderConfirmed
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private LegacyShipmentAcl $acl,
|
||||||
|
private RequestShipmentFromSalesOrderHandler $handler,
|
||||||
|
private IdempotencyStore $idempotencyStore,
|
||||||
|
private LoggerInterface $logger = new NullLogger(),
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function __invoke(OrderConfirmed $message): void
|
||||||
|
{
|
||||||
|
$idempotencyKey = 'fulfillment:order-confirmed:' . $message->orderId;
|
||||||
|
|
||||||
|
if ($this->idempotencyStore->isDuplicate($idempotencyKey)) {
|
||||||
|
$this->logger->info('Duplicate OrderConfirmed ignored.', [
|
||||||
|
'orderId' => $message->orderId,
|
||||||
|
'correlationId' => $message->correlationId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logger->info('Processing OrderConfirmed via ACL.', [
|
||||||
|
'orderId' => $message->orderId,
|
||||||
|
'correlationId' => $message->correlationId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$legacyCommand = $this->acl->fromSalesOrderConfirmed($message);
|
||||||
|
|
||||||
|
($this->handler)(new RequestShipmentFromSalesOrder(
|
||||||
|
externalOrderId: $message->orderId,
|
||||||
|
recipientName: $legacyCommand->rcpt_nm,
|
||||||
|
street: $legacyCommand->rcpt_addr,
|
||||||
|
city: 'N/A',
|
||||||
|
postalCode: $legacyCommand->rcpt_zip,
|
||||||
|
country: $legacyCommand->rcpt_cty,
|
||||||
|
totalWeightInGrams: $legacyCommand->wgt_g,
|
||||||
|
description: $legacyCommand->desc,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,11 +12,12 @@ use MiniShop\Sales\Domain\Event\OrderCancelled;
|
|||||||
use MiniShop\Sales\Domain\Event\OrderConfirmed;
|
use MiniShop\Sales\Domain\Event\OrderConfirmed;
|
||||||
use MiniShop\Sales\Domain\Event\OrderPlaced;
|
use MiniShop\Sales\Domain\Event\OrderPlaced;
|
||||||
use MiniShop\Sales\Domain\Model\OrderLine;
|
use MiniShop\Sales\Domain\Model\OrderLine;
|
||||||
|
use MiniShop\Shared\Technical\CorrelationId;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publie les evenements de domaine Sales sous forme de contrats Published Language
|
* Publie les evenements de domaine Sales sous forme de contrats Published Language
|
||||||
* via Symfony Messenger. Remplace le NaiveSalesEventPublisher.
|
* via Symfony Messenger. Propage un correlationId pour le tracing.
|
||||||
*/
|
*/
|
||||||
final readonly class MessengerSalesEventPublisher implements SalesEventPublisher
|
final readonly class MessengerSalesEventPublisher implements SalesEventPublisher
|
||||||
{
|
{
|
||||||
@@ -33,6 +34,7 @@ final readonly class MessengerSalesEventPublisher implements SalesEventPublisher
|
|||||||
currency: $event->total->currency,
|
currency: $event->total->currency,
|
||||||
placedAt: $event->placedAt->format(\DateTimeInterface::ATOM),
|
placedAt: $event->placedAt->format(\DateTimeInterface::ATOM),
|
||||||
lines: [],
|
lines: [],
|
||||||
|
correlationId: CorrelationId::generate()->toString(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +54,7 @@ final readonly class MessengerSalesEventPublisher implements SalesEventPublisher
|
|||||||
],
|
],
|
||||||
$event->lines,
|
$event->lines,
|
||||||
),
|
),
|
||||||
|
correlationId: CorrelationId::generate()->toString(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +62,7 @@ final readonly class MessengerSalesEventPublisher implements SalesEventPublisher
|
|||||||
{
|
{
|
||||||
$this->messageBus->dispatch(new OrderCancelledContract(
|
$this->messageBus->dispatch(new OrderCancelledContract(
|
||||||
orderId: $event->orderId->toString(),
|
orderId: $event->orderId->toString(),
|
||||||
|
correlationId: CorrelationId::generate()->toString(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
84
src/Sales/Interfaces/Http/Api/V1/OrderController.php
Normal file
84
src/Sales/Interfaces/Http/Api/V1/OrderController.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Sales\Interfaces\Http\Api\V1;
|
||||||
|
|
||||||
|
use MiniShop\Sales\Application\Command\ConfirmOrder;
|
||||||
|
use MiniShop\Sales\Application\Command\ConfirmOrderHandler;
|
||||||
|
use MiniShop\Sales\Application\Command\PlaceOrder;
|
||||||
|
use MiniShop\Sales\Application\Command\PlaceOrderHandler;
|
||||||
|
use MiniShop\Sales\Application\Query\GetOrderById;
|
||||||
|
use MiniShop\Sales\Application\Query\GetOrderByIdHandler;
|
||||||
|
use MiniShop\Sales\Application\Query\ListOrdersByCustomer;
|
||||||
|
use MiniShop\Sales\Application\Query\ListOrdersByCustomerHandler;
|
||||||
|
use MiniShop\Shared\Technical\UuidGenerator;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open Host Service — sales.v1
|
||||||
|
* API stable et versionnee. Les modeles internes ne sont jamais exposes.
|
||||||
|
* Tous les DTOs de reponse passent par OrderViewAssembler → OrderView (Published Language).
|
||||||
|
*/
|
||||||
|
#[Route('/api/sales/v1')]
|
||||||
|
final readonly class OrderController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private PlaceOrderHandler $placeOrderHandler,
|
||||||
|
private ConfirmOrderHandler $confirmOrderHandler,
|
||||||
|
private GetOrderByIdHandler $getOrderByIdHandler,
|
||||||
|
private ListOrdersByCustomerHandler $listOrdersByCustomerHandler,
|
||||||
|
private OrderViewAssembler $assembler,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[Route('/orders', name: 'ohs_sales_place_order', methods: ['POST'])]
|
||||||
|
public function placeOrder(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
/** @var array{customerId: string, lines: list<array{productName: string, quantity: int, unitPriceInCents: int, currency: string}>} $data */
|
||||||
|
$data = json_decode($request->getContent(), true, flags: JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
|
$orderId = UuidGenerator::generate();
|
||||||
|
|
||||||
|
($this->placeOrderHandler)(new PlaceOrder(
|
||||||
|
orderId: $orderId,
|
||||||
|
customerId: $data['customerId'],
|
||||||
|
lines: $data['lines'],
|
||||||
|
));
|
||||||
|
|
||||||
|
$order = ($this->getOrderByIdHandler)(new GetOrderById($orderId));
|
||||||
|
|
||||||
|
return new JsonResponse($this->assembler->toView($order), Response::HTTP_CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/orders/{orderId}', name: 'ohs_sales_get_order', methods: ['GET'])]
|
||||||
|
public function getOrder(string $orderId): JsonResponse
|
||||||
|
{
|
||||||
|
$order = ($this->getOrderByIdHandler)(new GetOrderById($orderId));
|
||||||
|
|
||||||
|
return new JsonResponse($this->assembler->toView($order));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/orders/{orderId}/confirm', name: 'ohs_sales_confirm_order', methods: ['POST'])]
|
||||||
|
public function confirmOrder(string $orderId): JsonResponse
|
||||||
|
{
|
||||||
|
($this->confirmOrderHandler)(new ConfirmOrder(orderId: $orderId));
|
||||||
|
|
||||||
|
$order = ($this->getOrderByIdHandler)(new GetOrderById($orderId));
|
||||||
|
|
||||||
|
return new JsonResponse($this->assembler->toView($order));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/customers/{customerId}/orders', name: 'ohs_sales_list_orders', methods: ['GET'])]
|
||||||
|
public function listOrders(string $customerId): JsonResponse
|
||||||
|
{
|
||||||
|
$orders = ($this->listOrdersByCustomerHandler)(new ListOrdersByCustomer($customerId));
|
||||||
|
|
||||||
|
return new JsonResponse(array_map(
|
||||||
|
fn ($order) => $this->assembler->toView($order),
|
||||||
|
$orders,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/Sales/Interfaces/Http/Api/V1/OrderViewAssembler.php
Normal file
37
src/Sales/Interfaces/Http/Api/V1/OrderViewAssembler.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Sales\Interfaces\Http\Api\V1;
|
||||||
|
|
||||||
|
use MiniShop\Contracts\Sales\V1\Api\OrderView;
|
||||||
|
use MiniShop\Sales\Domain\Model\Order;
|
||||||
|
use MiniShop\Sales\Domain\Model\OrderLine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assemble le modele interne Order vers le DTO public OrderView (sales.v1).
|
||||||
|
* Les modeles internes de Sales ne sont jamais exposes directement.
|
||||||
|
*/
|
||||||
|
final class OrderViewAssembler
|
||||||
|
{
|
||||||
|
public function toView(Order $order): OrderView
|
||||||
|
{
|
||||||
|
return new OrderView(
|
||||||
|
orderId: $order->id->toString(),
|
||||||
|
customerId: $order->customerId->toString(),
|
||||||
|
status: $order->status()->value,
|
||||||
|
totalInCents: $order->total()->amount,
|
||||||
|
currency: $order->total()->currency,
|
||||||
|
lines: array_map(
|
||||||
|
static fn (OrderLine $line): array => [
|
||||||
|
'productName' => $line->productName,
|
||||||
|
'quantity' => $line->quantity,
|
||||||
|
'unitPriceInCents' => $line->unitPrice->amount,
|
||||||
|
'currency' => $line->unitPrice->currency,
|
||||||
|
'lineTotalInCents' => $line->lineTotal()->amount,
|
||||||
|
],
|
||||||
|
$order->lines(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/Shared/Technical/CorrelationId.php
Normal file
25
src/Shared/Technical/CorrelationId.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Shared\Technical;
|
||||||
|
|
||||||
|
final readonly class CorrelationId
|
||||||
|
{
|
||||||
|
private function __construct(public string $value) {}
|
||||||
|
|
||||||
|
public static function generate(): self
|
||||||
|
{
|
||||||
|
return new self(UuidGenerator::generate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fromString(string $value): self
|
||||||
|
{
|
||||||
|
return new self($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toString(): string
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/Shared/Technical/IdempotencyStore.php
Normal file
14
src/Shared/Technical/IdempotencyStore.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Shared\Technical;
|
||||||
|
|
||||||
|
interface IdempotencyStore
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns true if the key was already processed (duplicate).
|
||||||
|
* Returns false and marks the key as processed (first time).
|
||||||
|
*/
|
||||||
|
public function isDuplicate(string $key): bool;
|
||||||
|
}
|
||||||
22
src/Shared/Technical/InMemoryIdempotencyStore.php
Normal file
22
src/Shared/Technical/InMemoryIdempotencyStore.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Shared\Technical;
|
||||||
|
|
||||||
|
final class InMemoryIdempotencyStore implements IdempotencyStore
|
||||||
|
{
|
||||||
|
/** @var array<string, true> */
|
||||||
|
private array $processed = [];
|
||||||
|
|
||||||
|
public function isDuplicate(string $key): bool
|
||||||
|
{
|
||||||
|
if (isset($this->processed[$key])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->processed[$key] = true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
|||||||
use MiniShop\Invoicing\Infrastructure\Persistence\InMemoryInvoiceRepository;
|
use MiniShop\Invoicing\Infrastructure\Persistence\InMemoryInvoiceRepository;
|
||||||
use MiniShop\Invoicing\Infrastructure\SequentialInvoiceNumberGenerator;
|
use MiniShop\Invoicing\Infrastructure\SequentialInvoiceNumberGenerator;
|
||||||
use MiniShop\Invoicing\Interfaces\Messaging\WhenOrderConfirmed;
|
use MiniShop\Invoicing\Interfaces\Messaging\WhenOrderConfirmed;
|
||||||
|
use MiniShop\Shared\Technical\InMemoryIdempotencyStore;
|
||||||
use MiniShop\Shared\Technical\SystemClock;
|
use MiniShop\Shared\Technical\SystemClock;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ final class ConformistCompatibilityTest extends TestCase
|
|||||||
new SequentialInvoiceNumberGenerator(),
|
new SequentialInvoiceNumberGenerator(),
|
||||||
new SystemClock(),
|
new SystemClock(),
|
||||||
);
|
);
|
||||||
$consumer = new WhenOrderConfirmed($handler);
|
$consumer = new WhenOrderConfirmed($handler, new InMemoryIdempotencyStore());
|
||||||
|
|
||||||
$message = new OrderConfirmed(
|
$message = new OrderConfirmed(
|
||||||
orderId: 'order-conformist-001',
|
orderId: 'order-conformist-001',
|
||||||
|
|||||||
97
tests/Integration/IdempotentConsumerTest.php
Normal file
97
tests/Integration/IdempotentConsumerTest.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Tests\Integration;
|
||||||
|
|
||||||
|
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||||
|
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
||||||
|
use MiniShop\Invoicing\Infrastructure\Persistence\InMemoryInvoiceRepository;
|
||||||
|
use MiniShop\Invoicing\Infrastructure\SequentialInvoiceNumberGenerator;
|
||||||
|
use MiniShop\Invoicing\Interfaces\Messaging\WhenOrderConfirmed as InvoicingConsumer;
|
||||||
|
use MiniShop\LegacyFulfillment\Application\Command\RequestShipmentFromSalesOrderHandler;
|
||||||
|
use MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption\LegacyShipmentAcl;
|
||||||
|
use MiniShop\LegacyFulfillment\Infrastructure\Gateway\FakeLegacyFulfillmentGateway;
|
||||||
|
use MiniShop\LegacyFulfillment\Infrastructure\Persistence\InMemoryShipmentRequestRepository;
|
||||||
|
use MiniShop\LegacyFulfillment\Interfaces\Messaging\WhenOrderConfirmed as FulfillmentConsumer;
|
||||||
|
use MiniShop\Shared\Technical\InMemoryIdempotencyStore;
|
||||||
|
use MiniShop\Shared\Technical\SystemClock;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test d'idempotence : un message recu deux fois ne doit pas creer de doublon.
|
||||||
|
*/
|
||||||
|
final class IdempotentConsumerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_invoicing_consumer_ignores_duplicate(): void
|
||||||
|
{
|
||||||
|
$invoiceRepo = new InMemoryInvoiceRepository();
|
||||||
|
$idempotencyStore = new InMemoryIdempotencyStore();
|
||||||
|
|
||||||
|
$consumer = new InvoicingConsumer(
|
||||||
|
new IssueInvoiceForExternalOrderHandler(
|
||||||
|
$invoiceRepo,
|
||||||
|
new SequentialInvoiceNumberGenerator(),
|
||||||
|
new SystemClock(),
|
||||||
|
),
|
||||||
|
$idempotencyStore,
|
||||||
|
);
|
||||||
|
|
||||||
|
$message = $this->createMessage('idem-001');
|
||||||
|
|
||||||
|
$consumer($message);
|
||||||
|
$consumer($message); // duplicate
|
||||||
|
|
||||||
|
// Only one invoice should exist
|
||||||
|
$invoice = $invoiceRepo->findByExternalOrderId('idem-001');
|
||||||
|
self::assertNotNull($invoice);
|
||||||
|
self::assertSame('INV-000001', $invoice->invoiceNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_fulfillment_consumer_ignores_duplicate(): void
|
||||||
|
{
|
||||||
|
$shipmentRepo = new InMemoryShipmentRequestRepository();
|
||||||
|
$gateway = new FakeLegacyFulfillmentGateway();
|
||||||
|
$idempotencyStore = new InMemoryIdempotencyStore();
|
||||||
|
|
||||||
|
$consumer = new FulfillmentConsumer(
|
||||||
|
new LegacyShipmentAcl(),
|
||||||
|
new RequestShipmentFromSalesOrderHandler($shipmentRepo, $gateway, new SystemClock()),
|
||||||
|
$idempotencyStore,
|
||||||
|
);
|
||||||
|
|
||||||
|
$message = $this->createMessage('idem-002');
|
||||||
|
|
||||||
|
$consumer($message);
|
||||||
|
$consumer($message); // duplicate
|
||||||
|
|
||||||
|
// Only one shipment should exist, only one gateway call
|
||||||
|
self::assertCount(1, $gateway->sentRequests());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_correlation_id_is_propagated(): void
|
||||||
|
{
|
||||||
|
$message = new OrderConfirmed(
|
||||||
|
orderId: 'corr-001',
|
||||||
|
customerId: 'cust-001',
|
||||||
|
totalInCents: 1000,
|
||||||
|
currency: 'EUR',
|
||||||
|
lines: [['productName' => 'X', 'quantity' => 1, 'unitPriceInCents' => 1000, 'currency' => 'EUR']],
|
||||||
|
correlationId: 'corr-id-abc-123',
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertSame('corr-id-abc-123', $message->correlationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createMessage(string $orderId): OrderConfirmed
|
||||||
|
{
|
||||||
|
return new OrderConfirmed(
|
||||||
|
orderId: $orderId,
|
||||||
|
customerId: 'cust-001',
|
||||||
|
totalInCents: 1500,
|
||||||
|
currency: 'EUR',
|
||||||
|
lines: [['productName' => 'Widget', 'quantity' => 1, 'unitPriceInCents' => 1500, 'currency' => 'EUR']],
|
||||||
|
correlationId: 'test-correlation-id',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ use MiniShop\Invoicing\Infrastructure\Persistence\InMemoryInvoiceRepository;
|
|||||||
use MiniShop\Invoicing\Infrastructure\SequentialInvoiceNumberGenerator;
|
use MiniShop\Invoicing\Infrastructure\SequentialInvoiceNumberGenerator;
|
||||||
use MiniShop\Invoicing\Interfaces\Messaging\WhenOrderConfirmed;
|
use MiniShop\Invoicing\Interfaces\Messaging\WhenOrderConfirmed;
|
||||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
||||||
|
use MiniShop\Shared\Technical\InMemoryIdempotencyStore;
|
||||||
use MiniShop\Shared\Technical\SystemClock;
|
use MiniShop\Shared\Technical\SystemClock;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ final class InvoicingConformistTest extends TestCase
|
|||||||
new SequentialInvoiceNumberGenerator(),
|
new SequentialInvoiceNumberGenerator(),
|
||||||
new SystemClock(),
|
new SystemClock(),
|
||||||
),
|
),
|
||||||
|
new InMemoryIdempotencyStore(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$consumer(new OrderConfirmed(
|
$consumer(new OrderConfirmed(
|
||||||
|
|||||||
49
tests/Integration/LegacyFulfillmentAclTest.php
Normal file
49
tests/Integration/LegacyFulfillmentAclTest.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Tests\Integration;
|
||||||
|
|
||||||
|
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||||
|
use MiniShop\LegacyFulfillment\Application\Command\RequestShipmentFromSalesOrderHandler;
|
||||||
|
use MiniShop\LegacyFulfillment\Domain\Model\LegacyOrderRef;
|
||||||
|
use MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption\LegacyShipmentAcl;
|
||||||
|
use MiniShop\LegacyFulfillment\Infrastructure\Gateway\FakeLegacyFulfillmentGateway;
|
||||||
|
use MiniShop\LegacyFulfillment\Infrastructure\Persistence\InMemoryShipmentRequestRepository;
|
||||||
|
use MiniShop\LegacyFulfillment\Interfaces\Messaging\WhenOrderConfirmed;
|
||||||
|
use MiniShop\Shared\Technical\InMemoryIdempotencyStore;
|
||||||
|
use MiniShop\Shared\Technical\SystemClock;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test d'integration : le consumer ACL de LegacyFulfillment recoit un message
|
||||||
|
* sales.v1.OrderConfirmed, le traduit via l'ACL, et cree une demande d'expedition.
|
||||||
|
*/
|
||||||
|
final class LegacyFulfillmentAclTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_acl_consumer_creates_shipment_from_contract(): void
|
||||||
|
{
|
||||||
|
$shipmentRepo = new InMemoryShipmentRequestRepository();
|
||||||
|
$gateway = new FakeLegacyFulfillmentGateway();
|
||||||
|
|
||||||
|
$consumer = new WhenOrderConfirmed(
|
||||||
|
new LegacyShipmentAcl(),
|
||||||
|
new RequestShipmentFromSalesOrderHandler($shipmentRepo, $gateway, new SystemClock()),
|
||||||
|
new InMemoryIdempotencyStore(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$consumer(new OrderConfirmed(
|
||||||
|
orderId: 'order-acl-int-001',
|
||||||
|
customerId: 'cust-001',
|
||||||
|
totalInCents: 3000,
|
||||||
|
currency: 'EUR',
|
||||||
|
lines: [
|
||||||
|
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||||
|
],
|
||||||
|
));
|
||||||
|
|
||||||
|
$shipment = $shipmentRepo->findByOrderRef(LegacyOrderRef::fromExternalId('order-acl-int-001'));
|
||||||
|
self::assertNotNull($shipment, 'ACL consumer must create a shipment request.');
|
||||||
|
self::assertCount(1, $gateway->sentRequests());
|
||||||
|
}
|
||||||
|
}
|
||||||
94
tests/Integration/Sales/OhsApiTest.php
Normal file
94
tests/Integration/Sales/OhsApiTest.php
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Tests\Integration\Sales;
|
||||||
|
|
||||||
|
use MiniShop\Contracts\Sales\V1\Api\OrderView;
|
||||||
|
use MiniShop\Sales\Application\Command\PlaceOrder;
|
||||||
|
use MiniShop\Sales\Application\Command\PlaceOrderHandler;
|
||||||
|
use MiniShop\Sales\Application\Query\GetOrderById;
|
||||||
|
use MiniShop\Sales\Application\Query\GetOrderByIdHandler;
|
||||||
|
use MiniShop\Sales\Domain\Model\OrderLine;
|
||||||
|
use MiniShop\Sales\Interfaces\Http\Api\V1\OrderViewAssembler;
|
||||||
|
use MiniShop\Sales\Infrastructure\Persistence\InMemoryOrderRepository;
|
||||||
|
use MiniShop\Shared\Technical\SystemClock;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test de l'Open Host Service : verifie que l'API OHS expose uniquement
|
||||||
|
* des DTOs du Published Language (OrderView) et jamais les modeles internes.
|
||||||
|
*/
|
||||||
|
final class OhsApiTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_assembler_returns_order_view_contract(): void
|
||||||
|
{
|
||||||
|
$orderRepo = new InMemoryOrderRepository();
|
||||||
|
$clock = new SystemClock();
|
||||||
|
$assembler = new OrderViewAssembler();
|
||||||
|
|
||||||
|
// Create a stub publisher that does nothing
|
||||||
|
$publisher = new class implements \MiniShop\Sales\Application\Port\SalesEventPublisher {
|
||||||
|
public function publishOrderPlaced(\MiniShop\Sales\Domain\Event\OrderPlaced $event): void {}
|
||||||
|
public function publishOrderConfirmed(\MiniShop\Sales\Domain\Event\OrderConfirmed $event): void {}
|
||||||
|
public function publishOrderCancelled(\MiniShop\Sales\Domain\Event\OrderCancelled $event): void {}
|
||||||
|
};
|
||||||
|
|
||||||
|
$placeHandler = new PlaceOrderHandler($orderRepo, $publisher, $clock);
|
||||||
|
$getHandler = new GetOrderByIdHandler($orderRepo);
|
||||||
|
|
||||||
|
$orderId = 'ohs-test-001';
|
||||||
|
($placeHandler)(new PlaceOrder(
|
||||||
|
orderId: $orderId,
|
||||||
|
customerId: 'cust-001',
|
||||||
|
lines: [
|
||||||
|
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||||
|
],
|
||||||
|
));
|
||||||
|
|
||||||
|
$order = ($getHandler)(new GetOrderById($orderId));
|
||||||
|
$view = $assembler->toView($order);
|
||||||
|
|
||||||
|
// Verifie que le retour est un DTO du Published Language
|
||||||
|
self::assertInstanceOf(OrderView::class, $view);
|
||||||
|
self::assertSame($orderId, $view->orderId);
|
||||||
|
self::assertSame('placed', $view->status);
|
||||||
|
self::assertSame(3000, $view->totalInCents);
|
||||||
|
self::assertSame('EUR', $view->currency);
|
||||||
|
self::assertCount(1, $view->lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_order_view_does_not_expose_internal_model(): void
|
||||||
|
{
|
||||||
|
$assembler = new OrderViewAssembler();
|
||||||
|
$orderRepo = new InMemoryOrderRepository();
|
||||||
|
$clock = new SystemClock();
|
||||||
|
$publisher = new class implements \MiniShop\Sales\Application\Port\SalesEventPublisher {
|
||||||
|
public function publishOrderPlaced(\MiniShop\Sales\Domain\Event\OrderPlaced $event): void {}
|
||||||
|
public function publishOrderConfirmed(\MiniShop\Sales\Domain\Event\OrderConfirmed $event): void {}
|
||||||
|
public function publishOrderCancelled(\MiniShop\Sales\Domain\Event\OrderCancelled $event): void {}
|
||||||
|
};
|
||||||
|
|
||||||
|
($placeHandler = new PlaceOrderHandler($orderRepo, $publisher, $clock))(new PlaceOrder(
|
||||||
|
orderId: 'ohs-test-002',
|
||||||
|
customerId: 'cust-001',
|
||||||
|
lines: [['productName' => 'Widget', 'quantity' => 1, 'unitPriceInCents' => 1000, 'currency' => 'EUR']],
|
||||||
|
));
|
||||||
|
|
||||||
|
$order = (new GetOrderByIdHandler($orderRepo))(new GetOrderById('ohs-test-002'));
|
||||||
|
$view = $assembler->toView($order);
|
||||||
|
|
||||||
|
$json = json_encode($view, JSON_THROW_ON_ERROR);
|
||||||
|
$decoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
|
// Le JSON ne doit contenir que les champs du Published Language
|
||||||
|
$allowedKeys = ['orderId', 'customerId', 'status', 'totalInCents', 'currency', 'lines'];
|
||||||
|
self::assertSame($allowedKeys, array_keys($decoded));
|
||||||
|
|
||||||
|
// Les lignes ne doivent pas contenir de types internes (Money, OrderLine)
|
||||||
|
$lineKeys = array_keys($decoded['lines'][0]);
|
||||||
|
self::assertContains('productName', $lineKeys);
|
||||||
|
self::assertContains('lineTotalInCents', $lineKeys);
|
||||||
|
self::assertNotContains('unitPrice', $lineKeys); // pas d'objet Money
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Tests\Unit\LegacyFulfillment\Infrastructure\AntiCorruption;
|
||||||
|
|
||||||
|
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||||
|
use MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption\LegacyShipmentAcl;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests du mapping ACL : sales.v1.OrderConfirmed → LegacyCreateShipmentCommand.
|
||||||
|
*/
|
||||||
|
final class LegacyShipmentAclTest extends TestCase
|
||||||
|
{
|
||||||
|
private LegacyShipmentAcl $acl;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->acl = new LegacyShipmentAcl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_maps_order_ref_with_legacy_prefix(): void
|
||||||
|
{
|
||||||
|
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage());
|
||||||
|
|
||||||
|
self::assertStringStartsWith('LEG-', $command->ord_ref);
|
||||||
|
self::assertSame('LEG-order-acl-001', $command->ord_ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_truncates_recipient_name(): void
|
||||||
|
{
|
||||||
|
$message = new OrderConfirmed(
|
||||||
|
orderId: 'order-001',
|
||||||
|
customerId: 'very-long-customer-id-that-exceeds-thirty-five-characters-limit',
|
||||||
|
totalInCents: 1000,
|
||||||
|
currency: 'EUR',
|
||||||
|
lines: [['productName' => 'X', 'quantity' => 1, 'unitPriceInCents' => 1000, 'currency' => 'EUR']],
|
||||||
|
);
|
||||||
|
|
||||||
|
$command = $this->acl->fromSalesOrderConfirmed($message);
|
||||||
|
|
||||||
|
self::assertLessThanOrEqual(35, mb_strlen($command->rcpt_nm));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_calculates_weight_from_line_count(): void
|
||||||
|
{
|
||||||
|
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage(lineCount: 3));
|
||||||
|
|
||||||
|
self::assertSame(1500, $command->wgt_g); // 3 * 500g
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_minimum_weight_is_100g(): void
|
||||||
|
{
|
||||||
|
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage(lineCount: 0));
|
||||||
|
|
||||||
|
self::assertGreaterThanOrEqual(100, $command->wgt_g);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_status_is_new(): void
|
||||||
|
{
|
||||||
|
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage());
|
||||||
|
|
||||||
|
self::assertSame('NEW', $command->sts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_date_format_is_legacy_yyyymmdd(): void
|
||||||
|
{
|
||||||
|
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage());
|
||||||
|
|
||||||
|
self::assertMatchesRegularExpression('/^\d{8}$/', $command->req_dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_description_contains_order_ref_and_article_count(): void
|
||||||
|
{
|
||||||
|
$command = $this->acl->fromSalesOrderConfirmed($this->createMessage(lineCount: 2));
|
||||||
|
|
||||||
|
self::assertStringContainsString('CMD-', $command->desc);
|
||||||
|
self::assertStringContainsString('2 articles', $command->desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createMessage(int $lineCount = 1): OrderConfirmed
|
||||||
|
{
|
||||||
|
$lines = array_fill(0, $lineCount, [
|
||||||
|
'productName' => 'Widget',
|
||||||
|
'quantity' => 1,
|
||||||
|
'unitPriceInCents' => 1000,
|
||||||
|
'currency' => 'EUR',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return new OrderConfirmed(
|
||||||
|
orderId: 'order-acl-001',
|
||||||
|
customerId: 'cust-001',
|
||||||
|
totalInCents: $lineCount * 1000,
|
||||||
|
currency: 'EUR',
|
||||||
|
lines: $lines,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
tests/Unit/Shared/IdempotencyTest.php
Normal file
36
tests/Unit/Shared/IdempotencyTest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MiniShop\Tests\Unit\Shared;
|
||||||
|
|
||||||
|
use MiniShop\Shared\Technical\InMemoryIdempotencyStore;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class IdempotencyTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_first_call_is_not_duplicate(): void
|
||||||
|
{
|
||||||
|
$store = new InMemoryIdempotencyStore();
|
||||||
|
|
||||||
|
self::assertFalse($store->isDuplicate('key-1'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_second_call_is_duplicate(): void
|
||||||
|
{
|
||||||
|
$store = new InMemoryIdempotencyStore();
|
||||||
|
|
||||||
|
$store->isDuplicate('key-1');
|
||||||
|
|
||||||
|
self::assertTrue($store->isDuplicate('key-1'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_different_keys_are_independent(): void
|
||||||
|
{
|
||||||
|
$store = new InMemoryIdempotencyStore();
|
||||||
|
|
||||||
|
$store->isDuplicate('key-1');
|
||||||
|
|
||||||
|
self::assertFalse($store->isDuplicate('key-2'));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user