Step 00 — Squelette + intégration naïve
3 Bounded Contexts (Sales, Invoicing, LegacyFulfillment) avec : - Domaines complets (agrégats, VOs, événements, invariants) - Couche application (commands, queries, ports) - Infrastructure in-memory (repos, gateway fake) - Controllers HTTP Symfony - Couplage naïf synchrone entre BC via NaiveSalesEventPublisher - 20 tests unitaires et d'intégration passants
This commit is contained in:
68
tests/Unit/LegacyFulfillment/Domain/ShipmentRequestTest.php
Normal file
68
tests/Unit/LegacyFulfillment/Domain/ShipmentRequestTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Tests\Unit\LegacyFulfillment\Domain;
|
||||
|
||||
use MiniShop\LegacyFulfillment\Domain\Event\ShipmentRequested;
|
||||
use MiniShop\LegacyFulfillment\Domain\Model\LegacyOrderRef;
|
||||
use MiniShop\LegacyFulfillment\Domain\Model\ParcelSpec;
|
||||
use MiniShop\LegacyFulfillment\Domain\Model\ShipmentRequest;
|
||||
use MiniShop\LegacyFulfillment\Domain\Model\ShipmentStatus;
|
||||
use MiniShop\LegacyFulfillment\Domain\Model\ShippingAddress;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ShipmentRequestTest extends TestCase
|
||||
{
|
||||
public function test_create_from_sales_order(): void
|
||||
{
|
||||
$request = $this->createRequest();
|
||||
|
||||
self::assertSame(ShipmentStatus::Requested, $request->status());
|
||||
self::assertSame('order-1', $request->orderRef->toString());
|
||||
}
|
||||
|
||||
public function test_create_records_event(): void
|
||||
{
|
||||
$request = $this->createRequest();
|
||||
|
||||
$events = $request->releaseEvents();
|
||||
self::assertCount(1, $events);
|
||||
self::assertInstanceOf(ShipmentRequested::class, $events[0]);
|
||||
}
|
||||
|
||||
public function test_mark_dispatched(): void
|
||||
{
|
||||
$request = $this->createRequest();
|
||||
|
||||
$request->markDispatched();
|
||||
|
||||
self::assertSame(ShipmentStatus::Dispatched, $request->status());
|
||||
}
|
||||
|
||||
public function test_mark_dispatched_twice_throws(): void
|
||||
{
|
||||
$this->expectException(\DomainException::class);
|
||||
|
||||
$request = $this->createRequest();
|
||||
$request->markDispatched();
|
||||
$request->markDispatched();
|
||||
}
|
||||
|
||||
public function test_parcel_with_zero_weight_throws(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
new ParcelSpec(0, 'Widget');
|
||||
}
|
||||
|
||||
private function createRequest(): ShipmentRequest
|
||||
{
|
||||
return ShipmentRequest::fromSalesOrder(
|
||||
LegacyOrderRef::fromExternalId('order-1'),
|
||||
new ShippingAddress('John Doe', '1 Rue du Commerce', 'Paris', '75001', 'FR'),
|
||||
new ParcelSpec(1000, 'Order order-1'),
|
||||
new \DateTimeImmutable(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user