diff --git a/app/Casts/OrderReferenceCast.php b/app/Casts/OrderReferenceCast.php index 828ccec2..3a741309 100644 --- a/app/Casts/OrderReferenceCast.php +++ b/app/Casts/OrderReferenceCast.php @@ -6,6 +6,7 @@ namespace App\Casts; use Domain\Models\ValueObjects\OrderReference; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; +use Ramsey\Uuid\Uuid; /** * @implements CastsAttributes @@ -19,17 +20,16 @@ class OrderReferenceCast implements CastsAttributes throw new \UnexpectedValueException('OrderReference cannot be null.'); } - return new OrderReference($value); + return new OrderReference(Uuid::fromString($value)); } /** @param array $attributes */ public function set($model, string $key, $value, array $attributes): string { - if (! $value instanceof OrderReference) { throw new \UnexpectedValueException('The given value is not an instance of OrderReference.'); } - return $value->value; + return $value->value->toString(); } } diff --git a/app/Http/Controllers/Fo/TunnelController.php b/app/Http/Controllers/Fo/TunnelController.php index 68f29a50..b10bf74d 100644 --- a/app/Http/Controllers/Fo/TunnelController.php +++ b/app/Http/Controllers/Fo/TunnelController.php @@ -143,7 +143,7 @@ class TunnelController extends Controller return back()->with('message', $e->getMessage()); } - return to_route('fo.sales.confirmation.show-confirmed', $orderReference->value); + return to_route('fo.sales.confirmation.show-confirmed', (string) $orderReference); } // * -- CONFIRMATION -- * diff --git a/app/Providers/DomainServiceProvider.php b/app/Providers/DomainServiceProvider.php index dcd570bc..25d4bbd1 100644 --- a/app/Providers/DomainServiceProvider.php +++ b/app/Providers/DomainServiceProvider.php @@ -17,7 +17,6 @@ use Domain\Ports\Services\CustomerAuthenticationService; use Domain\Ports\Services\EmployeeImportStorageService; use Domain\Ports\Services\EmployeeStatisticsService; use Domain\Ports\Services\TransactionManager; -use Domain\Ports\Services\UuidConverter; use Illuminate\Support\ServiceProvider; use Infrastructure\Adapters\Directories\EloquentCodeDirectory; use Infrastructure\Adapters\Directories\EloquentShopDirectory; @@ -33,7 +32,6 @@ use Infrastructure\Adapters\Services\AppCustomerAuthService; use Infrastructure\Adapters\Services\EloquentEmployeeImportStorageService; use Infrastructure\Adapters\Services\EloquentEmployeeStatisticsService; use Infrastructure\Adapters\Services\LaravelTransactionManager; -use Infrastructure\Adapters\Services\UuidConverterImpl; use Shared\DDD\DomainEventDispatcher; class DomainServiceProvider extends ServiceProvider @@ -113,11 +111,6 @@ class DomainServiceProvider extends ServiceProvider EmployeeImportStorageService::class, EloquentEmployeeImportStorageService::class ); - - $this->app->bind( - UuidConverter::class, - UuidConverterImpl::class - ); } /** diff --git a/domain/Models/ValueObjects/OrderReference.php b/domain/Models/ValueObjects/OrderReference.php index 46c7ec8f..00a4e682 100644 --- a/domain/Models/ValueObjects/OrderReference.php +++ b/domain/Models/ValueObjects/OrderReference.php @@ -4,37 +4,22 @@ declare(strict_types=1); namespace Domain\Models\ValueObjects; -use Symfony\Component\Uid\Uuid; -use Symfony\Component\Uid\UuidV7; +use Ramsey\Uuid\UuidInterface; +use Shared\Helpers\UuidHelper; final readonly class OrderReference implements \Stringable { public function __construct( - public string $value + public UuidInterface $value ) { - $value = trim($value); - - if (empty($value)) { - throw new \DomainException('Order reference cannot be empty'); - } - - if (! preg_match('/^[1-9A-HJ-NP-Za-km-z]{21,22}$/', $value)) { - throw new \DomainException('Order reference must be a valid base-58 string of 21 or 22 characters'); - } - - try { - $uuid = Uuid::fromBase58($value); - if (get_class($uuid) !== UuidV7::class) { - throw new \DomainException('Order reference must be generated from a UUID v7'); - } - } catch (\InvalidArgumentException $e) { - throw new \DomainException('Order reference must be a valid base-58 string'); + if (! UuidHelper::isV7($value)) { + throw new \DomainException('value must be a valid UUID v7'); } } #[\Override] public function __toString(): string { - return $this->value; + return $this->value->toString(); } } diff --git a/domain/Ports/Services/UuidConverter.php b/domain/Ports/Services/UuidConverter.php deleted file mode 100644 index e3bef2e4..00000000 --- a/domain/Ports/Services/UuidConverter.php +++ /dev/null @@ -1,14 +0,0 @@ -uuidConverter->toBase58( - Uuid::uuid7() - ) - ); + return new OrderReference(Uuid::uuid7()); } public function cancelOrder(OrderId $id): void diff --git a/domain/Services/RegateService.php b/domain/Services/RegateService.php index 46adb105..214f526a 100644 --- a/domain/Services/RegateService.php +++ b/domain/Services/RegateService.php @@ -58,7 +58,7 @@ class RegateService '', $pickupDay->format('d/m/Y'), (string) $line->quantity, - $reference->value, + (string) $reference, ] ); } diff --git a/infra/Adapters/Services/UuidConverterImpl.php b/infra/Adapters/Services/UuidConverterImpl.php deleted file mode 100644 index 3eee1e78..00000000 --- a/infra/Adapters/Services/UuidConverterImpl.php +++ /dev/null @@ -1,23 +0,0 @@ -toString()); - } - - public function toBase58(UuidInterface $uuid): string - { - return SymphonyUuid::fromString($uuid->toString())->toBase58(); - } -} diff --git a/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php b/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php index 24d3dcd9..d28053d0 100644 --- a/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php @@ -43,7 +43,7 @@ describe('Bo\OrdersController', function (): void { Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2500, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000101'), 'Alice', 'Smith', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -70,7 +70,7 @@ describe('Bo\OrdersController', function (): void { Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2500, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule((string) (1000100 + $i)), 'Alice', 'Smith', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -93,12 +93,13 @@ describe('Bo\OrdersController', function (): void { it('can filter index by search term', function (): void { /** @var \Tests\TestCase $this */ // GIVEN - $ref = \Symfony\Component\Uid\Uuid::v7()->toBase58(); - $shop = Shop::factory()->create(['name' => 'UniqueShopSearch']); + $refUuid = Uuid::uuid7(); + $ref = $refUuid->toString(); + $shop = Shop::factory()->create(['name' => 'UniqueShopSearch']); Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference($ref), + 'reference' => new OrderReference($refUuid), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1500, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000102'), 'Bob', 'Jones', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -125,7 +126,7 @@ describe('Bo\OrdersController', function (): void { Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(3000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000103'), 'Charlie', 'Brown', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -172,7 +173,7 @@ describe('Bo\OrdersController', function (): void { $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(4000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000999'), 'Jean', 'Dupont', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -196,7 +197,7 @@ describe('Bo\OrdersController', function (): void { $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000104'), 'David', 'Clark', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -235,7 +236,7 @@ describe('Bo\OrdersController', function (): void { $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::CANCELED->value, 'total' => new Money(2000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000105'), 'Eve', 'Stone', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), diff --git a/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php index 8942b6a3..d5a425a1 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php @@ -115,12 +115,13 @@ describe('OrderController', function () { 'updated_at' => CarbonImmutable::now(), ]); - $shop = Shop::factory()->create(); - $ref = \Symfony\Component\Uid\Uuid::v7()->toBase58(); + $shop = Shop::factory()->create(); + $refUuid = Uuid::uuid7(); + $ref = $refUuid->toString(); Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference($ref), + 'reference' => new OrderReference($refUuid), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(5000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('8888001'), 'Jean', 'Dupont', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -196,12 +197,13 @@ describe('OrderController', function () { 'updated_at' => CarbonImmutable::now(), ]); - $shop = Shop::factory()->create(); - $ref = \Symfony\Component\Uid\Uuid::v7()->toBase58(); - $order = Order::forceCreate([ + $shop = Shop::factory()->create(); + $refUuid = Uuid::uuid7(); + $ref = $refUuid->toString(); + $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference($ref), + 'reference' => new OrderReference($refUuid), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(5000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('8888002'), 'Paul', 'Martin', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), diff --git a/tests/Feature/App/Http/Controllers/Fo/TunnelControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/TunnelControllerTest.php index a26d215a..80187ceb 100644 --- a/tests/Feature/App/Http/Controllers/Fo/TunnelControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/TunnelControllerTest.php @@ -488,7 +488,7 @@ describe('TunnelController', function (): void { ]); Gate::before(fn () => true); - $orderReference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()); + $orderReference = new OrderReference(Uuid::uuid7()); $this->mock(Executor::class, function ($mock) use ($orderReference): void { $mock->shouldReceive('execute') ->once() @@ -572,7 +572,7 @@ describe('TunnelController', function (): void { $shop->default = true; $shop->save(); - $orderReference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()); + $orderReference = new OrderReference(Uuid::uuid7()); $order = new Order(); $order->reference = $orderReference; $order->total = Money::EUR(3000); diff --git a/tests/Integration/WithApp/App/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php b/tests/Integration/WithApp/App/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php index 74061bf2..827b5d74 100644 --- a/tests/Integration/WithApp/App/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php +++ b/tests/Integration/WithApp/App/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php @@ -21,7 +21,7 @@ use Domain\Models\ValueObjects\ShopperEstablishmentCode; use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Money\Money; -use Symfony\Component\Uid\Uuid; +use Ramsey\Uuid\Uuid; describe('GetTunnelOrderConfirmedQuery', function (): void { it('returns order confirmed output with step, orderDto, shopDto and mapUrl', function (): void { @@ -34,7 +34,7 @@ describe('GetTunnelOrderConfirmedQuery', function (): void { $shop->default = true; $shop->save(); - $reference = new OrderReference(Uuid::v7()->toBase58()); + $reference = new OrderReference(Uuid::uuid7()); $order = new Order(); $order->reference = $reference; @@ -69,7 +69,7 @@ describe('GetTunnelOrderConfirmedQuery', function (): void { expect($output)->toBeInstanceOf(GetTunnelOrderConfirmedQueryOutput::class) ->and($output->step)->toBe(OrderTunnelStep::CONFIRMATION) ->and($output->order)->toBeInstanceOf(OrderDto::class) - ->and((string) $output->order->reference)->toBe($reference->value) + ->and((string) $output->order->reference)->toBe((string) $reference) ->and($output->shop)->toBeInstanceOf(ShopDto::class) ->and($output->shop->name)->toBe('Boutique Retrait') ->and($output->mapUrl)->toBeString(); @@ -77,7 +77,7 @@ describe('GetTunnelOrderConfirmedQuery', function (): void { it('throws UnexpectedValueException when order has no shop', function (): void { // GIVEN - $reference = new OrderReference(Uuid::v7()->toBase58()); + $reference = new OrderReference(Uuid::uuid7()); $order = new Order(); $order->reference = $reference; diff --git a/tests/Integration/WithApp/App/Services/OrderServiceTest.php b/tests/Integration/WithApp/App/Services/OrderServiceTest.php index 42e0756e..c8a1aeda 100644 --- a/tests/Integration/WithApp/App/Services/OrderServiceTest.php +++ b/tests/Integration/WithApp/App/Services/OrderServiceTest.php @@ -51,7 +51,7 @@ describe('OrderService', function () { $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000301'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -91,7 +91,7 @@ describe('OrderService', function () { $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000999'), 'Other', 'Person', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -117,7 +117,7 @@ describe('OrderService', function () { $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000999'), 'Other', 'Person', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), diff --git a/tests/Integration/WithApp/Directories/EloquentOrderDirectoryTest.php b/tests/Integration/WithApp/Directories/EloquentOrderDirectoryTest.php index d946bbc5..da594880 100644 --- a/tests/Integration/WithApp/Directories/EloquentOrderDirectoryTest.php +++ b/tests/Integration/WithApp/Directories/EloquentOrderDirectoryTest.php @@ -76,7 +76,7 @@ describe('EloquentOrderDirectory', function () { Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000201'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -85,7 +85,7 @@ describe('EloquentOrderDirectory', function () { Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee(new Matricule('1000999'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -106,7 +106,7 @@ describe('EloquentOrderDirectory', function () { $directory = new EloquentOrderDirectory(); $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'total' => new Money(1000, new Currency('EUR')), 'status' => OrderStatus::VALIDATED->value, 'employee' => new OrderEmployee(new Matricule('1000999'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -157,7 +157,7 @@ describe('EloquentOrderDirectory', function () { $orderId = Uuid::uuid7()->toString(); Order::forceCreate([ 'id' => $orderId, - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'total' => new Money(1000, new Currency('EUR')), 'status' => OrderStatus::VALIDATED->value, 'employee' => new OrderEmployee(new Matricule('1000202'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -179,7 +179,7 @@ describe('EloquentOrderDirectory', function () { $pastDate = CarbonImmutable::now()->subDays(5); Order::forceCreate([ 'id' => Uuid::uuid7($pastDate)->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'total' => new Money(1000, new Currency('EUR')), 'status' => OrderStatus::VALIDATED->value, 'employee' => new OrderEmployee(new Matricule('1000999'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -187,7 +187,7 @@ describe('EloquentOrderDirectory', function () { ]); Order::forceCreate([ 'id' => Uuid::uuid7($pastDate)->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'total' => new Money(1000, new Currency('EUR')), 'status' => OrderStatus::WAITING->value, 'employee' => new OrderEmployee(new Matricule('1000999'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -210,7 +210,7 @@ describe('EloquentOrderDirectory', function () { $pastDate = CarbonImmutable::now()->subDays(5); Order::forceCreate([ 'id' => Uuid::uuid7($pastDate)->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'total' => new Money(1000, new Currency('EUR')), 'status' => OrderStatus::CANCELED->value, 'employee' => new OrderEmployee(new Matricule('1000999'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -252,7 +252,7 @@ describe('EloquentOrderDirectory', function () { $pastDate = CarbonImmutable::now()->subDays(5); Order::forceCreate([ 'id' => Uuid::uuid7($pastDate)->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'total' => new Money(1000, new Currency('EUR')), 'status' => OrderStatus::VALIDATED->value, 'employee' => new OrderEmployee(new Matricule('1000203'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), @@ -275,7 +275,7 @@ describe('EloquentOrderDirectory', function () { $pastDate = CarbonImmutable::now()->subDays(5); $order = Order::forceCreate([ 'id' => Uuid::uuid7($pastDate)->toString(), - 'reference' => new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()), + 'reference' => new OrderReference(Uuid::uuid7()), 'total' => new Money(1000, new Currency('EUR')), 'status' => OrderStatus::VALIDATED->value, 'employee' => new OrderEmployee(new Matricule('1000999'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), diff --git a/tests/Unit/App/Actions/Orders/FinalizeOrderTest.php b/tests/Unit/App/Actions/Orders/FinalizeOrderTest.php index 2a89c097..6e3cb009 100644 --- a/tests/Unit/App/Actions/Orders/FinalizeOrderTest.php +++ b/tests/Unit/App/Actions/Orders/FinalizeOrderTest.php @@ -26,7 +26,7 @@ describe('FinalizeOrder', function (): void { // GIVEN $input = new FinalizeOrderInput(); - $orderReference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()); + $orderReference = new OrderReference(Uuid::uuid7()); $builder = \Mockery::mock(OrderBuilderCompleted::class); $order = new Order( id: new OrderId(Uuid::uuid7()), diff --git a/tests/Unit/App/Casts/OrderReferenceCastTest.php b/tests/Unit/App/Casts/OrderReferenceCastTest.php index bc09ca45..a32b3485 100644 --- a/tests/Unit/App/Casts/OrderReferenceCastTest.php +++ b/tests/Unit/App/Casts/OrderReferenceCastTest.php @@ -5,19 +5,22 @@ declare(strict_types=1); use App\Casts\OrderReferenceCast; use Domain\Models\ValueObjects\OrderReference; use Illuminate\Database\Eloquent\Model; +use Ramsey\Uuid\Uuid; it('gets a reference', function () { // GIVEN $cast = new OrderReferenceCast(); $model = \Mockery::mock(Model::class); - $value = '1Cbx1Nwz16buAGRpU3FX8F'; + $uuid = Uuid::uuid7(); + $value = $uuid->toString(); // WHEN $reference = $cast->get($model, 'reference', $value, []); // THEN expect($reference)->toBeInstanceOf(OrderReference::class) - ->and($reference->value)->toBe($value); + ->and((string) $reference)->toBe($value) + ->and($reference->value->equals($uuid))->toBeTrue(); }); it('throws exception when getting invalid reference', function () { @@ -46,7 +49,7 @@ it('throws exception when setting invalid reference type', function () { // GIVEN $cast = new OrderReferenceCast(); $model = \Mockery::mock(Model::class); - $value = '1Cbx1Nwz16buAGRpU3FX8F'; + $value = Uuid::uuid7()->toString(); // WHEN $cast->set($model, 'reference', $value, []); @@ -61,12 +64,12 @@ it('sets a reference', function () { // GIVEN $cast = new OrderReferenceCast(); $model = \Mockery::mock(Model::class); - $value = '1Cbx1Nwz16buAGRpU3FX8F'; - $reference = new OrderReference($value); + $uuid = Uuid::uuid7(); + $reference = new OrderReference($uuid); // WHEN $value = $cast->set($model, 'reference', $reference, []); // THEN - expect($value)->toBe($value); + expect($value)->toBe($uuid->toString()); }); diff --git a/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php b/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php index 0c484df0..fa95f53e 100644 --- a/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php +++ b/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php @@ -25,7 +25,7 @@ describe('AnOrderHasBeenPlaced', function () { // GIVEN $uuid = Uuid::uuid7(); $orderId = new OrderId($uuid); - $reference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()); + $reference = new OrderReference(Uuid::uuid7()); $totalTtc = new Money(1000, new Currency('EUR')); $matricule = new Matricule('1234567'); $employee = new OrderEmployee($matricule, 'John', 'Doe', new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITEA'), new ShopperServiceCode('101')); @@ -47,7 +47,7 @@ describe('AnOrderHasBeenPlaced', function () { // GIVEN $uuid = Uuid::uuid7(); $orderId = new OrderId($uuid); - $reference = new OrderReference(\Symfony\Component\Uid\Uuid::v7()->toBase58()); + $reference = new OrderReference(Uuid::uuid7()); $totalTtc = new Money(1000, new Currency('EUR')); $matricule = new Matricule('1234567'); $employee = new OrderEmployee($matricule, 'John', 'Doe', new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITEA'), new ShopperServiceCode('101')); diff --git a/tests/Unit/Domain/Models/Entities/OrderTest.php b/tests/Unit/Domain/Models/Entities/OrderTest.php index 706e84b3..c721f79d 100644 --- a/tests/Unit/Domain/Models/Entities/OrderTest.php +++ b/tests/Unit/Domain/Models/Entities/OrderTest.php @@ -26,7 +26,6 @@ use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Money\Money; use Ramsey\Uuid\Uuid; -use Symfony\Component\Uid\UuidV7; function makeOrderLine(array $overrides = []): OrderLine { @@ -62,7 +61,7 @@ function makeOrder(array $overrides = []): Order id: $overrides['id'] ?? new OrderId(Uuid::uuid7()), shopId: $overrides['shopId'] ?? new ShopId(Uuid::uuid7()), reference: $overrides['reference'] ?? new OrderReference( - UuidV7::v7()->toBase58() + Uuid::uuid7() ), employee: $overrides['employee'] ?? new OrderEmployee( matricule: new Matricule('1234567'), diff --git a/tests/Unit/Domain/Models/ValueObjects/OrderReferenceTest.php b/tests/Unit/Domain/Models/ValueObjects/OrderReferenceTest.php index ae0f728e..3659d3e8 100644 --- a/tests/Unit/Domain/Models/ValueObjects/OrderReferenceTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/OrderReferenceTest.php @@ -5,66 +5,36 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects; use Domain\Models\ValueObjects\OrderReference; -use Symfony\Component\Uid\Uuid; +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\UuidInterface; describe('OrderReference', function () { - - function getNewOrderReference(string $value): OrderReference + function getNewOrderReference(UuidInterface $value): OrderReference { return new OrderReference($value); } - it('can instantiate', function () { + it('can instantiate with a valid UUID v7', function () { // GIVEN - $uuidBase58 = Uuid::v7()->toBase58(); + $uuidV7 = Uuid::uuid7(); // WHEN - $vo = getNewOrderReference($uuidBase58); + $vo = getNewOrderReference($uuidV7); // THEN expect($vo)->toBeInstanceOf(OrderReference::class); - expect((string) $vo)->toBe($uuidBase58); - }); - - it('throws exception if order reference is empty', function () { - // GIVEN - $value = ' '; - - // WHEN - $action = fn () => getNewOrderReference($value); - - // THEN - expect($action)->toThrow(\DomainException::class); - }); - - it('throws exception if order reference is not a valid base58 string', function () { - // GIVEN - $value = 'invalid_base58_string!!!!'; - - // WHEN - $action = fn () => getNewOrderReference($value); - - // THEN - expect($action)->toThrow(\DomainException::class); + expect((string) $vo)->toBe($uuidV7->toString()); + expect($vo->value)->toBe($uuidV7); }); it('throws exception if provided UUID is not v7', function () { // GIVEN - $uuidV4Base58 = Uuid::v4()->toBase58(); + $uuidV4 = Uuid::uuid4(); // WHEN - $action = fn () => getNewOrderReference($uuidV4Base58); + $action = fn () => getNewOrderReference($uuidV4); // THEN - expect($action)->toThrow(\DomainException::class); + expect($action)->toThrow(\DomainException::class, 'value must be a valid UUID v7'); }); }); - -it('throws exception if base58 string is syntactically valid but invalid length when decoded', function (): void { - // GIVEN - $value = 'zzzzzzzzzzzzzzzzzzzzzz'; // 22 valid chars, but decodes to out-of-bounds UUID - // WHEN - $action = fn () => new OrderReference($value); - // THEN - expect($action)->toThrow(\DomainException::class, 'Order reference must be a valid base-58 string'); -}); diff --git a/tests/Unit/Domain/Services/OrderServiceTest.php b/tests/Unit/Domain/Services/OrderServiceTest.php index 9d7b78ac..cc0f6d59 100644 --- a/tests/Unit/Domain/Services/OrderServiceTest.php +++ b/tests/Unit/Domain/Services/OrderServiceTest.php @@ -33,23 +33,21 @@ use Domain\Models\ValueObjects\ShopperEstablishmentCode; use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Domain\Ports\Repositories\OrderRepository; -use Domain\Ports\Services\UuidConverter; use Domain\Services\OrderService; use Mockery; use Money\Money; use Ramsey\Uuid\Uuid; -use Symfony\Component\Uid\UuidV7; +use Shared\Helpers\UuidHelper; describe('Order Cancellation', function () { it('cancels a validated order successfully', function () { // GIVEN $orderId = new OrderId(Uuid::uuid7()); - $validBase58 = UuidV7::v7()->toBase58(); $order = new Order( id: $orderId, shopId: new ShopId(Uuid::uuid7()), - reference: new OrderReference($validBase58), + reference: new OrderReference(Uuid::uuid7()), employee: new OrderEmployee( new Matricule('1234567'), 'Jean', @@ -102,9 +100,7 @@ describe('Order Cancellation', function () { $repository->shouldReceive('find')->with($orderId)->andReturn($order); $repository->shouldReceive('persist')->with($order)->once(); - $uuidConverter = Mockery::mock(UuidConverter::class); - - $service = new OrderService($uuidConverter, $repository); + $service = new OrderService($repository); // WHEN $service->cancelOrder($orderId); @@ -121,9 +117,7 @@ describe('Order Cancellation', function () { $repository = Mockery::mock(OrderRepository::class); $repository->shouldReceive('find')->with($orderId)->andReturn(null); - $uuidConverter = Mockery::mock(UuidConverter::class); - - $service = new OrderService($uuidConverter, $repository); + $service = new OrderService($repository); // WHEN $action = fn () => $service->cancelOrder($orderId); @@ -186,14 +180,10 @@ describe('Order Creation', function () { phone: '0478123456' ); - $validBase58 = UuidV7::v7()->toBase58(); - $uuidConverter = Mockery::mock(UuidConverter::class); - $uuidConverter->shouldReceive('toBase58')->andReturn($validBase58); - /** @var OrderRepository|\Mockery\MockInterface $repository */ $repository = Mockery::mock(OrderRepository::class); - $service = new OrderService($uuidConverter, $repository); + $service = new OrderService($repository); // WHEN $order = $service->createOrderFromBasket($basket, $pickupTimeSlot, $shopper, $shop); @@ -201,7 +191,7 @@ describe('Order Creation', function () { // THEN expect($order)->toBeInstanceOf(Order::class); expect($order->status)->toBe(OrderStatus::VALIDATED); - expect($order->reference->value)->toBe($validBase58); + expect(UuidHelper::isV7($order->reference->value))->toBeTrue(); // * Employee $employee = $order->employee; @@ -292,10 +282,9 @@ describe('Order Creation', function () { city: 'C' ); - $uuidConverter = Mockery::mock(UuidConverter::class); $repository = Mockery::mock(OrderRepository::class); - $service = new OrderService($uuidConverter, $repository); + $service = new OrderService($repository); // WHEN $action = fn () => $service->createOrderFromBasket($basket, $pickupTimeSlot, $shopper, $shop); diff --git a/tests/Unit/Domain/Services/OrderTunnelServiceTest.php b/tests/Unit/Domain/Services/OrderTunnelServiceTest.php index a5998e93..aaf470d8 100644 --- a/tests/Unit/Domain/Services/OrderTunnelServiceTest.php +++ b/tests/Unit/Domain/Services/OrderTunnelServiceTest.php @@ -39,7 +39,6 @@ use Domain\Ports\Services\EmployeeStatisticsService; use Domain\Ports\Services\OrderBuilderSessionManager; use Domain\Ports\Services\SessionService; use Domain\Ports\Services\TransactionManager; -use Domain\Ports\Services\UuidConverter; use Domain\Services\BasketService; use Domain\Services\OrderService; use Domain\Services\OrderTunnelService; @@ -107,7 +106,6 @@ function createOrderTunnelService( ?OrderRepository $orderRepository = null, ?TransactionManager $transactionManager = null, ?DomainEventDispatcher $eventDispatcher = null, - ?UuidConverter $uuidConverter = null, ): OrderTunnelService { if ($basketRepository === null) { $basketRepository = mock(BasketRepository::class); @@ -144,7 +142,6 @@ function createOrderTunnelService( $transactionManager ??= mock(TransactionManager::class); $eventDispatcher ??= mock(DomainEventDispatcher::class); - $uuidConverter ??= mock(UuidConverter::class); $sessionService = \Mockery::mock(SessionService::class); $sessionService->shouldReceive('get')->andReturn(new SessionId(Uuid::uuid7()))->byDefault(); @@ -155,7 +152,7 @@ function createOrderTunnelService( $basketService = new BasketService($basketRepository, $productRepository, $sessionService); $shopperService = new ShopperService($shopRepository, $shopperRepository); $pickupService = new PickupSchedulingService($pickupExceptionRepository); - $orderService = new OrderService($uuidConverter, $orderRepository, $employeeStatisticsService); + $orderService = new OrderService($orderRepository); $orderLimitPolicy = new CustomerOrderLimitPolicy(500000, 500000); @@ -580,9 +577,6 @@ describe('OrderTunnelService', function (): void { $builderRepo = mock(OrderBuilderSessionManager::class); $builderRepo->shouldReceive('clear')->once(); - $uuidConverter = mock(UuidConverter::class); - $uuidConverter->shouldReceive('toBase58')->andReturn(\Symfony\Component\Uid\Uuid::v7()->toBase58()); - $service = createOrderTunnelService( basketRepository: $basketRepo, shopRepository: $shopRepo, @@ -590,8 +584,7 @@ describe('OrderTunnelService', function (): void { orderBuilderSessionManager: $builderRepo, orderRepository: $orderRepo, transactionManager: $transactionManager, - eventDispatcher: $eventDispatcher, - uuidConverter: $uuidConverter + eventDispatcher: $eventDispatcher ); // WHEN @@ -685,9 +678,6 @@ describe('OrderTunnelService', function (): void { $builderRepo = mock(OrderBuilderSessionManager::class); $builderRepo->shouldReceive('clear')->once(); - $uuidConverter = mock(UuidConverter::class); - $uuidConverter->shouldReceive('toBase58')->andReturn(\Symfony\Component\Uid\Uuid::v7()->toBase58()); - $basketRepo = mock(BasketRepository::class); $basketRepo->shouldReceive('find')->once()->andReturn(createTestBasket(1)); $basketRepo->shouldReceive('persist')->once(); @@ -723,8 +713,7 @@ describe('OrderTunnelService', function (): void { orderBuilderSessionManager: $builderRepo, orderRepository: $orderRepo, transactionManager: $transactionManager, - eventDispatcher: $eventDispatcher, - uuidConverter: $uuidConverter + eventDispatcher: $eventDispatcher ); // WHEN diff --git a/tests/Unit/Domain/Services/RegateServiceTest.php b/tests/Unit/Domain/Services/RegateServiceTest.php index 0febadb2..05c2e485 100644 --- a/tests/Unit/Domain/Services/RegateServiceTest.php +++ b/tests/Unit/Domain/Services/RegateServiceTest.php @@ -15,8 +15,8 @@ use Domain\Ports\Services\CsvGenerator; use Domain\Services\RegateService; use Mockery; use Money\Money; +use Ramsey\Uuid\Uuid; use Shared\DDD\DomainEventDispatcher; -use Symfony\Component\Uid\Uuid; describe('RegateService', function (): void { @@ -26,8 +26,9 @@ describe('RegateService', function (): void { $dispatcher = Mockery::mock(DomainEventDispatcher::class); $service = new RegateService($csvGenerator, $dispatcher); - $orderReferenceValue = Uuid::v7()->toBase58(); - $reference = new OrderReference($orderReferenceValue); + $uuid = Uuid::uuid7(); + $reference = new OrderReference($uuid); + $orderReferenceValue = (string) $reference; $employeeMatricule = new Matricule('1234567'); $pickupDay = CarbonImmutable::create(2025, 1, 1); diff --git a/tests/Unit/Infra/Adapters/Services/UuidConverterImplTest.php b/tests/Unit/Infra/Adapters/Services/UuidConverterImplTest.php deleted file mode 100644 index 42b5b1a2..00000000 --- a/tests/Unit/Infra/Adapters/Services/UuidConverterImplTest.php +++ /dev/null @@ -1,36 +0,0 @@ -toBase58(); - - // WHEN - $result = $converter->fromBase58($base58); - - // THEN - expect($result->toString())->toBe($uuidStr); - }); - - it('converts from uuid to base58', function () { - // GIVEN - $converter = new UuidConverterImpl(); - $uuidStr = '123e4567-e89b-12d3-a456-426614174000'; - $uuid = Uuid::fromString($uuidStr); - $expectedBase58 = SymphonyUuid::fromString($uuidStr)->toBase58(); - - // WHEN - $result = $converter->toBase58($uuid); - - // THEN - expect($result)->toBe($expectedBase58); - }); -});