Step 03 — ACL (LegacyFulfillment)
- LegacyShipmentAcl : mapping explicite sales.v1.OrderConfirmed → LegacyCreateShipmentCommand - LegacyCreateShipmentCommand : modèle legacy (champs abrégés, codification date/status) - WhenOrderConfirmed (LegacyFulfillment) : consumer Messenger via ACL - Tests unitaires mapping ACL + test d'intégration
This commit is contained in:
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