Compare commits
3 Commits
step/00-na
...
step/03-ac
| Author | SHA1 | Date | |
|---|---|---|---|
| f8be8166b7 | |||
| dcc81ec9bb | |||
| 21b8f37411 |
11
apps/symfony/config/packages/messenger.yaml
Normal file
11
apps/symfony/config/packages/messenger.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
framework:
|
||||
messenger:
|
||||
default_bus: messenger.bus.default
|
||||
buses:
|
||||
messenger.bus.default: ~
|
||||
transports:
|
||||
sync: 'sync://'
|
||||
routing:
|
||||
'MiniShop\Contracts\Sales\V1\Event\OrderConfirmed': sync
|
||||
'MiniShop\Contracts\Sales\V1\Event\OrderPlaced': sync
|
||||
'MiniShop\Contracts\Sales\V1\Event\OrderCancelled': sync
|
||||
@@ -25,7 +25,7 @@ services:
|
||||
alias: MiniShop\Sales\Infrastructure\Persistence\InMemoryOrderRepository
|
||||
|
||||
MiniShop\Sales\Application\Port\SalesEventPublisher:
|
||||
alias: MiniShop\Sales\Infrastructure\Messaging\NaiveSalesEventPublisher
|
||||
alias: MiniShop\Sales\Infrastructure\Messaging\MessengerSalesEventPublisher
|
||||
|
||||
# --- Invoicing ---
|
||||
MiniShop\Invoicing\Application\:
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": ">=8.5",
|
||||
"symfony/framework-bundle": "^7.2",
|
||||
"symfony/console": "^7.2",
|
||||
"symfony/dotenv": "^7.2",
|
||||
"symfony/framework-bundle": "^7.2",
|
||||
"symfony/messenger": "^7.2",
|
||||
"symfony/yaml": "^7.2"
|
||||
},
|
||||
"require-dev": {
|
||||
@@ -19,7 +20,7 @@
|
||||
"MiniShop\\Invoicing\\": "src/Invoicing/",
|
||||
"MiniShop\\LegacyFulfillment\\": "src/LegacyFulfillment/",
|
||||
"MiniShop\\Shared\\": "src/Shared/",
|
||||
"MiniShop\\Contracts\\": "contracts/",
|
||||
"MiniShop\\Contracts\\Sales\\V1\\": "contracts/sales/v1/",
|
||||
"App\\": "apps/symfony/src/"
|
||||
}
|
||||
},
|
||||
|
||||
221
composer.lock
generated
221
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "cf876267ce49272867204aaa70702ed4",
|
||||
"content-hash": "1ad6323891b4f76eb1b6f55ff6741b32",
|
||||
"packages": [
|
||||
{
|
||||
"name": "psr/cache",
|
||||
@@ -55,6 +55,54 @@
|
||||
},
|
||||
"time": "2021-02-03T23:26:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/clock",
|
||||
"version": "1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/clock.git",
|
||||
"reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d",
|
||||
"reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0 || ^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Clock\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "https://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for reading the clock.",
|
||||
"homepage": "https://github.com/php-fig/clock",
|
||||
"keywords": [
|
||||
"clock",
|
||||
"now",
|
||||
"psr",
|
||||
"psr-20",
|
||||
"time"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/php-fig/clock/issues",
|
||||
"source": "https://github.com/php-fig/clock/tree/1.0.0"
|
||||
},
|
||||
"time": "2022-11-25T14:36:26+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "2.0.2",
|
||||
@@ -384,6 +432,83 @@
|
||||
],
|
||||
"time": "2025-03-13T15:25:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/clock",
|
||||
"version": "v8.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/clock.git",
|
||||
"reference": "832119f9b8dbc6c8e6f65f30c5969eca1e88764f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/clock/zipball/832119f9b8dbc6c8e6f65f30c5969eca1e88764f",
|
||||
"reference": "832119f9b8dbc6c8e6f65f30c5969eca1e88764f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.4",
|
||||
"psr/clock": "^1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/clock-implementation": "1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"Resources/now.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Clock\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Decouples applications from the system clock",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"clock",
|
||||
"psr20",
|
||||
"time"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/clock/tree/v8.0.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-11-12T15:46:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/config",
|
||||
"version": "v8.0.6",
|
||||
@@ -1508,6 +1633,100 @@
|
||||
],
|
||||
"time": "2026-02-26T08:36:42+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/messenger",
|
||||
"version": "v7.4.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/messenger.git",
|
||||
"reference": "9da6166eb98937d903ed3685b317b426c82d3496"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/messenger/zipball/9da6166eb98937d903ed3685b317b426c82d3496",
|
||||
"reference": "9da6166eb98937d903ed3685b317b426c82d3496",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.2",
|
||||
"psr/log": "^1|^2|^3",
|
||||
"symfony/clock": "^6.4|^7.0|^8.0",
|
||||
"symfony/deprecation-contracts": "^2.5|^3"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/console": "<7.2",
|
||||
"symfony/event-dispatcher": "<6.4",
|
||||
"symfony/event-dispatcher-contracts": "<2.5",
|
||||
"symfony/framework-bundle": "<6.4",
|
||||
"symfony/http-kernel": "<7.3",
|
||||
"symfony/lock": "<7.4",
|
||||
"symfony/serializer": "<6.4.32|>=7.3,<7.3.10|>=7.4,<7.4.4|>=8.0,<8.0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"psr/cache": "^1.0|^2.0|^3.0",
|
||||
"symfony/console": "^7.2|^8.0",
|
||||
"symfony/dependency-injection": "^6.4|^7.0|^8.0",
|
||||
"symfony/event-dispatcher": "^6.4|^7.0|^8.0",
|
||||
"symfony/http-kernel": "^7.3|^8.0",
|
||||
"symfony/lock": "^7.4|^8.0",
|
||||
"symfony/process": "^6.4|^7.0|^8.0",
|
||||
"symfony/property-access": "^6.4|^7.0|^8.0",
|
||||
"symfony/rate-limiter": "^6.4|^7.0|^8.0",
|
||||
"symfony/routing": "^6.4|^7.0|^8.0",
|
||||
"symfony/serializer": "^6.4.32|~7.3.10|^7.4.4|^8.0.4",
|
||||
"symfony/service-contracts": "^2.5|^3",
|
||||
"symfony/stopwatch": "^6.4|^7.0|^8.0",
|
||||
"symfony/validator": "^6.4|^7.0|^8.0",
|
||||
"symfony/var-dumper": "^6.4|^7.0|^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Messenger\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Samuel Roze",
|
||||
"email": "samuel.roze@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Helps applications send and receive messages to/from other applications or via message queues",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/messenger/tree/v7.4.6"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-02-25T16:50:00+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.33.0",
|
||||
|
||||
24
contracts/sales/v1/Api/OrderView.php
Normal file
24
contracts/sales/v1/Api/OrderView.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Contracts\Sales\V1\Api;
|
||||
|
||||
/**
|
||||
* Published Language — sales.v1.OrderView
|
||||
* DTO de consultation. Contrat immutable et versionne.
|
||||
*/
|
||||
final readonly class OrderView
|
||||
{
|
||||
/**
|
||||
* @param list<array{productName: string, quantity: int, unitPriceInCents: int, currency: string, lineTotalInCents: int}> $lines
|
||||
*/
|
||||
public function __construct(
|
||||
public string $orderId,
|
||||
public string $customerId,
|
||||
public string $status,
|
||||
public int $totalInCents,
|
||||
public string $currency,
|
||||
public array $lines,
|
||||
) {}
|
||||
}
|
||||
16
contracts/sales/v1/Event/OrderCancelled.php
Normal file
16
contracts/sales/v1/Event/OrderCancelled.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Contracts\Sales\V1\Event;
|
||||
|
||||
/**
|
||||
* Published Language — sales.v1.OrderCancelled
|
||||
* Contrat immutable et versionne. Ne jamais modifier les champs existants.
|
||||
*/
|
||||
final readonly class OrderCancelled
|
||||
{
|
||||
public function __construct(
|
||||
public string $orderId,
|
||||
) {}
|
||||
}
|
||||
23
contracts/sales/v1/Event/OrderConfirmed.php
Normal file
23
contracts/sales/v1/Event/OrderConfirmed.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Contracts\Sales\V1\Event;
|
||||
|
||||
/**
|
||||
* Published Language — sales.v1.OrderConfirmed
|
||||
* Contrat immutable et versionne. Ne jamais modifier les champs existants.
|
||||
*/
|
||||
final readonly class OrderConfirmed
|
||||
{
|
||||
/**
|
||||
* @param list<array{productName: string, quantity: int, unitPriceInCents: int, currency: string}> $lines
|
||||
*/
|
||||
public function __construct(
|
||||
public string $orderId,
|
||||
public string $customerId,
|
||||
public int $totalInCents,
|
||||
public string $currency,
|
||||
public array $lines,
|
||||
) {}
|
||||
}
|
||||
24
contracts/sales/v1/Event/OrderPlaced.php
Normal file
24
contracts/sales/v1/Event/OrderPlaced.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Contracts\Sales\V1\Event;
|
||||
|
||||
/**
|
||||
* Published Language — sales.v1.OrderPlaced
|
||||
* Contrat immutable et versionne. Ne jamais modifier les champs existants.
|
||||
*/
|
||||
final readonly class OrderPlaced
|
||||
{
|
||||
/**
|
||||
* @param list<array{productName: string, quantity: int, unitPriceInCents: int, currency: string}> $lines
|
||||
*/
|
||||
public function __construct(
|
||||
public string $orderId,
|
||||
public string $customerId,
|
||||
public int $totalInCents,
|
||||
public string $currency,
|
||||
public string $placedAt,
|
||||
public array $lines,
|
||||
) {}
|
||||
}
|
||||
40
src/Invoicing/Interfaces/Messaging/WhenOrderConfirmed.php
Normal file
40
src/Invoicing/Interfaces/Messaging/WhenOrderConfirmed.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Invoicing\Interfaces\Messaging;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrder;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
/**
|
||||
* Conformist : Invoicing consomme le contrat sales.v1.OrderConfirmed tel quel,
|
||||
* sans traduction. La dependance upstream est explicite.
|
||||
*/
|
||||
#[AsMessageHandler]
|
||||
final readonly class WhenOrderConfirmed
|
||||
{
|
||||
public function __construct(
|
||||
private IssueInvoiceForExternalOrderHandler $handler,
|
||||
) {}
|
||||
|
||||
public function __invoke(OrderConfirmed $message): void
|
||||
{
|
||||
($this->handler)(new IssueInvoiceForExternalOrder(
|
||||
externalOrderId: $message->orderId,
|
||||
customerName: 'Customer ' . $message->customerId,
|
||||
customerAddress: 'N/A',
|
||||
lines: array_map(
|
||||
static fn (array $line): array => [
|
||||
'description' => $line['productName'],
|
||||
'quantity' => $line['quantity'],
|
||||
'unitPriceInCents' => $line['unitPriceInCents'],
|
||||
'currency' => $line['currency'],
|
||||
],
|
||||
$message->lines,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -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,40 @@
|
||||
<?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 Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
/**
|
||||
* Consumer ACL : recoit sales.v1.OrderConfirmed, passe par l'Anti-Corruption Layer
|
||||
* pour traduire vers le modele legacy, puis delegue au handler applicatif.
|
||||
*/
|
||||
#[AsMessageHandler]
|
||||
final readonly class WhenOrderConfirmed
|
||||
{
|
||||
public function __construct(
|
||||
private LegacyShipmentAcl $acl,
|
||||
private RequestShipmentFromSalesOrderHandler $handler,
|
||||
) {}
|
||||
|
||||
public function __invoke(OrderConfirmed $message): void
|
||||
{
|
||||
$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,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Sales\Infrastructure\Messaging;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderCancelled as OrderCancelledContract;
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed as OrderConfirmedContract;
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderPlaced as OrderPlacedContract;
|
||||
use MiniShop\Sales\Application\Port\SalesEventPublisher;
|
||||
use MiniShop\Sales\Domain\Event\OrderCancelled;
|
||||
use MiniShop\Sales\Domain\Event\OrderConfirmed;
|
||||
use MiniShop\Sales\Domain\Event\OrderPlaced;
|
||||
use MiniShop\Sales\Domain\Model\OrderLine;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
/**
|
||||
* Publie les evenements de domaine Sales sous forme de contrats Published Language
|
||||
* via Symfony Messenger. Remplace le NaiveSalesEventPublisher.
|
||||
*/
|
||||
final readonly class MessengerSalesEventPublisher implements SalesEventPublisher
|
||||
{
|
||||
public function __construct(
|
||||
private MessageBusInterface $messageBus,
|
||||
) {}
|
||||
|
||||
public function publishOrderPlaced(OrderPlaced $event): void
|
||||
{
|
||||
$this->messageBus->dispatch(new OrderPlacedContract(
|
||||
orderId: $event->orderId->toString(),
|
||||
customerId: $event->customerId->toString(),
|
||||
totalInCents: $event->total->amount,
|
||||
currency: $event->total->currency,
|
||||
placedAt: $event->placedAt->format(\DateTimeInterface::ATOM),
|
||||
lines: [],
|
||||
));
|
||||
}
|
||||
|
||||
public function publishOrderConfirmed(OrderConfirmed $event): void
|
||||
{
|
||||
$this->messageBus->dispatch(new OrderConfirmedContract(
|
||||
orderId: $event->orderId->toString(),
|
||||
customerId: $event->customerId->toString(),
|
||||
totalInCents: $event->total->amount,
|
||||
currency: $event->total->currency,
|
||||
lines: array_map(
|
||||
static fn (OrderLine $line): array => [
|
||||
'productName' => $line->productName,
|
||||
'quantity' => $line->quantity,
|
||||
'unitPriceInCents' => $line->unitPrice->amount,
|
||||
'currency' => $line->unitPrice->currency,
|
||||
],
|
||||
$event->lines,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function publishOrderCancelled(OrderCancelled $event): void
|
||||
{
|
||||
$this->messageBus->dispatch(new OrderCancelledContract(
|
||||
orderId: $event->orderId->toString(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Sales\Infrastructure\Messaging;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed as OrderConfirmedContract;
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderPlaced as OrderPlacedContract;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrder;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
||||
use MiniShop\LegacyFulfillment\Application\Command\RequestShipmentFromSalesOrder;
|
||||
@@ -16,7 +18,7 @@ use MiniShop\Sales\Domain\Model\OrderLine;
|
||||
|
||||
/**
|
||||
* Couplage naif : Sales appelle directement les handlers des autres BC.
|
||||
* Ce couplage sera supprime dans les episodes suivants (Published Language, Conformist, ACL).
|
||||
* Depuis step/01, la traduction passe par le Published Language (contracts/sales/v1).
|
||||
*/
|
||||
final readonly class NaiveSalesEventPublisher implements SalesEventPublisher
|
||||
{
|
||||
@@ -27,42 +29,78 @@ final readonly class NaiveSalesEventPublisher implements SalesEventPublisher
|
||||
|
||||
public function publishOrderPlaced(OrderPlaced $event): void
|
||||
{
|
||||
// Pas d'action downstream sur OrderPlaced dans le scenario naif.
|
||||
}
|
||||
|
||||
public function publishOrderConfirmed(OrderConfirmed $event): void
|
||||
{
|
||||
// Appel direct vers Invoicing — couplage naif
|
||||
($this->issueInvoiceHandler)(new IssueInvoiceForExternalOrder(
|
||||
externalOrderId: $event->orderId->toString(),
|
||||
customerName: 'Customer ' . $event->customerId->toString(),
|
||||
customerAddress: 'N/A',
|
||||
// Traduction domaine → Published Language (pour reference)
|
||||
new OrderPlacedContract(
|
||||
orderId: $event->orderId->toString(),
|
||||
customerId: $event->customerId->toString(),
|
||||
totalInCents: $event->total->amount,
|
||||
currency: $event->total->currency,
|
||||
placedAt: $event->placedAt->format(\DateTimeInterface::ATOM),
|
||||
lines: array_map(
|
||||
static fn (OrderLine $line): array => [
|
||||
'description' => $line->productName,
|
||||
'productName' => $line->productName,
|
||||
'quantity' => $line->quantity,
|
||||
'unitPriceInCents' => $line->unitPrice->amount,
|
||||
'currency' => $line->unitPrice->currency,
|
||||
],
|
||||
$event->lines,
|
||||
[], // OrderPlaced doesn't carry lines in this version
|
||||
),
|
||||
);
|
||||
// Pas d'action downstream sur OrderPlaced.
|
||||
}
|
||||
|
||||
public function publishOrderConfirmed(OrderConfirmed $event): void
|
||||
{
|
||||
$lines = array_map(
|
||||
static fn (OrderLine $line): array => [
|
||||
'productName' => $line->productName,
|
||||
'quantity' => $line->quantity,
|
||||
'unitPriceInCents' => $line->unitPrice->amount,
|
||||
'currency' => $line->unitPrice->currency,
|
||||
],
|
||||
$event->lines,
|
||||
);
|
||||
|
||||
// Step 01 : traduction domaine → Published Language
|
||||
$message = new OrderConfirmedContract(
|
||||
orderId: $event->orderId->toString(),
|
||||
customerId: $event->customerId->toString(),
|
||||
totalInCents: $event->total->amount,
|
||||
currency: $event->total->currency,
|
||||
lines: $lines,
|
||||
);
|
||||
|
||||
// Appel direct vers Invoicing — toujours naif mais via Published Language
|
||||
($this->issueInvoiceHandler)(new IssueInvoiceForExternalOrder(
|
||||
externalOrderId: $message->orderId,
|
||||
customerName: 'Customer ' . $message->customerId,
|
||||
customerAddress: 'N/A',
|
||||
lines: array_map(
|
||||
static fn (array $line): array => [
|
||||
'description' => $line['productName'],
|
||||
'quantity' => $line['quantity'],
|
||||
'unitPriceInCents' => $line['unitPriceInCents'],
|
||||
'currency' => $line['currency'],
|
||||
],
|
||||
$message->lines,
|
||||
),
|
||||
));
|
||||
|
||||
// Appel direct vers LegacyFulfillment — couplage naif
|
||||
// Appel direct vers LegacyFulfillment — toujours naif mais via Published Language
|
||||
($this->requestShipmentHandler)(new RequestShipmentFromSalesOrder(
|
||||
externalOrderId: $event->orderId->toString(),
|
||||
recipientName: 'Customer ' . $event->customerId->toString(),
|
||||
externalOrderId: $message->orderId,
|
||||
recipientName: 'Customer ' . $message->customerId,
|
||||
street: '1 Rue du Commerce',
|
||||
city: 'Paris',
|
||||
postalCode: '75001',
|
||||
country: 'FR',
|
||||
totalWeightInGrams: 1000,
|
||||
description: sprintf('Order %s', $event->orderId->toString()),
|
||||
description: sprintf('Order %s', $message->orderId),
|
||||
));
|
||||
}
|
||||
|
||||
public function publishOrderCancelled(OrderCancelled $event): void
|
||||
{
|
||||
// Pas d'action downstream sur OrderCancelled dans le scenario naif.
|
||||
// Pas d'action downstream sur OrderCancelled.
|
||||
}
|
||||
}
|
||||
|
||||
68
tests/Contract/Sales/v1/ConformistCompatibilityTest.php
Normal file
68
tests/Contract/Sales/v1/ConformistCompatibilityTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Tests\Contract\Sales\v1;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrder;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
||||
use MiniShop\Invoicing\Infrastructure\Persistence\InMemoryInvoiceRepository;
|
||||
use MiniShop\Invoicing\Infrastructure\SequentialInvoiceNumberGenerator;
|
||||
use MiniShop\Invoicing\Interfaces\Messaging\WhenOrderConfirmed;
|
||||
use MiniShop\Shared\Technical\SystemClock;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test de compatibilite Conformist : Invoicing consomme sales.v1.OrderConfirmed
|
||||
* tel quel, sans traduction. Toute evolution du schema upstream doit rester
|
||||
* compatible avec ce consommateur.
|
||||
*/
|
||||
final class ConformistCompatibilityTest extends TestCase
|
||||
{
|
||||
public function test_invoicing_can_consume_order_confirmed_v1(): void
|
||||
{
|
||||
$invoiceRepo = new InMemoryInvoiceRepository();
|
||||
$handler = new IssueInvoiceForExternalOrderHandler(
|
||||
$invoiceRepo,
|
||||
new SequentialInvoiceNumberGenerator(),
|
||||
new SystemClock(),
|
||||
);
|
||||
$consumer = new WhenOrderConfirmed($handler);
|
||||
|
||||
$message = new OrderConfirmed(
|
||||
orderId: 'order-conformist-001',
|
||||
customerId: 'cust-001',
|
||||
totalInCents: 3000,
|
||||
currency: 'EUR',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||
],
|
||||
);
|
||||
|
||||
$consumer($message);
|
||||
|
||||
$invoice = $invoiceRepo->findByExternalOrderId('order-conformist-001');
|
||||
self::assertNotNull($invoice, 'Invoicing (Conformist) must be able to consume sales.v1.OrderConfirmed.');
|
||||
self::assertSame('order-conformist-001', $invoice->externalOrderId);
|
||||
self::assertCount(1, $invoice->lines());
|
||||
}
|
||||
|
||||
public function test_schema_backward_compatible_with_extra_fields(): void
|
||||
{
|
||||
// Simule un schema upstream avec un champ supplementaire (retro-compatible)
|
||||
$json = '{"orderId":"order-002","customerId":"cust-002","totalInCents":5000,"currency":"EUR","lines":[{"productName":"Gadget","quantity":1,"unitPriceInCents":5000,"currency":"EUR"}],"newField":"ignored"}';
|
||||
$decoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
|
||||
|
||||
$message = new OrderConfirmed(
|
||||
orderId: $decoded['orderId'],
|
||||
customerId: $decoded['customerId'],
|
||||
totalInCents: $decoded['totalInCents'],
|
||||
currency: $decoded['currency'],
|
||||
lines: $decoded['lines'],
|
||||
);
|
||||
|
||||
self::assertSame('order-002', $message->orderId);
|
||||
self::assertSame(5000, $message->totalInCents);
|
||||
}
|
||||
}
|
||||
78
tests/Contract/Sales/v1/OrderConfirmedSchemaTest.php
Normal file
78
tests/Contract/Sales/v1/OrderConfirmedSchemaTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Tests\Contract\Sales\v1;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests de stabilite du contrat sales.v1.OrderConfirmed.
|
||||
*/
|
||||
final class OrderConfirmedSchemaTest extends TestCase
|
||||
{
|
||||
public function test_contract_has_required_fields(): void
|
||||
{
|
||||
$event = new OrderConfirmed(
|
||||
orderId: 'order-001',
|
||||
customerId: 'cust-001',
|
||||
totalInCents: 5500,
|
||||
currency: 'EUR',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||
['productName' => 'Gadget', 'quantity' => 1, 'unitPriceInCents' => 2500, 'currency' => 'EUR'],
|
||||
],
|
||||
);
|
||||
|
||||
self::assertSame('order-001', $event->orderId);
|
||||
self::assertSame('cust-001', $event->customerId);
|
||||
self::assertSame(5500, $event->totalInCents);
|
||||
self::assertSame('EUR', $event->currency);
|
||||
self::assertCount(2, $event->lines);
|
||||
}
|
||||
|
||||
public function test_contract_serializes_to_stable_json(): void
|
||||
{
|
||||
$event = new OrderConfirmed(
|
||||
orderId: 'order-001',
|
||||
customerId: 'cust-001',
|
||||
totalInCents: 5500,
|
||||
currency: 'EUR',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||
],
|
||||
);
|
||||
|
||||
$json = json_encode($event, JSON_THROW_ON_ERROR);
|
||||
$decoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertArrayHasKey('orderId', $decoded);
|
||||
self::assertArrayHasKey('customerId', $decoded);
|
||||
self::assertArrayHasKey('totalInCents', $decoded);
|
||||
self::assertArrayHasKey('currency', $decoded);
|
||||
self::assertArrayHasKey('lines', $decoded);
|
||||
}
|
||||
|
||||
public function test_lines_contain_required_fields(): void
|
||||
{
|
||||
$event = new OrderConfirmed(
|
||||
orderId: 'order-001',
|
||||
customerId: 'cust-001',
|
||||
totalInCents: 3000,
|
||||
currency: 'EUR',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||
],
|
||||
);
|
||||
|
||||
$json = json_encode($event, JSON_THROW_ON_ERROR);
|
||||
$decoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
|
||||
$line = $decoded['lines'][0];
|
||||
|
||||
self::assertArrayHasKey('productName', $line);
|
||||
self::assertArrayHasKey('quantity', $line);
|
||||
self::assertArrayHasKey('unitPriceInCents', $line);
|
||||
self::assertArrayHasKey('currency', $line);
|
||||
}
|
||||
}
|
||||
79
tests/Contract/Sales/v1/OrderPlacedSchemaTest.php
Normal file
79
tests/Contract/Sales/v1/OrderPlacedSchemaTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Tests\Contract\Sales\v1;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderPlaced;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests de stabilite du contrat sales.v1.OrderPlaced.
|
||||
* Garantit que le schema est stable et ne casse pas les consommateurs downstream.
|
||||
*/
|
||||
final class OrderPlacedSchemaTest extends TestCase
|
||||
{
|
||||
public function test_contract_has_required_fields(): void
|
||||
{
|
||||
$event = new OrderPlaced(
|
||||
orderId: 'order-001',
|
||||
customerId: 'cust-001',
|
||||
totalInCents: 3000,
|
||||
currency: 'EUR',
|
||||
placedAt: '2026-01-15T10:30:00+00:00',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||
],
|
||||
);
|
||||
|
||||
self::assertSame('order-001', $event->orderId);
|
||||
self::assertSame('cust-001', $event->customerId);
|
||||
self::assertSame(3000, $event->totalInCents);
|
||||
self::assertSame('EUR', $event->currency);
|
||||
self::assertSame('2026-01-15T10:30:00+00:00', $event->placedAt);
|
||||
self::assertCount(1, $event->lines);
|
||||
}
|
||||
|
||||
public function test_contract_serializes_to_stable_json(): void
|
||||
{
|
||||
$event = new OrderPlaced(
|
||||
orderId: 'order-001',
|
||||
customerId: 'cust-001',
|
||||
totalInCents: 3000,
|
||||
currency: 'EUR',
|
||||
placedAt: '2026-01-15T10:30:00+00:00',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||
],
|
||||
);
|
||||
|
||||
$json = json_encode($event, JSON_THROW_ON_ERROR);
|
||||
$decoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertArrayHasKey('orderId', $decoded);
|
||||
self::assertArrayHasKey('customerId', $decoded);
|
||||
self::assertArrayHasKey('totalInCents', $decoded);
|
||||
self::assertArrayHasKey('currency', $decoded);
|
||||
self::assertArrayHasKey('placedAt', $decoded);
|
||||
self::assertArrayHasKey('lines', $decoded);
|
||||
}
|
||||
|
||||
public function test_contract_deserializes_from_json(): void
|
||||
{
|
||||
$json = '{"orderId":"order-001","customerId":"cust-001","totalInCents":3000,"currency":"EUR","placedAt":"2026-01-15T10:30:00+00:00","lines":[{"productName":"Widget","quantity":2,"unitPriceInCents":1500,"currency":"EUR"}]}';
|
||||
|
||||
$decoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
|
||||
|
||||
$event = new OrderPlaced(
|
||||
orderId: $decoded['orderId'],
|
||||
customerId: $decoded['customerId'],
|
||||
totalInCents: $decoded['totalInCents'],
|
||||
currency: $decoded['currency'],
|
||||
placedAt: $decoded['placedAt'],
|
||||
lines: $decoded['lines'],
|
||||
);
|
||||
|
||||
self::assertSame('order-001', $event->orderId);
|
||||
self::assertSame(3000, $event->totalInCents);
|
||||
}
|
||||
}
|
||||
57
tests/Contract/Sales/v1/OrderViewSchemaTest.php
Normal file
57
tests/Contract/Sales/v1/OrderViewSchemaTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Tests\Contract\Sales\v1;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Api\OrderView;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests de stabilite du contrat sales.v1.OrderView.
|
||||
*/
|
||||
final class OrderViewSchemaTest extends TestCase
|
||||
{
|
||||
public function test_contract_has_required_fields(): void
|
||||
{
|
||||
$view = new OrderView(
|
||||
orderId: 'order-001',
|
||||
customerId: 'cust-001',
|
||||
status: 'confirmed',
|
||||
totalInCents: 5500,
|
||||
currency: 'EUR',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR', 'lineTotalInCents' => 3000],
|
||||
],
|
||||
);
|
||||
|
||||
self::assertSame('order-001', $view->orderId);
|
||||
self::assertSame('confirmed', $view->status);
|
||||
self::assertSame(5500, $view->totalInCents);
|
||||
self::assertCount(1, $view->lines);
|
||||
}
|
||||
|
||||
public function test_contract_serializes_to_stable_json(): void
|
||||
{
|
||||
$view = new OrderView(
|
||||
orderId: 'order-001',
|
||||
customerId: 'cust-001',
|
||||
status: 'placed',
|
||||
totalInCents: 3000,
|
||||
currency: 'EUR',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR', 'lineTotalInCents' => 3000],
|
||||
],
|
||||
);
|
||||
|
||||
$json = json_encode($view, JSON_THROW_ON_ERROR);
|
||||
$decoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertArrayHasKey('orderId', $decoded);
|
||||
self::assertArrayHasKey('customerId', $decoded);
|
||||
self::assertArrayHasKey('status', $decoded);
|
||||
self::assertArrayHasKey('totalInCents', $decoded);
|
||||
self::assertArrayHasKey('currency', $decoded);
|
||||
self::assertArrayHasKey('lines', $decoded);
|
||||
}
|
||||
}
|
||||
48
tests/Integration/InvoicingConformistTest.php
Normal file
48
tests/Integration/InvoicingConformistTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Tests\Integration;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||
use MiniShop\Invoicing\Infrastructure\Persistence\InMemoryInvoiceRepository;
|
||||
use MiniShop\Invoicing\Infrastructure\SequentialInvoiceNumberGenerator;
|
||||
use MiniShop\Invoicing\Interfaces\Messaging\WhenOrderConfirmed;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
||||
use MiniShop\Shared\Technical\SystemClock;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test d'integration : le consumer Conformist d'Invoicing recoit un message
|
||||
* sales.v1.OrderConfirmed et cree une facture sans traduction.
|
||||
*/
|
||||
final class InvoicingConformistTest extends TestCase
|
||||
{
|
||||
public function test_invoicing_creates_invoice_on_order_confirmed(): void
|
||||
{
|
||||
$invoiceRepo = new InMemoryInvoiceRepository();
|
||||
$consumer = new WhenOrderConfirmed(
|
||||
new IssueInvoiceForExternalOrderHandler(
|
||||
$invoiceRepo,
|
||||
new SequentialInvoiceNumberGenerator(),
|
||||
new SystemClock(),
|
||||
),
|
||||
);
|
||||
|
||||
$consumer(new OrderConfirmed(
|
||||
orderId: 'order-int-001',
|
||||
customerId: 'cust-001',
|
||||
totalInCents: 4500,
|
||||
currency: 'EUR',
|
||||
lines: [
|
||||
['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||
['productName' => 'Gadget', 'quantity' => 1, 'unitPriceInCents' => 1500, 'currency' => 'EUR'],
|
||||
],
|
||||
));
|
||||
|
||||
$invoice = $invoiceRepo->findByExternalOrderId('order-int-001');
|
||||
self::assertNotNull($invoice);
|
||||
self::assertCount(2, $invoice->lines());
|
||||
self::assertSame('INV-000001', $invoice->invoiceNumber);
|
||||
}
|
||||
}
|
||||
47
tests/Integration/LegacyFulfillmentAclTest.php
Normal file
47
tests/Integration/LegacyFulfillmentAclTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\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()),
|
||||
);
|
||||
|
||||
$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());
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user