Files
DDDBoilerplate/tests/Integration/InvoicingConformistTest.php
Mathias STRASSER b356033f7b Step 05 — Hardening
- CorrelationId VO pour le tracing inter-BC
- IdempotencyStore (interface + InMemory) pour garde d'idempotence
- correlationId ajouté aux contrats Published Language (retro-compatible par défaut)
- Consumers Invoicing et LegacyFulfillment idempotents avec logging
- MessengerSalesEventPublisher propage les correlationIds
- Tests unitaires idempotence + tests d'intégration consommateurs idempotents
2026-03-04 00:35:20 +01:00

51 lines
1.8 KiB
PHP

<?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\InMemoryIdempotencyStore;
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(),
),
new InMemoryIdempotencyStore(),
);
$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);
}
}