ConfirmOrder -> Invoice + Shipment. * Illustre le couplage direct entre BC (episode 00). */ final class NaiveWorkflowTest extends TestCase { public function test_full_naive_workflow(): void { // --- Setup : cablage naif synchrone --- $clock = new SystemClock(); $orderRepo = new InMemoryOrderRepository(); $invoiceRepo = new InMemoryInvoiceRepository(); $shipmentRepo = new InMemoryShipmentRequestRepository(); $gateway = new FakeLegacyFulfillmentGateway(); $issueInvoiceHandler = new IssueInvoiceForExternalOrderHandler( $invoiceRepo, new SequentialInvoiceNumberGenerator(), $clock, ); $requestShipmentHandler = new RequestShipmentFromSalesOrderHandler( $shipmentRepo, $gateway, $clock, ); $publisher = new NaiveSalesEventPublisher($issueInvoiceHandler, $requestShipmentHandler); $placeOrderHandler = new PlaceOrderHandler($orderRepo, $publisher, $clock); $confirmOrderHandler = new ConfirmOrderHandler($orderRepo, $publisher); $orderId = 'test-order-001'; // --- Act : passer et confirmer une commande --- ($placeOrderHandler)(new PlaceOrder( orderId: $orderId, customerId: 'cust-001', lines: [ ['productName' => 'Widget', 'quantity' => 2, 'unitPriceInCents' => 1500, 'currency' => 'EUR'], ['productName' => 'Gadget', 'quantity' => 1, 'unitPriceInCents' => 2500, 'currency' => 'EUR'], ], )); ($confirmOrderHandler)(new ConfirmOrder(orderId: $orderId)); // --- Assert : ordre confirme --- $order = $orderRepo->get(OrderId::fromString($orderId)); self::assertSame(OrderStatus::Confirmed, $order->status()); // --- Assert : facture creee --- $invoice = $invoiceRepo->findByExternalOrderId($orderId); self::assertNotNull($invoice, 'An invoice should have been created for the confirmed order.'); self::assertSame($orderId, $invoice->externalOrderId); self::assertCount(2, $invoice->lines()); // --- Assert : expedition demandee --- $shipment = $shipmentRepo->findByOrderRef(LegacyOrderRef::fromExternalId($orderId)); self::assertNotNull($shipment, 'A shipment request should have been created.'); self::assertSame(ShipmentStatus::Requested, $shipment->status()); // --- Assert : gateway legacy appele --- self::assertCount(1, $gateway->sentRequests()); } }