- Ajout Symfony Messenger comme bus d'intégration - MessengerSalesEventPublisher remplace le NaivePublisher pour dispatch via Messenger - WhenOrderConfirmed (Invoicing) : consumer Conformist qui consomme sales.v1.OrderConfirmed tel quel - Tests de compatibilité Conformist et intégration - Configuration Messenger avec transport sync
69 lines
2.7 KiB
PHP
69 lines
2.7 KiB
PHP
<?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);
|
|
}
|
|
}
|