diff --git a/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php b/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php index ae7a39b8..b2d9076b 100644 --- a/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php @@ -29,7 +29,7 @@ use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Date; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use function Pest\Laravel\get; @@ -57,9 +57,9 @@ describe('Bo\OrdersController', function (): void { // GIVEN $shop = Shop::factory()->create(['name' => 'Boutique Test']); Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2500, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -91,9 +91,9 @@ describe('Bo\OrdersController', function (): void { $shop = Shop::factory()->create(['name' => 'Boutique Pagination']); for ($i = 0; $i < 30; $i++) { Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2500, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -123,12 +123,12 @@ describe('Bo\OrdersController', function (): void { it('can filter index by search term', function (): void { /** @var \Tests\TestCase $this */ // GIVEN - $refUuid = Uuid::uuid7(); + $refUuid = UuidHelper::v7(); $reference = new OrderReference($refUuid); $ref = (string) $reference; $shop = Shop::factory()->create(['name' => 'UniqueShopSearch']); Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, 'reference' => $reference, 'status' => OrderStatus::VALIDATED->value, @@ -163,9 +163,9 @@ describe('Bo\OrdersController', function (): void { // GIVEN $shop = Shop::factory()->create(); $olderOrder = Order::query()->forceCreate([ - 'id' => Uuid::uuid7(Date::now()->subHours(2))->toString(), + 'id' => UuidHelper::v7(Date::now()->subHours(2))->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -180,9 +180,9 @@ describe('Bo\OrdersController', function (): void { 'pickup_day' => Date::now()->addDays(7)->toDateString(), ]); $newerOrder = Order::query()->forceCreate([ - 'id' => Uuid::uuid7(Date::now())->toString(), + 'id' => UuidHelper::v7(Date::now())->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -213,9 +213,9 @@ describe('Bo\OrdersController', function (): void { // GIVEN $shop = Shop::factory()->create(); $todayOrder = Order::query()->forceCreate([ - 'id' => Uuid::uuid7(Date::now())->toString(), + 'id' => UuidHelper::v7(Date::now())->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(3000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -230,9 +230,9 @@ describe('Bo\OrdersController', function (): void { 'pickup_day' => Date::now()->addDays(7)->toDateString(), ]); $pastOrder = Order::query()->forceCreate([ - 'id' => Uuid::uuid7(Date::now()->subDays(3))->toString(), + 'id' => UuidHelper::v7(Date::now()->subDays(3))->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(4000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -264,8 +264,8 @@ describe('Bo\OrdersController', function (): void { // GIVEN $shop = Shop::factory()->create(); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('customer@example.com'), ]); Employee::query()->forceCreate([ @@ -287,9 +287,9 @@ describe('Bo\OrdersController', function (): void { App::instance(CrmService::class, $crmMock); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(4000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -318,9 +318,9 @@ describe('Bo\OrdersController', function (): void { // GIVEN $shop = Shop::factory()->create(); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -364,9 +364,9 @@ describe('Bo\OrdersController', function (): void { // GIVEN $shop = Shop::factory()->create(); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::CANCELED->value, 'total' => new Money(2000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -392,9 +392,9 @@ describe('Bo\OrdersController', function (): void { // GIVEN $shop = Shop::factory()->create(); $validated = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2500, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -409,9 +409,9 @@ describe('Bo\OrdersController', function (): void { 'pickup_day' => Date::now()->toDateString(), ]); $failed = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::FAILED->value, 'total' => new Money(1500, new Currency('EUR')), 'employee' => new OrderEmployee( diff --git a/tests/Feature/App/Http/Controllers/Fo/Ajax/BasketControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Ajax/BasketControllerTest.php index 5f4034d0..421dbed1 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Ajax/BasketControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Ajax/BasketControllerTest.php @@ -29,7 +29,7 @@ use Infrastructure\Adapters\Repositories\SessionBasketRepository; use Infrastructure\Adapters\Serializers\BasketSerializer; use Infrastructure\Adapters\Services\AppSessionService; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('BasketController', function () { it('can access post /ajax/basket/add', function () { @@ -111,9 +111,9 @@ describe('BasketController', function () { Cache::flush(); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'email' => new Email('basket-nplusone@example.com'), - 'hashcode' => Uuid::uuid4()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), ]); $range = new Range(); @@ -156,7 +156,7 @@ describe('BasketController', function () { $product->save(); $basket->addOrUpdate(new BasketProduct( - id: new ProductId(Uuid::fromString((string) $product->id)), + id: new ProductId(UuidHelper::fromString((string) $product->id)), name: $product->name, qty: 1, unitPriceHt: Money::EUR(1000), diff --git a/tests/Feature/App/Http/Controllers/Fo/Ajax/PickupControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Ajax/PickupControllerTest.php index 5691618f..27a0feaf 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Ajax/PickupControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Ajax/PickupControllerTest.php @@ -13,7 +13,7 @@ use Database\Seeders\ContentSeeder; use Domain\Models\ValueObjects\Email; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\View; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('PickupController', function (): void { @@ -46,7 +46,7 @@ describe('PickupController', function (): void { $customer = new Customer(); $customer->email = new Email('employee@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); $this->withoutMiddleware([ @@ -74,7 +74,7 @@ describe('PickupController', function (): void { $shop = Shop::factory()->create(); $customer = new Customer(); $customer->email = new Email('employee2@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); $this->withoutMiddleware([ diff --git a/tests/Feature/App/Http/Controllers/Fo/Ajax/ProductsControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Ajax/ProductsControllerTest.php index 4cf2759c..2a1d9726 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Ajax/ProductsControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Ajax/ProductsControllerTest.php @@ -21,7 +21,7 @@ use Domain\Models\ValueObjects\Email; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\View; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('ProductsController (Ajax)', function () { @@ -79,7 +79,7 @@ describe('ProductsController (Ajax)', function () { Cache::flush(); $customer = new Customer(); $customer->email = new Email('test1@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -143,7 +143,7 @@ describe('ProductsController (Ajax)', function () { Cache::flush(); $customer = new Customer(); $customer->email = new Email('test2@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); diff --git a/tests/Feature/App/Http/Controllers/Fo/Auth/LoginControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Auth/LoginControllerTest.php index 362b5d67..2c910148 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Auth/LoginControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Auth/LoginControllerTest.php @@ -28,7 +28,7 @@ use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\View; use Illuminate\Support\Str; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('LoginController', function () { @@ -119,7 +119,7 @@ describe('LoginController', function () { Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $user->hashcode = new CrmHashcode(Uuid::uuid4()); + $user->hashcode = new CrmHashcode(UuidHelper::v4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); diff --git a/tests/Feature/App/Http/Controllers/Fo/Auth/RegisterControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Auth/RegisterControllerTest.php index a4fd68bd..a74e74b6 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Auth/RegisterControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Auth/RegisterControllerTest.php @@ -24,7 +24,7 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\View; use Illuminate\Support\ViewErrorBag; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; use Webmozart\Assert\Assert; @@ -67,7 +67,7 @@ describe('RegisterController', function () { /** @var \Tests\TestCase $this */ // GIVEN $customer = new Customer(['email' => new Email('existing@example.com')]); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->saveOrFail(); $employee = new Employee(); @@ -105,7 +105,7 @@ describe('RegisterController', function () { /** @var \Tests\TestCase $this */ // GIVEN $customer = new Customer(['email' => new Email('john.doe@example.com')]); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->saveOrFail(); $input = new RegisterCustomerInput( diff --git a/tests/Feature/App/Http/Controllers/Fo/Customers/CustomerControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Customers/CustomerControllerTest.php index e34efc43..d76df87d 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Customers/CustomerControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Customers/CustomerControllerTest.php @@ -20,7 +20,7 @@ use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\View; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('CustomerController', function () { @@ -48,7 +48,7 @@ describe('CustomerController', function () { Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $user->hashcode = new CrmHashcode(Uuid::uuid4()); + $user->hashcode = new CrmHashcode(UuidHelper::v4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); @@ -73,7 +73,7 @@ describe('CustomerController', function () { Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $user->hashcode = new CrmHashcode(Uuid::uuid4()); + $user->hashcode = new CrmHashcode(UuidHelper::v4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); @@ -98,7 +98,7 @@ describe('CustomerController', function () { Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $user->hashcode = new CrmHashcode(Uuid::uuid4()); + $user->hashcode = new CrmHashcode(UuidHelper::v4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); @@ -122,9 +122,9 @@ describe('CustomerController', function () { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'hashcode' => $hashcode->value, 'email' => new Email('jean.dupont@example.com'), ]); @@ -188,9 +188,9 @@ describe('CustomerController', function () { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'hashcode' => $hashcode->value, 'email' => new Email('jean.dupont@example.com'), ]); diff --git a/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php index 8ad770de..aba25ed8 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php @@ -33,7 +33,7 @@ use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\View; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('OrderController', function () { @@ -61,7 +61,7 @@ describe('OrderController', function () { Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $user->hashcode = new CrmHashcode(Uuid::uuid4()); + $user->hashcode = new CrmHashcode(UuidHelper::v4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); @@ -86,7 +86,7 @@ describe('OrderController', function () { Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $user->hashcode = new CrmHashcode(Uuid::uuid4()); + $user->hashcode = new CrmHashcode(UuidHelper::v4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); @@ -110,9 +110,9 @@ describe('OrderController', function () { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'hashcode' => $hashcode->value, 'email' => new Email('verified@example.com'), ]); @@ -132,11 +132,11 @@ describe('OrderController', function () { ]); $shop = Shop::factory()->create(); - $refUuid = Uuid::uuid7(); + $refUuid = UuidHelper::v7(); $reference = new OrderReference($refUuid); $ref = (string) $reference; Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, 'reference' => $reference, 'status' => OrderStatus::VALIDATED->value, @@ -207,9 +207,9 @@ describe('OrderController', function () { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'hashcode' => $hashcode->value, 'email' => new Email('verified_show@example.com'), ]); @@ -229,11 +229,11 @@ describe('OrderController', function () { ]); $shop = Shop::factory()->create(); - $refUuid = Uuid::uuid7(); + $refUuid = UuidHelper::v7(); $reference = new OrderReference($refUuid); $ref = (string) $reference; $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, 'reference' => $reference, 'status' => OrderStatus::VALIDATED->value, @@ -294,9 +294,9 @@ describe('OrderController', function () { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'hashcode' => $hashcode->value, 'email' => new Email('tech-order-' . $status->value . '@example.com'), ]); @@ -315,9 +315,9 @@ describe('OrderController', function () { ]); $shop = Shop::factory()->create(); - $reference = new OrderReference(Uuid::uuid7()); + $reference = new OrderReference(UuidHelper::v7()); Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, 'reference' => $reference, 'status' => $status->value, diff --git a/tests/Feature/App/Http/Controllers/Fo/Customers/PasswordControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Customers/PasswordControllerTest.php index b827e731..0754aa5a 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Customers/PasswordControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Customers/PasswordControllerTest.php @@ -11,7 +11,7 @@ use Database\Seeders\ContentSeeder; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\View; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('PasswordController', function () { @@ -26,7 +26,7 @@ describe('PasswordController', function () { Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $user->hashcode = new CrmHashcode(Uuid::uuid4()); + $user->hashcode = new CrmHashcode(UuidHelper::v4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); @@ -51,7 +51,7 @@ describe('PasswordController', function () { Cache::flush(); $user = \Mockery::mock(Customer::class)->makePartial(); $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $user->hashcode = new CrmHashcode(Uuid::uuid4()); + $user->hashcode = new CrmHashcode(UuidHelper::v4()); $user->shouldReceive('getAuthPassword')->andReturn('dummy'); $this->actingAs($user, 'frontend'); $crmMock = \Mockery::mock(CrmService::class)->makePartial(); diff --git a/tests/Feature/App/Http/Controllers/Fo/NewsletterControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/NewsletterControllerTest.php index 73822b80..ddd8d185 100644 --- a/tests/Feature/App/Http/Controllers/Fo/NewsletterControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/NewsletterControllerTest.php @@ -9,7 +9,7 @@ use App\Services\CrmService; use Database\Seeders\ContentSeeder; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\View; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('NewsletterController', function () { it('can access get /unsubscribe with valid hashcode', function () { @@ -23,7 +23,7 @@ describe('NewsletterController', function () { $page->slug->value() => $page, ])); Cache::flush(); - $hashcode = Uuid::uuid4()->toString(); + $hashcode = UuidHelper::v4()->toString(); // WHEN $response = $this->get('/unsubscribe?hashcode=' . $hashcode); diff --git a/tests/Feature/App/Http/Controllers/Fo/Pages/ContactControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Pages/ContactControllerTest.php index e5338af3..66d40e5d 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Pages/ContactControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Pages/ContactControllerTest.php @@ -17,7 +17,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\View; use Mockery\MockInterface; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Contracts\StorageService; use Uwil\Storage\Lib\ValueObjects\DiskName; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; @@ -81,7 +81,7 @@ describe('ContactController', function (): void { 'last_name' => 'Dupont', 'email' => 'jean.dupont@gmail.com', 'subject' => 'Question', - 'order_ref' => (string) new OrderReference(Uuid::uuid7()), + 'order_ref' => (string) new OrderReference(UuidHelper::v7()), 'message' => 'Bonjour, ceci est un message de test qui contient au moins vingt caractères.', 'ok_cgv' => '1', ]; diff --git a/tests/Feature/App/Http/Controllers/Fo/Pages/HomeControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Pages/HomeControllerTest.php index 4fe02123..f3bd4030 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Pages/HomeControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Pages/HomeControllerTest.php @@ -21,7 +21,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\View; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; describe('HomeController', function () { @@ -84,7 +84,7 @@ describe('HomeController', function () { $slide->save(); $product = new Product(); - $product->id = (string) Uuid::uuid7(); + $product->id = (string) UuidHelper::v7(); $product->name = 'Poulet Fermier'; $product->brand = ProductBrand::loue; $product->slug = 'poulet-fermier'; @@ -171,7 +171,7 @@ describe('HomeController', function () { $discount->save(); $promoProduct = new Product(); - $promoProduct->id = (string) Uuid::uuid7(); + $promoProduct->id = (string) UuidHelper::v7(); $promoProduct->name = 'Foie Gras Promo'; $promoProduct->brand = ProductBrand::loue; $promoProduct->slug = 'foie-gras-promo'; @@ -193,7 +193,7 @@ describe('HomeController', function () { $promoProduct->save(); $regularProduct = new Product(); - $regularProduct->id = (string) Uuid::uuid7(); + $regularProduct->id = (string) UuidHelper::v7(); $regularProduct->name = 'Poulet Standard'; $regularProduct->brand = ProductBrand::loue; $regularProduct->slug = 'poulet-standard'; @@ -246,7 +246,7 @@ describe('HomeController', function () { $range->save(); $product = new Product(); - $product->id = (string) Uuid::uuid7(); + $product->id = (string) UuidHelper::v7(); $product->name = 'Poulet Sûr'; $product->brand = ProductBrand::loue; $product->slug = 'poulet-sur'; diff --git a/tests/Feature/App/Http/Controllers/Fo/ProductCharacterizationTest.php b/tests/Feature/App/Http/Controllers/Fo/ProductCharacterizationTest.php index 2b6cb007..d90bc829 100644 --- a/tests/Feature/App/Http/Controllers/Fo/ProductCharacterizationTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/ProductCharacterizationTest.php @@ -28,7 +28,7 @@ use Domain\Models\ValueObjects\Email; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\View; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; use Tests\TestCase; use Webmozart\Assert\Assert; @@ -53,7 +53,7 @@ function characterizationCustomer(string $email): Customer { $customer = new Customer(); $customer->email = new Email($email); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); return $customer; diff --git a/tests/Feature/App/Http/Controllers/Fo/TunnelControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/TunnelControllerTest.php index a5ed75fb..11202ec6 100644 --- a/tests/Feature/App/Http/Controllers/Fo/TunnelControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/TunnelControllerTest.php @@ -83,8 +83,8 @@ use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\View; use Mockery\MockInterface; use Money\Money; -use Ramsey\Uuid\Uuid; use Sentry\State\HubInterface; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('TunnelController', function (): void { @@ -219,7 +219,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -229,7 +229,7 @@ describe('TunnelController', function (): void { ]); Gate::before(fn () => true); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $basket = new Basket(new BasketId(UuidHelper::v7())); $this->mock(Executor::class, function (MockInterface $mock) use ($basket): void { $mock->shouldReceive('execute') ->once() @@ -261,7 +261,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -295,7 +295,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -351,7 +351,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -376,7 +376,7 @@ describe('TunnelController', function (): void { $this->mock(ShopperRepository::class, function (MockInterface $mock) use ($shopper): void { $mock->shouldReceive('getByIdOrFail')->andReturn($shopper); }); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $basket = new Basket(new BasketId(UuidHelper::v7())); $builder = \Mockery::mock(OrderBuilderWithBasket::class); $builder->shouldReceive('getBasket')->andReturn($basket); $this->mock(OrderTunnelService::class, function (MockInterface $mock) use ($builder): void { @@ -412,7 +412,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -437,7 +437,7 @@ describe('TunnelController', function (): void { $this->mock(ShopperRepository::class, function (MockInterface $mock) use ($shopper): void { $mock->shouldReceive('getByIdOrFail')->andReturn($shopper); }); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $basket = new Basket(new BasketId(UuidHelper::v7())); $builder = \Mockery::mock(OrderBuilderWithBasket::class); $builder->shouldReceive('getBasket')->andReturn($basket); $this->mock(OrderTunnelService::class, function (MockInterface $mock) use ($builder): void { @@ -473,7 +473,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -483,7 +483,7 @@ describe('TunnelController', function (): void { ]); Gate::before(fn () => true); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $basket = new Basket(new BasketId(UuidHelper::v7())); $builder = \Mockery::mock(OrderBuilderCompleted::class); $slot = new PickupTimeSlot(now(), new \DateInterval('PT1H')); $builder->shouldReceive('getPickupTimeSlot')->andReturn($slot); @@ -534,7 +534,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -544,8 +544,8 @@ describe('TunnelController', function (): void { ]); Gate::before(fn () => true); - $orderId = new OrderId(Uuid::uuid7()); - $orderReference = new OrderReference(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); + $orderReference = new OrderReference(UuidHelper::v7()); $this->mock(Executor::class, function (MockInterface $mock) use ($orderId, $orderReference): void { $mock->shouldReceive('execute') ->once() @@ -582,7 +582,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('regate-export-fail@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -592,8 +592,8 @@ describe('TunnelController', function (): void { ]); Gate::before(fn () => true); - $orderId = new OrderId(Uuid::uuid7()); - $orderReference = new OrderReference(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); + $orderReference = new OrderReference(UuidHelper::v7()); $this->mock(Executor::class, function (MockInterface $mock) use ($orderId, $orderReference): void { $mock->shouldReceive('execute') ->once() @@ -631,7 +631,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('confirm-sql-fail@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -641,8 +641,8 @@ describe('TunnelController', function (): void { ]); Gate::before(fn () => true); - $orderId = new OrderId(Uuid::uuid7()); - $orderReference = new OrderReference(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); + $orderReference = new OrderReference(UuidHelper::v7()); $this->mock(Executor::class, function (MockInterface $mock) use ($orderId, $orderReference): void { $mock->shouldReceive('execute') ->once() @@ -680,7 +680,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -720,7 +720,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -760,7 +760,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -802,7 +802,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -844,7 +844,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -882,7 +882,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test-inactive@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -921,7 +921,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('test@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -939,7 +939,7 @@ describe('TunnelController', function (): void { $shop->default = true; $shop->save(); - $orderReference = new OrderReference(Uuid::uuid7()); + $orderReference = new OrderReference(UuidHelper::v7()); $order = new Order(); $order->reference = $orderReference; $order->total = Money::EUR(3000); @@ -986,7 +986,7 @@ describe('TunnelController', function (): void { $customer = new Customer(); $customer->email = new Email('regate-fail@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $this->actingAs($customer, 'frontend'); @@ -1039,10 +1039,10 @@ describe('TunnelController', function (): void { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'email' => new Email('e2e-success@example.com'), 'hashcode' => $hashcode, ]); @@ -1179,10 +1179,10 @@ describe('TunnelController', function (): void { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'email' => new Email('e2e-fail@example.com'), 'hashcode' => $hashcode, ]); @@ -1332,10 +1332,10 @@ describe('TunnelController', function (): void { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'email' => new Email('e2e-lock@example.com'), 'hashcode' => $hashcode, ]); @@ -1473,10 +1473,10 @@ describe('TunnelController', function (): void { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'email' => new Email('e2e-attempt@example.com'), 'hashcode' => $hashcode, ]); @@ -1616,10 +1616,10 @@ describe('TunnelController', function (): void { ])); Cache::flush(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'email' => new Email('e2e-attempt-ko@example.com'), 'hashcode' => $hashcode, ]); diff --git a/tests/Feature/App/Http/Requests/Basket/AddBasketRequestTest.php b/tests/Feature/App/Http/Requests/Basket/AddBasketRequestTest.php index 9f4dd9b1..2b6698ae 100644 --- a/tests/Feature/App/Http/Requests/Basket/AddBasketRequestTest.php +++ b/tests/Feature/App/Http/Requests/Basket/AddBasketRequestTest.php @@ -22,8 +22,8 @@ use Infrastructure\Adapters\Repositories\EloquentProductRepository; use Money\Currency; use Money\Money; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; use Shared\Concurrency\Lock; +use Shared\Helpers\UuidHelper; function makeAddBasketRequest(): AddBasketRequest { @@ -50,9 +50,9 @@ describe('AddBasketRequest', function () { 'picture_title' => '', ]); $product = Product::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'name' => 'Test', - 'slug' => Uuid::uuid7()->toString(), + 'slug' => UuidHelper::v7()->toString(), 'brand' => ProductBrand::cases()[0]->value, 'description' => 'Test', 'price' => new Money(100, new Currency('EUR')), @@ -90,7 +90,7 @@ describe('AddBasketRequest', function () { $request->initialize(); // WHEN - $request->merge(['rowId' => Uuid::uuid7()->toString()]); + $request->merge(['rowId' => UuidHelper::v7()->toString()]); // THEN expect($request->authorize())->toBeFalse(); @@ -106,9 +106,9 @@ describe('AddBasketRequest', function () { 'picture_title' => '', ]); $product = Product::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'name' => 'Test', - 'slug' => Uuid::uuid7()->toString(), + 'slug' => UuidHelper::v7()->toString(), 'brand' => ProductBrand::cases()[0]->value, 'description' => 'Test', 'price' => new Money(100, new Currency('EUR')), @@ -150,9 +150,9 @@ describe('AddBasketRequest', function () { 'picture_title' => '', ]); $product = Product::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'name' => 'Test', - 'slug' => Uuid::uuid7()->toString(), + 'slug' => UuidHelper::v7()->toString(), 'brand' => ProductBrand::cases()[0]->value, 'description' => 'Test', 'price' => new Money(100, new Currency('EUR')), @@ -203,7 +203,7 @@ describe('AddBasketRequest', function () { it('can get product id as value object', function () { // GIVEN - $uuid = Uuid::uuid7()->toString(); + $uuid = UuidHelper::v7()->toString(); $request = makeAddBasketRequest(); $request->initialize(); $request->merge(['rowId' => $uuid]); diff --git a/tests/Feature/App/Http/Requests/Basket/RemoveBasketRequestTest.php b/tests/Feature/App/Http/Requests/Basket/RemoveBasketRequestTest.php index 269bca07..816a818b 100644 --- a/tests/Feature/App/Http/Requests/Basket/RemoveBasketRequestTest.php +++ b/tests/Feature/App/Http/Requests/Basket/RemoveBasketRequestTest.php @@ -6,7 +6,7 @@ namespace Tests\Feature\App\Http\Requests\Basket; use App\Http\Requests\Basket\RemoveBasketRequest; use Illuminate\Support\Facades\Validator; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('RemoveBasketRequest', function () { it('authorizes always', function () { @@ -25,7 +25,7 @@ describe('RemoveBasketRequest', function () { $request = new RemoveBasketRequest(); $request->initialize(); $request->merge([ - 'rowId' => Uuid::uuid7()->toString(), + 'rowId' => UuidHelper::v7()->toString(), 'qty' => 1, ]); @@ -55,7 +55,7 @@ describe('RemoveBasketRequest', function () { it('can get product id as value object', function () { // GIVEN - $uuid = Uuid::uuid7()->toString(); + $uuid = UuidHelper::v7()->toString(); $request = new RemoveBasketRequest(); $request->initialize(); $request->merge(['rowId' => $uuid]); diff --git a/tests/Feature/App/Http/Requests/Bo/Shops/IndexShopRequestTest.php b/tests/Feature/App/Http/Requests/Bo/Shops/IndexShopRequestTest.php index da332046..317f48d0 100644 --- a/tests/Feature/App/Http/Requests/Bo/Shops/IndexShopRequestTest.php +++ b/tests/Feature/App/Http/Requests/Bo/Shops/IndexShopRequestTest.php @@ -12,7 +12,7 @@ use Illuminate\Session\ArraySessionHandler; use Illuminate\Session\Store; use Illuminate\Support\Facades\Validator; use Infrastructure\Adapters\Services\AppAdminAuthService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use function Pest\Laravel\actingAs; use function Pest\Laravel\get; @@ -42,7 +42,7 @@ describe('IndexShopRequest', function (): void { // WHEN $invalid = Validator::make(['pickup-exception' => 'not-a-uuid'], $rules); - $valid = Validator::make(['pickup-exception' => Uuid::uuid7()->toString()], $rules); + $valid = Validator::make(['pickup-exception' => UuidHelper::v7()->toString()], $rules); // THEN expect($invalid->errors()->has('pickup-exception'))->toBeTrue() @@ -53,7 +53,7 @@ describe('IndexShopRequest', function (): void { // GIVEN $admin = User::factory()->createOne(['role' => UserRole::SuperAdmin]); actingAs($admin, 'backend'); - $uuid = Uuid::uuid7()->toString(); + $uuid = UuidHelper::v7()->toString(); // WHEN $withFilter = get(route('bo.shops.index', ['pickup-exception' => $uuid])); @@ -74,7 +74,7 @@ describe('IndexShopRequest', function (): void { // GIVEN $authService = \Mockery::mock(AppAdminAuthService::class); $session = new Store('test', new ArraySessionHandler(120)); - $uuidV7 = Uuid::uuid7()->toString(); + $uuidV7 = UuidHelper::v7()->toString(); $session->put(IndexShopRequest::SESSION_KEY, $uuidV7); $request = new IndexShopRequest($authService); @@ -90,7 +90,7 @@ describe('IndexShopRequest', function (): void { ->and((string) $request->getPickupExceptionId())->toBe($uuidV7); // GIVEN - $session->put(IndexShopRequest::SESSION_KEY, Uuid::uuid4()->toString()); + $session->put(IndexShopRequest::SESSION_KEY, UuidHelper::v4()->toString()); // WHEN & THEN expect($request->toPickupExceptionId())->toBeNull(); diff --git a/tests/Feature/App/Http/Requests/Fo/Auth/RegisterRequestTest.php b/tests/Feature/App/Http/Requests/Fo/Auth/RegisterRequestTest.php index d11dca6f..193b1083 100644 --- a/tests/Feature/App/Http/Requests/Fo/Auth/RegisterRequestTest.php +++ b/tests/Feature/App/Http/Requests/Fo/Auth/RegisterRequestTest.php @@ -17,7 +17,7 @@ use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\Validator; use Infrastructure\Adapters\Services\AppCustomerAuthService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('RegisterRequest', function (): void { @@ -84,7 +84,7 @@ describe('RegisterRequest', function (): void { it('rejects matricule and code when employee already has a customer_id', function (): void { // GIVEN $customer = new Customer(['email' => new Email('existing@example.com')]); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->saveOrFail(); $employee = new Employee(); diff --git a/tests/Feature/App/Http/Requests/Fo/ContactFormRequestTest.php b/tests/Feature/App/Http/Requests/Fo/ContactFormRequestTest.php index 2f28960a..012cb60b 100644 --- a/tests/Feature/App/Http/Requests/Fo/ContactFormRequestTest.php +++ b/tests/Feature/App/Http/Requests/Fo/ContactFormRequestTest.php @@ -9,7 +9,7 @@ use Domain\Models\ValueObjects\OrderReference; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ContactFormRequest', function () { it('validates correct rules', function () { @@ -23,7 +23,7 @@ describe('ContactFormRequest', function () { 'first_name' => 'John', 'email' => 'john.doe@gmail.com', 'subject' => 'Help with my order', - 'order_ref' => (string) new OrderReference(Uuid::uuid7()), + 'order_ref' => (string) new OrderReference(UuidHelper::v7()), 'message' => 'This is a message that is longer than 20 characters.', 'ok_cgv' => true, ]); @@ -108,7 +108,7 @@ describe('ContactFormRequest', function () { it('converts to action input without file', function () { // GIVEN - $orderRef = new OrderReference(Uuid::uuid7()); + $orderRef = new OrderReference(UuidHelper::v7()); $request = new ContactFormRequest(); $request->initialize(); $request->merge([ diff --git a/tests/Feature/App/Http/Requests/Fo/Orders/ConfirmOrderRequestTest.php b/tests/Feature/App/Http/Requests/Fo/Orders/ConfirmOrderRequestTest.php index 2e19b5ee..8851cc76 100644 --- a/tests/Feature/App/Http/Requests/Fo/Orders/ConfirmOrderRequestTest.php +++ b/tests/Feature/App/Http/Requests/Fo/Orders/ConfirmOrderRequestTest.php @@ -9,7 +9,7 @@ use App\Models\Customer; use Domain\Models\ValueObjects\Entities\ShopperId; use Illuminate\Support\Facades\Validator; use Infrastructure\Adapters\Services\AppCustomerAuthService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ConfirmOrderRequest', function (): void { it('authorizes only when customer auth service returns true', function (): void { @@ -47,7 +47,7 @@ describe('ConfirmOrderRequest', function (): void { it('maps to PlacePendingOrderInput', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $customer = new Customer(); $customer->id = $shopperId->value->toString(); diff --git a/tests/Feature/App/Http/Requests/Fo/Orders/PickTimeSlotRequestTest.php b/tests/Feature/App/Http/Requests/Fo/Orders/PickTimeSlotRequestTest.php index eb6b4ab2..9fa17dfa 100644 --- a/tests/Feature/App/Http/Requests/Fo/Orders/PickTimeSlotRequestTest.php +++ b/tests/Feature/App/Http/Requests/Fo/Orders/PickTimeSlotRequestTest.php @@ -23,7 +23,7 @@ use Domain\Ports\Repositories\ShopperRepository; use Domain\Services\OrderTunnelService; use Illuminate\Support\Facades\Validator; use Infrastructure\Adapters\Services\AppCustomerAuthService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; const VALID_TIMESLOT_DATE = '2023-10-15'; @@ -88,11 +88,11 @@ describe('PickTimeSlotRequest', function (): void { it('fails basketTotal validation when weekly limit is exceeded', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $customer = new Customer(); $customer->id = $shopperId->value->toString(); - $basket = new Basket(new BasketId(Uuid::uuid7()), []); + $basket = new Basket(new BasketId(UuidHelper::v7()), []); $shopper = new Shopper( $shopperId, new Email('shopper@example.com'), @@ -160,7 +160,7 @@ describe('PickTimeSlotRequest', function (): void { it('maps to ApplyPickTimeSlotInput', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $customer = new Customer(); $customer->id = $shopperId->value->toString(); diff --git a/tests/Feature/App/Http/Requests/Fo/Orders/ValidateSummaryRequestTest.php b/tests/Feature/App/Http/Requests/Fo/Orders/ValidateSummaryRequestTest.php index 621a00f5..1d6e842d 100644 --- a/tests/Feature/App/Http/Requests/Fo/Orders/ValidateSummaryRequestTest.php +++ b/tests/Feature/App/Http/Requests/Fo/Orders/ValidateSummaryRequestTest.php @@ -14,7 +14,7 @@ use Domain\Services\BasketService; use Domain\Services\OrderTunnelService; use Illuminate\Support\Facades\Validator; use Infrastructure\Adapters\Services\AppCustomerAuthService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ValidateSummaryRequest', function (): void { it('authorizes only when customer auth service returns true', function (): void { @@ -40,7 +40,7 @@ describe('ValidateSummaryRequest', function (): void { it('fails basketTotal validation when order limit is exceeded', function (): void { // GIVEN - $basket = new Basket(new BasketId(Uuid::uuid7()), []); + $basket = new Basket(new BasketId(UuidHelper::v7()), []); $authService = \Mockery::mock(AppCustomerAuthService::class); $basketService = \Mockery::mock(BasketService::class); @@ -70,11 +70,11 @@ describe('ValidateSummaryRequest', function (): void { it('maps to InitializeOrderTunnelInput', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $customer = new Customer(); $customer->id = $shopperId->value->toString(); - $basket = new Basket(new BasketId(Uuid::uuid7()), []); + $basket = new Basket(new BasketId(UuidHelper::v7()), []); $authService = \Mockery::mock(AppCustomerAuthService::class); $authService->shouldReceive('getCustomerAsMandatory')->once()->andReturn($customer); diff --git a/tests/Feature/App/Http/Requests/Fo/UnsubscribeNewsletterRequestTest.php b/tests/Feature/App/Http/Requests/Fo/UnsubscribeNewsletterRequestTest.php index 8749c31d..1504aaef 100644 --- a/tests/Feature/App/Http/Requests/Fo/UnsubscribeNewsletterRequestTest.php +++ b/tests/Feature/App/Http/Requests/Fo/UnsubscribeNewsletterRequestTest.php @@ -6,7 +6,7 @@ namespace Tests\Feature\App\Http\Requests\Fo; use App\Http\Requests\Fo\UnsubscribeNewsletterRequest; use Illuminate\Support\Facades\Validator; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('UnsubscribeNewsletterRequest', function () { it('validates correct rules', function () { @@ -14,7 +14,7 @@ describe('UnsubscribeNewsletterRequest', function () { $request = new UnsubscribeNewsletterRequest(); $request->initialize(); $request->merge([ - 'hashcode' => Uuid::uuid4()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), ]); // WHEN @@ -58,7 +58,7 @@ describe('UnsubscribeNewsletterRequest', function () { // GIVEN $request = new UnsubscribeNewsletterRequest(); $request->initialize(); - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); $request->merge([ 'hashcode' => $uuid->toString(), ]); diff --git a/tests/Feature/App/Jobs/SendMissingOrderReminderJobTest.php b/tests/Feature/App/Jobs/SendMissingOrderReminderJobTest.php index 9628d687..3808c6b2 100644 --- a/tests/Feature/App/Jobs/SendMissingOrderReminderJobTest.php +++ b/tests/Feature/App/Jobs/SendMissingOrderReminderJobTest.php @@ -37,7 +37,7 @@ use Illuminate\Support\Facades\Notification; use Illuminate\Support\Str; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('SendMissingOrderReminderJob', function (): void { it('dispatches MissingOrderReminderNotification once per week with precomputed cutoff and ICS content', function (): void { @@ -134,7 +134,7 @@ describe('SendMissingOrderReminderJob', function (): void { ]); $exception = new PickupExceptionOnDate( - id: new PickupExceptionId(Uuid::uuid7()), + id: new PickupExceptionId(UuidHelper::v7()), date: CarbonImmutable::parse('2026-11-20', 'Europe/Paris'), label: 'Fermeture exceptionnelle', repeatable: false, @@ -194,9 +194,9 @@ describe('SendMissingOrderReminderJob', function (): void { ]); Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2500, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -229,7 +229,7 @@ describe('SendMissingOrderReminderJob', function (): void { ]); $exception = new PickupExceptionOnDate( - id: new PickupExceptionId(Uuid::uuid7()), + id: new PickupExceptionId(UuidHelper::v7()), date: CarbonImmutable::parse('2026-11-20', 'Europe/Paris'), label: 'Décalage jeudi', repeatable: false, diff --git a/tests/Feature/App/Jobs/SendReminderMailTest.php b/tests/Feature/App/Jobs/SendReminderMailTest.php index 6a9992ca..25cc87ce 100644 --- a/tests/Feature/App/Jobs/SendReminderMailTest.php +++ b/tests/Feature/App/Jobs/SendReminderMailTest.php @@ -34,7 +34,7 @@ use Money\Currency; use Money\Money; use Money\MoneyFormatter; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('SendReminderMail job', function (): void { it('sends today reminder once and marks orders as reminded idempotently', function (): void { @@ -60,9 +60,9 @@ describe('SendReminderMail job', function (): void { ]); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(3000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -126,9 +126,9 @@ describe('SendReminderMail job', function (): void { ]); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(3000, new Currency('EUR')), 'employee' => new OrderEmployee( diff --git a/tests/Feature/App/Listeners/Orders/SendAdminOrderConfirmationTest.php b/tests/Feature/App/Listeners/Orders/SendAdminOrderConfirmationTest.php index 851ebcab..fde7b6ad 100644 --- a/tests/Feature/App/Listeners/Orders/SendAdminOrderConfirmationTest.php +++ b/tests/Feature/App/Listeners/Orders/SendAdminOrderConfirmationTest.php @@ -22,13 +22,13 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Mail; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function makeOrderPlacedEvent(): AnOrderHasBeenPlaced { return new AnOrderHasBeenPlaced( - orderId: new OrderId(Uuid::uuid7()), - reference: new OrderReference(Uuid::uuid7()), + orderId: new OrderId(UuidHelper::v7()), + reference: new OrderReference(UuidHelper::v7()), totalTtc: new Money(1500, new Currency('EUR')), byMatricule: new Matricule('1234567'), employee: new OrderEmployee( diff --git a/tests/Feature/App/Listeners/Orders/SendCustomerOrderConfirmationTest.php b/tests/Feature/App/Listeners/Orders/SendCustomerOrderConfirmationTest.php index 750f93ea..40250500 100644 --- a/tests/Feature/App/Listeners/Orders/SendCustomerOrderConfirmationTest.php +++ b/tests/Feature/App/Listeners/Orders/SendCustomerOrderConfirmationTest.php @@ -23,13 +23,13 @@ use Domain\Models\ValueObjects\ShopperSiteCode; use Illuminate\Support\Facades\Notification; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function makeCustomerOrderPlacedEvent(string $matricule): AnOrderHasBeenPlaced { return new AnOrderHasBeenPlaced( - orderId: new OrderId(Uuid::uuid7()), - reference: new OrderReference(Uuid::uuid7()), + orderId: new OrderId(UuidHelper::v7()), + reference: new OrderReference(UuidHelper::v7()), totalTtc: new Money(1500, new Currency('EUR')), byMatricule: new Matricule($matricule), employee: new OrderEmployee( diff --git a/tests/Feature/App/Listeners/UpdateCustomerLastLoginTest.php b/tests/Feature/App/Listeners/UpdateCustomerLastLoginTest.php index 55afe162..54802504 100644 --- a/tests/Feature/App/Listeners/UpdateCustomerLastLoginTest.php +++ b/tests/Feature/App/Listeners/UpdateCustomerLastLoginTest.php @@ -13,32 +13,34 @@ use Illuminate\Auth\Events\Login; use Illuminate\Support\Facades\Date; use Infrastructure\Adapters\Events\LaravelDomainEventDispatcher; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; use Shared\Concurrency\Lock; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; -it('updates customer last_login_at via Executor when Login event is handled', function (): void { - // GIVEN - Date::setTestNow('2026-11-14 14:00:00'); - $customer = new Customer(); - $customer->email = new Email('login@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); - $customer->last_login_at = null; - $customer->saveOrFail(); +describe('UpdateCustomerLastLogin', function (): void { + it('updates customer last_login_at via Executor when Login event is handled', function (): void { + // GIVEN + Date::setTestNow('2026-11-14 14:00:00'); + $customer = new Customer(); + $customer->email = new Email('login@example.com'); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); + $customer->last_login_at = null; + $customer->saveOrFail(); - $executor = new ActionExecutorService( - lock: \Mockery::mock(Lock::class), - logger: new NullLogger(), - eventDispatcher: new LaravelDomainEventDispatcher(), - ); - $listener = new UpdateCustomerLastLogin($executor, new UpdateCustomerLastLoginAction()); + $executor = new ActionExecutorService( + lock: \Mockery::mock(Lock::class), + logger: new NullLogger(), + eventDispatcher: new LaravelDomainEventDispatcher(), + ); + $listener = new UpdateCustomerLastLogin($executor, new UpdateCustomerLastLoginAction()); - // WHEN - $listener->handle(new Login('frontend', $customer, false)); + // WHEN + $listener->handle(new Login('frontend', $customer, false)); - // THEN - $customer->refresh(); - expect($customer->last_login_at?->format('Y-m-d H:i:s'))->toBe('2026-11-14 14:00:00'); + // THEN + $customer->refresh(); + expect($customer->last_login_at?->format('Y-m-d H:i:s'))->toBe('2026-11-14 14:00:00'); - Date::setTestNow(); + Date::setTestNow(); + }); }); diff --git a/tests/Integration/Standalones/Infra/Adapters/Repositories/SessionBasketRepositoryTest.php b/tests/Integration/Standalones/Infra/Adapters/Repositories/SessionBasketRepositoryTest.php index e01cb739..80607fc9 100644 --- a/tests/Integration/Standalones/Infra/Adapters/Repositories/SessionBasketRepositoryTest.php +++ b/tests/Integration/Standalones/Infra/Adapters/Repositories/SessionBasketRepositoryTest.php @@ -10,14 +10,14 @@ use Illuminate\Session\ArraySessionHandler; use Illuminate\Session\Store; use Infrastructure\Adapters\Repositories\SessionBasketRepository; use Infrastructure\Adapters\Serializers\BasketSerializer; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; covers(SessionBasketRepository::class); describe('SessionBasketRepository', function (): void { it('returns null if session is empty', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $session = new Store('test', new ArraySessionHandler(120)); $repo = new SessionBasketRepository($session, 'basket_key', new BasketSerializer()); @@ -30,7 +30,7 @@ describe('SessionBasketRepository', function (): void { it('persists and retrieves a basket using real Store and BasketSerializer', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId, []); $session = new Store('test', new ArraySessionHandler(120)); $repo = new SessionBasketRepository($session, 'basket_key', new BasketSerializer()); @@ -47,7 +47,7 @@ describe('SessionBasketRepository', function (): void { it('returns null if session data is invalid json', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $session = new Store('test', new ArraySessionHandler(120)); $session->put('basket_key' . $basketId->value->toString(), 'invalid-json'); $repo = new SessionBasketRepository($session, 'basket_key', new BasketSerializer()); @@ -61,7 +61,7 @@ describe('SessionBasketRepository', function (): void { it('returns null if deserialization throws exception', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $session = new Store('test', new ArraySessionHandler(120)); $session->put('basket_key' . $basketId->value->toString(), '{"invalid":"payload"}'); $repo = new SessionBasketRepository($session, 'basket_key', new BasketSerializer()); @@ -75,7 +75,7 @@ describe('SessionBasketRepository', function (): void { it('deletes basket from session', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId, []); $session = new Store('test', new ArraySessionHandler(120)); $repo = new SessionBasketRepository($session, 'basket_key', new BasketSerializer()); diff --git a/tests/Integration/Standalones/Infra/Adapters/Services/SessionOrderBuilderManagerTest.php b/tests/Integration/Standalones/Infra/Adapters/Services/SessionOrderBuilderManagerTest.php index 66f51a63..b1ffc87f 100644 --- a/tests/Integration/Standalones/Infra/Adapters/Services/SessionOrderBuilderManagerTest.php +++ b/tests/Integration/Standalones/Infra/Adapters/Services/SessionOrderBuilderManagerTest.php @@ -11,7 +11,7 @@ use Domain\Models\ValueObjects\Entities\ShopperId; use Illuminate\Session\ArraySessionHandler; use Illuminate\Session\Store; use Infrastructure\Adapters\Services\SessionOrderBuilderManager; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('SessionOrderBuilderManager', function (): void { it('throws exception if session key is empty', function (): void { @@ -29,8 +29,8 @@ describe('SessionOrderBuilderManager', function (): void { // GIVEN $session = new Store('test', new ArraySessionHandler(120)); $builder = OrderBuilder::fromBasket( - new Basket(new BasketId(Uuid::uuid7()), []), - new ShopperId(Uuid::uuid7()), + new Basket(new BasketId(UuidHelper::v7()), []), + new ShopperId(UuidHelper::v7()), ); $session->put('builder_key', $builder); $manager = new SessionOrderBuilderManager($session, 'builder_key'); @@ -71,8 +71,8 @@ describe('SessionOrderBuilderManager', function (): void { // GIVEN $session = new Store('test', new ArraySessionHandler(120)); $builder = OrderBuilder::fromBasket( - new Basket(new BasketId(Uuid::uuid7()), []), - new ShopperId(Uuid::uuid7()), + new Basket(new BasketId(UuidHelper::v7()), []), + new ShopperId(UuidHelper::v7()), ); $manager = new SessionOrderBuilderManager($session, 'builder_key'); @@ -88,8 +88,8 @@ describe('SessionOrderBuilderManager', function (): void { // GIVEN $session = new Store('test', new ArraySessionHandler(120)); $builder = OrderBuilder::fromBasket( - new Basket(new BasketId(Uuid::uuid7()), []), - new ShopperId(Uuid::uuid7()), + new Basket(new BasketId(UuidHelper::v7()), []), + new ShopperId(UuidHelper::v7()), ); $session->put('builder_key', $builder); $manager = new SessionOrderBuilderManager($session, 'builder_key'); diff --git a/tests/Integration/WithApp/App/Casts/OrderLineProductCastTest.php b/tests/Integration/WithApp/App/Casts/OrderLineProductCastTest.php index 9dd90386..b818b461 100644 --- a/tests/Integration/WithApp/App/Casts/OrderLineProductCastTest.php +++ b/tests/Integration/WithApp/App/Casts/OrderLineProductCastTest.php @@ -16,7 +16,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; covers(OrderLineProductCast::class); @@ -49,7 +49,7 @@ describe('OrderLineProductCast', function () { // GIVEN $cast = new OrderLineProductCast(); $model = \Mockery::mock(Model::class); - $uuid = Uuid::uuid7()->toString(); + $uuid = UuidHelper::v7()->toString(); $json = json_encode([ 'inco_id' => 123, @@ -83,7 +83,7 @@ describe('OrderLineProductCast', function () { // GIVEN $cast = new OrderLineProductCast(); $model = \Mockery::mock(Model::class); - $uuid = Uuid::uuid7()->toString(); + $uuid = UuidHelper::v7()->toString(); $json = json_encode([ 'inco_id' => 123, @@ -131,7 +131,7 @@ describe('OrderLineProductCast', function () { $product = new OrderLineProduct( incoId: new IncoId(123), - originalId: new ProductId(Uuid::uuid7()), + originalId: new ProductId(UuidHelper::v7()), name: 'Product Name', weight: new ProductWeight(1000, false), brand: ProductBrand::cases()[0], // Pick first enum case diff --git a/tests/Integration/WithApp/App/Casts/OrderReferenceCastTest.php b/tests/Integration/WithApp/App/Casts/OrderReferenceCastTest.php index 8a01f98b..9a47ba67 100644 --- a/tests/Integration/WithApp/App/Casts/OrderReferenceCastTest.php +++ b/tests/Integration/WithApp/App/Casts/OrderReferenceCastTest.php @@ -7,87 +7,88 @@ namespace Tests\Integration\WithApp\App\Casts; use App\Casts\OrderReferenceCast; use Domain\Models\ValueObjects\OrderReference; use Illuminate\Database\Eloquent\Model; -use Ramsey\Uuid\Uuid; use Shared\Helpers\UuidHelper; -it('gets a reference', function () { - // GIVEN - $cast = new OrderReferenceCast(); - $model = \Mockery::mock(Model::class); - $uuid = Uuid::uuid7(); - $value = UuidHelper::toBase58($uuid); +describe('OrderReferenceCast', function (): void { + it('gets a reference', function () { + // GIVEN + $cast = new OrderReferenceCast(); + $model = \Mockery::mock(Model::class); + $uuid = UuidHelper::v7(); + $value = UuidHelper::toBase58($uuid); - // WHEN - $reference = $cast->get($model, 'reference', $value, []); + // WHEN + $reference = $cast->get($model, 'reference', $value, []); - // THEN - expect((string) $reference)->toBe($value) - ->and($reference->value->equals($uuid))->toBeTrue(); -}); - -it('gets a reference from raw uuid string', function () { - // GIVEN - $cast = new OrderReferenceCast(); - $model = \Mockery::mock(Model::class); - $uuid = Uuid::uuid7(); - $value = $uuid->toString(); - - // WHEN - $reference = $cast->get($model, 'reference', $value, []); - - // THEN - expect((string) $reference)->toBe(UuidHelper::toBase58($uuid)) - ->and($reference->value->equals($uuid))->toBeTrue(); -}); - -it('throws exception when getting invalid reference', function () { - // GIVEN - $cast = new OrderReferenceCast(); - $model = \Mockery::mock(Model::class); - - // WHEN - $cast->get($model, 'reference', 123, []); - - // THEN -})->throws(\UnexpectedValueException::class, 'OrderReference cannot be null.'); - -it('throws exception when getting null reference', function () { - // GIVEN - $cast = new OrderReferenceCast(); - $model = \Mockery::mock(Model::class); - - // WHEN - $cast->get($model, 'reference', null, []); - - // THEN -})->throws(\UnexpectedValueException::class, 'OrderReference cannot be null.'); - -it('throws exception when setting invalid reference type', function () { - // GIVEN - $cast = new OrderReferenceCast(); - $model = \Mockery::mock(Model::class); - $value = UuidHelper::toBase58(Uuid::uuid7()); - - // WHEN - /** @phpstan-ignore argument.type */ - $cast->set($model, 'reference', $value, []); - - // THEN -})->throws( - \UnexpectedValueException::class, - 'The given value is not an instance of OrderReference.' -); - -it('sets a reference', function () { - // GIVEN - $cast = new OrderReferenceCast(); - $model = \Mockery::mock(Model::class); - $uuid = Uuid::uuid7(); - $reference = new OrderReference($uuid); - - // WHEN - $value = $cast->set($model, 'reference', $reference, []); - - // THEN - expect($value)->toBe(UuidHelper::toBase58($uuid)); + // THEN + expect((string) $reference)->toBe($value) + ->and($reference->value->equals($uuid))->toBeTrue(); + }); + + it('gets a reference from raw uuid string', function () { + // GIVEN + $cast = new OrderReferenceCast(); + $model = \Mockery::mock(Model::class); + $uuid = UuidHelper::v7(); + $value = $uuid->toString(); + + // WHEN + $reference = $cast->get($model, 'reference', $value, []); + + // THEN + expect((string) $reference)->toBe(UuidHelper::toBase58($uuid)) + ->and($reference->value->equals($uuid))->toBeTrue(); + }); + + it('throws exception when getting invalid reference', function () { + // GIVEN + $cast = new OrderReferenceCast(); + $model = \Mockery::mock(Model::class); + + // WHEN + $cast->get($model, 'reference', 123, []); + + // THEN + })->throws(\UnexpectedValueException::class, 'OrderReference cannot be null.'); + + it('throws exception when getting null reference', function () { + // GIVEN + $cast = new OrderReferenceCast(); + $model = \Mockery::mock(Model::class); + + // WHEN + $cast->get($model, 'reference', null, []); + + // THEN + })->throws(\UnexpectedValueException::class, 'OrderReference cannot be null.'); + + it('throws exception when setting invalid reference type', function () { + // GIVEN + $cast = new OrderReferenceCast(); + $model = \Mockery::mock(Model::class); + $value = UuidHelper::toBase58(UuidHelper::v7()); + + // WHEN + /** @phpstan-ignore argument.type */ + $cast->set($model, 'reference', $value, []); + + // THEN + })->throws( + \UnexpectedValueException::class, + 'The given value is not an instance of OrderReference.' + ); + + it('sets a reference', function () { + // GIVEN + $cast = new OrderReferenceCast(); + $model = \Mockery::mock(Model::class); + $uuid = UuidHelper::v7(); + $reference = new OrderReference($uuid); + + // WHEN + $value = $cast->set($model, 'reference', $reference, []); + + // THEN + expect($value)->toBe(UuidHelper::toBase58($uuid)); + }); }); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Basket/AddToBasketTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Basket/AddToBasketTest.php index f0294da8..f407f3c9 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Basket/AddToBasketTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Basket/AddToBasketTest.php @@ -33,7 +33,7 @@ use Infrastructure\Adapters\Services\AppSessionService; use Infrastructure\Adapters\Services\SessionOrderBuilderManager; use Money\Money; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function makeBasketProductFixture(bool $status = true, bool $withInco = true): Product { @@ -112,8 +112,8 @@ describe('AddToBasket action', function (): void { $repository = new SessionBasketRepository($session, 'basket_', new BasketSerializer()); $builderManager = new SessionOrderBuilderManager($session, 'order_tunnel_builder_session'); $builderManager->save(OrderBuilder::fromBasket( - new Basket(new BasketId(Uuid::uuid7()), []), - new ShopperId(Uuid::uuid7()), + new Basket(new BasketId(UuidHelper::v7()), []), + new ShopperId(UuidHelper::v7()), )); $dispatcher = new LaravelDomainEventDispatcher(); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Basket/EmptyBasketTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Basket/EmptyBasketTest.php index 86fa7928..38535638 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Basket/EmptyBasketTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Basket/EmptyBasketTest.php @@ -32,7 +32,7 @@ use Infrastructure\Adapters\Services\AppSessionService; use Infrastructure\Adapters\Services\SessionOrderBuilderManager; use Money\Money; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('EmptyBasket action', function (): void { it('removes all items from session basket and clears order builder', function (): void { @@ -82,8 +82,8 @@ describe('EmptyBasket action', function (): void { $basketSvc->add($product->getId(), 2); $builderManager->save(OrderBuilder::fromBasket( - new Basket(new BasketId(Uuid::uuid7()), []), - new ShopperId(Uuid::uuid7()), + new Basket(new BasketId(UuidHelper::v7()), []), + new ShopperId(UuidHelper::v7()), )); $executor = new ActionExecutorService( diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Basket/RemoveFromBasketTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Basket/RemoveFromBasketTest.php index ab37e5a1..6bded19c 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Basket/RemoveFromBasketTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Basket/RemoveFromBasketTest.php @@ -33,7 +33,7 @@ use Infrastructure\Adapters\Services\AppSessionService; use Infrastructure\Adapters\Services\SessionOrderBuilderManager; use Money\Money; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function makeRemovableProductFixture(): Product { @@ -120,8 +120,8 @@ describe('RemoveFromBasket action', function (): void { $basketSvc->add($product2->getId(), 2); $builderManager->save(OrderBuilder::fromBasket( - new Basket(new BasketId(Uuid::uuid7()), []), - new ShopperId(Uuid::uuid7()), + new Basket(new BasketId(UuidHelper::v7()), []), + new ShopperId(UuidHelper::v7()), )); $executor = new ActionExecutorService( diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Contact/SubmitContactFormTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Contact/SubmitContactFormTest.php index 4e3a860f..d03e0d04 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Contact/SubmitContactFormTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Contact/SubmitContactFormTest.php @@ -11,7 +11,7 @@ use App\Lib\PrivateS3Disk; use Domain\Models\ValueObjects\AttachedFile; use Domain\Models\ValueObjects\OrderReference; use Illuminate\Http\UploadedFile; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Contracts\StorageService; use Uwil\Storage\Lib\ValueObjects\DiskName; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; @@ -22,7 +22,7 @@ describe('SubmitContactForm action', function (): void { $storage = \Mockery::mock(StorageService::class); $storage->shouldNotReceive('storeUploadedOntoDisk'); $action = new SubmitContactForm($storage, new PrivateS3Disk()); - $orderRef = new OrderReference(Uuid::uuid7()); + $orderRef = new OrderReference(UuidHelper::v7()); $input = new SubmitContactFormInput( lastName: 'Doe', firstName: 'John', diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Crm/UnsubscribeFromNewsletterTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Crm/UnsubscribeFromNewsletterTest.php index 42e68d77..d3ce64b6 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Crm/UnsubscribeFromNewsletterTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Crm/UnsubscribeFromNewsletterTest.php @@ -8,13 +8,13 @@ use App\Cqs\Actions\Crm\UnsubscribeFromNewsletter; use App\Cqs\Actions\Crm\UnsubscribeFromNewsletterInput; use App\Cqs\Actions\Crm\UnsubscribeFromNewsletterOutput; use App\Services\CrmService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('UnsubscribeFromNewsletter action', function (): void { it('returns SUCCESS when CRM service unsubscribes the customer', function (): void { // GIVEN - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); /** @var \App\Services\CrmService&\Mockery\MockInterface $crmService */ $crmService = \Mockery::mock(CrmService::class); @@ -34,7 +34,7 @@ describe('UnsubscribeFromNewsletter action', function (): void { it('returns FAILURE when CRM service returns false', function (): void { // GIVEN - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); /** @var \App\Services\CrmService&\Mockery\MockInterface $crmService */ $crmService = \Mockery::mock(CrmService::class); @@ -54,7 +54,7 @@ describe('UnsubscribeFromNewsletter action', function (): void { it('returns FAILURE without throwing when CRM service throws an exception', function (): void { // GIVEN - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); /** @var \App\Services\CrmService&\Mockery\MockInterface $crmService */ $crmService = \Mockery::mock(CrmService::class); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Crm/UpdateCustomerPasswordTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Crm/UpdateCustomerPasswordTest.php index 40c12fc3..fd1e567e 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Crm/UpdateCustomerPasswordTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Crm/UpdateCustomerPasswordTest.php @@ -14,7 +14,7 @@ use Domain\Models\ValueObjects\CrmCustomer; use Domain\Models\ValueObjects\Email; use Illuminate\Support\Facades\Auth; use Infrastructure\Adapters\Services\AppCustomerAuthService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; function makePasswordTestCrmCustomer(string $hashcode, string $email): CrmCustomer @@ -42,7 +42,7 @@ describe('UpdateCustomerPassword action', function (): void { it('changes password in CRM for authenticated customer', function (): void { /** @var \Tests\TestCase $this */ // GIVEN - $hashcodeUuid = Uuid::uuid4(); + $hashcodeUuid = UuidHelper::v4(); $hashcode = $hashcodeUuid->toString(); $customer = new Customer(); $customer->email = new Email('claire.dupuis@example.com'); @@ -79,7 +79,7 @@ describe('UpdateCustomerPassword action', function (): void { // GIVEN $customer = new Customer(); $customer->email = new Email('missing.crm@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->saveOrFail(); $this->actingAs($customer, 'frontend'); @@ -104,7 +104,7 @@ describe('UpdateCustomerPassword action', function (): void { it('returns false output when changePassword throws an unexpected exception', function (): void { /** @var \Tests\TestCase $this */ // GIVEN - $hashcodeUuid = Uuid::uuid4(); + $hashcodeUuid = UuidHelper::v4(); $hashcode = $hashcodeUuid->toString(); $customer = new Customer(); $customer->email = new Email('pwd.error@example.com'); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Crm/UpdateCustomerTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Crm/UpdateCustomerTest.php index ffa16dbe..059f0211 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Crm/UpdateCustomerTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Crm/UpdateCustomerTest.php @@ -15,7 +15,7 @@ use Domain\Models\ValueObjects\Email; use Illuminate\Support\Facades\Auth; use Illuminate\Validation\ValidationException; use Infrastructure\Adapters\Services\AppCustomerAuthService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; function makeCrmCustomerDto(string $hashcode, string $email): CrmCustomer @@ -43,7 +43,7 @@ describe('UpdateCustomer action', function (): void { it('updates customer information in CRM for the authenticated customer', function (): void { /** @var \Tests\TestCase $this */ // GIVEN - $hashcodeUuid = Uuid::uuid4(); + $hashcodeUuid = UuidHelper::v4(); $hashcode = $hashcodeUuid->toString(); $customer = new Customer(); $customer->email = new Email('jeanne.martin@example.com'); @@ -97,7 +97,7 @@ describe('UpdateCustomer action', function (): void { it('omits nullable phone and address when null and propagates validation exceptions', function (): void { /** @var \Tests\TestCase $this */ // GIVEN - $hashcodeUuid = Uuid::uuid4(); + $hashcodeUuid = UuidHelper::v4(); $customer = new Customer(); $customer->email = new Email('no.phone@example.com'); $customer->hashcode = new CrmHashcode($hashcodeUuid); @@ -144,7 +144,7 @@ describe('UpdateCustomer action', function (): void { // GIVEN $customer = new Customer(); $customer->email = new Email('err.crm@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->saveOrFail(); $this->actingAs($customer, 'frontend'); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Customers/RegisterCustomerTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Customers/RegisterCustomerTest.php index df76db1f..876281d5 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Customers/RegisterCustomerTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Customers/RegisterCustomerTest.php @@ -34,9 +34,9 @@ use Illuminate\Validation\ValidationException; use Infrastructure\Adapters\Events\LaravelDomainEventDispatcher; use Infrastructure\Adapters\Services\AppCustomerAuthService; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; use Shared\Concurrency\Lock; use Shared\Concurrency\LockTimeoutException; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('RegisterCustomer action', function (): void { @@ -62,7 +62,7 @@ describe('RegisterCustomer action', function (): void { $employee->service = new ShopperServiceCode('1'); $employee->saveOrFail(); - $crmReturnedHashcode = Uuid::uuid4()->toString(); + $crmReturnedHashcode = UuidHelper::v4()->toString(); $crmService = \Mockery::mock(CrmService::class); $crmService->shouldReceive('persist') @@ -138,7 +138,7 @@ describe('RegisterCustomer action', function (): void { it('returns EMPLOYEE_ALREADY_REGISTERED when employee already has a customer_id', function (): void { // GIVEN $existingCustomer = new Customer(['email' => new Email('already@example.com')]); - $existingCustomer->hashcode = new CrmHashcode(Uuid::uuid4()); + $existingCustomer->hashcode = new CrmHashcode(UuidHelper::v4()); $existingCustomer->saveOrFail(); $matricule = new Matricule('5678901'); @@ -576,7 +576,7 @@ describe('RegisterCustomer action', function (): void { $employee->service = new ShopperServiceCode('1'); $employee->saveOrFail(); - $crmReturnedHashcode = Uuid::uuid4()->toString(); + $crmReturnedHashcode = UuidHelper::v4()->toString(); $crmService = \Mockery::mock(CrmService::class); $crmService->shouldReceive('persist')->once()->andReturn(new CrmCustomer( @@ -645,7 +645,7 @@ describe('RegisterCustomer action', function (): void { $employee->service = new ShopperServiceCode('1'); $employee->saveOrFail(); - $crmUuid = Uuid::uuid4(); + $crmUuid = UuidHelper::v4(); $crmReturnedHashcode = $crmUuid->toString(); $crmService = \Mockery::mock(CrmService::class); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Customers/UpdateCustomerLastLoginTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Customers/UpdateCustomerLastLoginTest.php index 89dd859a..e9003f68 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Customers/UpdateCustomerLastLoginTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Customers/UpdateCustomerLastLoginTest.php @@ -10,7 +10,7 @@ use App\Cqs\Actions\Customers\UpdateCustomerLastLoginInput; use App\Models\Customer; use Domain\Models\ValueObjects\Email; use Illuminate\Support\Facades\Date; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('UpdateCustomerLastLogin action', function (): void { @@ -19,7 +19,7 @@ describe('UpdateCustomerLastLogin action', function (): void { Date::setTestNow('2026-11-14 10:30:00'); $customer = new Customer(); $customer->email = new Email('customer@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->last_login_at = null; $customer->saveOrFail(); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Orders/ApplyPickTimeSlotTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Orders/ApplyPickTimeSlotTest.php index 18e743e4..a27f113c 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Orders/ApplyPickTimeSlotTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Orders/ApplyPickTimeSlotTest.php @@ -49,7 +49,7 @@ use Infrastructure\Adapters\Services\EloquentEmployeeStatisticsService; use Infrastructure\Adapters\Services\SessionOrderBuilderManager; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('ApplyPickTimeSlot action', function (): void { @@ -73,7 +73,7 @@ describe('ApplyPickTimeSlot action', function (): void { $customer = new Customer(); $customer->email = new Email('slot.buyer@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->saveOrFail(); $employee = new Employee(); @@ -88,8 +88,8 @@ describe('ApplyPickTimeSlot action', function (): void { $employee->service = new ShopperServiceCode('01'); $employee->saveOrFail(); - $productId = new ProductId(Uuid::uuid7()); - $basket = new Basket(new BasketId(Uuid::uuid7()), [ + $productId = new ProductId(UuidHelper::v7()); + $basket = new Basket(new BasketId(UuidHelper::v7()), [ $productId->value->toString() => new BasketProduct( id: $productId, name: 'Filet de Poulet', diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Orders/CancelOrderTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Orders/CancelOrderTest.php index 3e639b20..ea48952e 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Orders/CancelOrderTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Orders/CancelOrderTest.php @@ -21,16 +21,16 @@ use Domain\Services\OrderService; use Infrastructure\Adapters\Repositories\EloquentOrderRepository; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function makeCancelOrderFixture(OrderStatus $status = OrderStatus::VALIDATED): Order { $shop = Shop::factory()->create(); return Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => $status->value, 'total' => new Money(2500, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -63,7 +63,7 @@ describe('CancelOrder action', function (): void { it('returns NOT_FOUND when the order does not exist in database', function (): void { // GIVEN $missingOrder = new Order(); - $missingOrder->id = Uuid::uuid7()->toString(); + $missingOrder->id = UuidHelper::v7()->toString(); $action = new CancelOrder(new OrderService(new EloquentOrderRepository())); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Orders/ClaimTodayOrderReminderTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Orders/ClaimTodayOrderReminderTest.php index 0f8c5c38..e32d88d3 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Orders/ClaimTodayOrderReminderTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Orders/ClaimTodayOrderReminderTest.php @@ -19,16 +19,16 @@ use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ClaimTodayOrderReminder action', function (): void { it('claims an unreminded validated order atomically and rejects duplicate claims', function (): void { // GIVEN $shop = Shop::factory()->create(); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2000, new Currency('EUR')), 'employee' => new OrderEmployee( diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Orders/FailStalePendingOrdersTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Orders/FailStalePendingOrdersTest.php index 97e762b3..97b4575a 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Orders/FailStalePendingOrdersTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Orders/FailStalePendingOrdersTest.php @@ -22,7 +22,7 @@ use Infrastructure\Adapters\Events\LaravelDomainEventDispatcher; use Infrastructure\Adapters\Locks\LaravelCacheLock; use Infrastructure\Adapters\Repositories\EloquentOrderRepository; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('FailStalePendingOrders', function (): void { afterEach(function (): void { @@ -38,10 +38,10 @@ describe('FailStalePendingOrders', function (): void { $shop = Shop::factory()->create(); - $stalePendingId = Uuid::uuid7()->toString(); - $freshPendingId = Uuid::uuid7()->toString(); - $staleWaitingId = Uuid::uuid7()->toString(); - $staleValidatedId = Uuid::uuid7()->toString(); + $stalePendingId = UuidHelper::v7()->toString(); + $freshPendingId = UuidHelper::v7()->toString(); + $staleWaitingId = UuidHelper::v7()->toString(); + $staleValidatedId = UuidHelper::v7()->toString(); $baseRow = [ 'shop_id' => $shop->id, @@ -61,25 +61,25 @@ describe('FailStalePendingOrders', function (): void { DB::table('orders')->insert([ array_merge($baseRow, [ 'id' => $stalePendingId, - 'reference' => (string) new OrderReference(Uuid::uuid7()), + 'reference' => (string) new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::PENDING->value, 'updated_at' => $now->subMinutes(15)->toDateTimeString(), ]), array_merge($baseRow, [ 'id' => $freshPendingId, - 'reference' => (string) new OrderReference(Uuid::uuid7()), + 'reference' => (string) new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::PENDING->value, 'updated_at' => $now->subMinutes(4)->toDateTimeString(), ]), array_merge($baseRow, [ 'id' => $staleWaitingId, - 'reference' => (string) new OrderReference(Uuid::uuid7()), + 'reference' => (string) new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::WAITING->value, 'updated_at' => $now->subHours(2)->toDateTimeString(), ]), array_merge($baseRow, [ 'id' => $staleValidatedId, - 'reference' => (string) new OrderReference(Uuid::uuid7()), + 'reference' => (string) new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'updated_at' => $now->subHours(2)->toDateTimeString(), ]), diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Orders/InitializeOrderTunnelTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Orders/InitializeOrderTunnelTest.php index c474fbb8..a5b1ed40 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Orders/InitializeOrderTunnelTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Orders/InitializeOrderTunnelTest.php @@ -36,7 +36,7 @@ use Infrastructure\Adapters\Services\EloquentEmployeeStatisticsService; use Infrastructure\Adapters\Services\SessionOrderBuilderManager; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('InitializeOrderTunnel action', function (): void { it('stores OrderBuilderWithBasket in session for the shopper and basket', function (): void { @@ -67,8 +67,8 @@ describe('InitializeOrderTunnel action', function (): void { new DatabaseTunnelAttemptTrackerService($session, 'order_tunnel_attempt_id'), ); - $productId = new ProductId(Uuid::uuid7()); - $basket = new Basket(new BasketId(Uuid::uuid7()), [ + $productId = new ProductId(UuidHelper::v7()); + $basket = new Basket(new BasketId(UuidHelper::v7()), [ $productId->value->toString() => new BasketProduct( id: $productId, name: 'Poulet Rôti', @@ -91,9 +91,9 @@ describe('InitializeOrderTunnel action', function (): void { ]); /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'email' => new Email('init-tunnel@example.com'), - 'hashcode' => Uuid::uuid4()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), ]); $shopperId = $customer->getId(); diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Orders/PlacePendingOrderTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Orders/PlacePendingOrderTest.php index d1107e01..48ef9267 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Orders/PlacePendingOrderTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Orders/PlacePendingOrderTest.php @@ -82,9 +82,9 @@ use Infrastructure\Adapters\Services\SessionOrderBuilderManager; use Money\Currency; use Money\Money; use Psr\Log\NullLogger; -use Ramsey\Uuid\Uuid; use Shared\Concurrency\Lock; use Shared\Concurrency\LockTimeoutException; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('Order placement two-step CQS actions', function (): void { @@ -128,9 +128,9 @@ describe('Order placement two-step CQS actions', function (): void { ): array { /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'email' => new Email('buyer-' . uniqid() . '@example.com'), - 'hashcode' => new CrmHashcode(Uuid::uuid4()), + 'hashcode' => new CrmHashcode(UuidHelper::v4()), ]); /** @var int $sequence */ @@ -389,9 +389,9 @@ describe('Order placement two-step CQS actions', function (): void { $ctx = buildOrderPlacementScenario(priceCents: 6000, qty: 1); Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $ctx['shop']->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::PENDING->value, 'total' => Money::EUR(16000), 'employee' => new OrderEmployee( @@ -472,7 +472,7 @@ describe('Order placement two-step CQS actions', function (): void { it('executes ExportOrderToRegate without opening a DB transaction and returns LOCK_TIMEOUT when lock fails', function (): void { // GIVEN - $orderId = new OrderId(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); $input = new ExportOrderToRegateInput($orderId); $levelBeforeExecute = DB::transactionLevel(); $levelInsideAction = null; diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Orders/ReleaseTodayOrderReminderTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Orders/ReleaseTodayOrderReminderTest.php index 82297be7..3aa9d435 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Orders/ReleaseTodayOrderReminderTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Orders/ReleaseTodayOrderReminderTest.php @@ -19,7 +19,7 @@ use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ReleaseTodayOrderReminder action', function (): void { it('releases reminded_at only when timestamp matches the claim timestamp', function (): void { @@ -28,9 +28,9 @@ describe('ReleaseTodayOrderReminder action', function (): void { $otherAt = CarbonImmutable::parse('2026-11-20 10:05:00'); $shop = Shop::factory()->create(); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2000, new Currency('EUR')), 'employee' => new OrderEmployee( diff --git a/tests/Integration/WithApp/App/Cqs/Queries/Basket/GetBasketQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/Basket/GetBasketQueryTest.php index ceb24a0d..3513e394 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/Basket/GetBasketQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/Basket/GetBasketQueryTest.php @@ -27,13 +27,13 @@ use Domain\Ports\Services\SessionService; use Domain\Services\BasketService; use Mockery; use Money\Money; -use Ramsey\Uuid\Uuid; use Shared\DDD\DomainEventDispatcher; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; function makeBasketServiceWithBasket(?Basket $basket): BasketService { - $basketId = $basket !== null ? $basket->id : new BasketId(Uuid::uuid7()); + $basketId = $basket !== null ? $basket->id : new BasketId(UuidHelper::v7()); $sessionId = new SessionId($basketId->value); $sessionService = Mockery::mock(SessionService::class); @@ -135,10 +135,10 @@ describe('GetBasketQuery', function (): void { $unpublishedProduct->price = Money::EUR(1000); $unpublishedProduct->save(); - $publishedId = new ProductId(Uuid::fromString($publishedProduct->id)); - $unpublishedId = new ProductId(Uuid::fromString($unpublishedProduct->id)); + $publishedId = new ProductId(UuidHelper::fromString($publishedProduct->id)); + $unpublishedId = new ProductId(UuidHelper::fromString($unpublishedProduct->id)); - $basket = new Basket(new BasketId(Uuid::uuid7()), [ + $basket = new Basket(new BasketId(UuidHelper::v7()), [ makeBasketProductItem($publishedId, 'Poulet Publié', 2), makeBasketProductItem($unpublishedId, 'Poulet Dépublié', 1), ]); diff --git a/tests/Integration/WithApp/App/Cqs/Queries/Customers/GetCustomerByEmailQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/Customers/GetCustomerByEmailQueryTest.php index 3e7a9557..060033c9 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/Customers/GetCustomerByEmailQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/Customers/GetCustomerByEmailQueryTest.php @@ -9,7 +9,7 @@ use App\Cqs\Queries\Customers\GetCustomerByEmailQueryInput; use App\Models\Customer; use Domain\Models\ValueObjects\Email; use Domain\Models\ValueObjects\Entities\ShopperId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('GetCustomerByEmailQuery', function (): void { @@ -17,7 +17,7 @@ describe('GetCustomerByEmailQuery', function (): void { // GIVEN $email = new Email('john.doe@example.com'); $customer = new Customer(['email' => $email]); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); $query = new GetCustomerByEmailQuery(); diff --git a/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetBoPaginatedOrdersQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetBoPaginatedOrdersQueryTest.php index bc1063fd..af0825fc 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetBoPaginatedOrdersQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetBoPaginatedOrdersQueryTest.php @@ -25,7 +25,7 @@ use Illuminate\Session\Store; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Schema; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\Pagination\PageNumber; use Shared\Pagination\PageSize; use Shared\Pagination\Pagination; @@ -56,9 +56,9 @@ describe('GetBoPaginatedOrdersQuery', function (): void { ): Order { $order = new Order(); if ($createdAt !== null) { - $order->id = (string) Uuid::uuid7($createdAt); + $order->id = (string) UuidHelper::v7($createdAt); } - $order->reference = new OrderReference(Uuid::uuid7()); + $order->reference = new OrderReference(UuidHelper::v7()); $order->total = Money::EUR(2500); $order->status = $status; $order->pickup_day = Carbon::instance($pickupDay); diff --git a/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetBoTodayOrdersQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetBoTodayOrdersQueryTest.php index abfb405e..63e8dda4 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetBoTodayOrdersQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetBoTodayOrdersQueryTest.php @@ -21,7 +21,7 @@ use Domain\Models\ValueObjects\ShopperSiteCode; use Illuminate\Http\Request; use Illuminate\Support\Facades\Date; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\Pagination\PageNumber; use Shared\Pagination\PageSize; use Shared\Pagination\Pagination; @@ -42,7 +42,7 @@ describe('GetBoTodayOrdersQuery', function (): void { $createOrder = static function (OrderStatus $status) use ($shop): Order { $order = new Order(); - $order->reference = new OrderReference(Uuid::uuid7()); + $order->reference = new OrderReference(UuidHelper::v7()); $order->total = Money::EUR(2000); $order->status = $status; $order->pickup_day = Date::now()->addDays(4); diff --git a/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetFoCustomerPaginatedOrdersQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetFoCustomerPaginatedOrdersQueryTest.php index dd0c0b99..c60d6e05 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetFoCustomerPaginatedOrdersQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetFoCustomerPaginatedOrdersQueryTest.php @@ -23,7 +23,7 @@ use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Illuminate\Support\Carbon; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\Pagination\PageNumber; use Shared\Pagination\PageSize; use Shared\Pagination\Pagination; @@ -37,7 +37,7 @@ describe('GetFoCustomerPaginatedOrdersQuery', function (): void { $createCustomer = function (): Customer { $customer = new Customer(); $customer->email = new Email('customer-' . uniqid() . '@example.com'); - $customer->hashcode = new CrmHashcode(Uuid::uuid4()); + $customer->hashcode = new CrmHashcode(UuidHelper::v4()); $customer->save(); return $customer; @@ -72,7 +72,7 @@ describe('GetFoCustomerPaginatedOrdersQuery', function (): void { $createOrder = function (Shop $shop, string $matricule): Order { $order = new Order(); - $order->reference = new OrderReference(Uuid::uuid7()); + $order->reference = new OrderReference(UuidHelper::v7()); $order->total = Money::EUR(2500); $order->status = OrderStatus::WAITING; $order->pickup_day = Carbon::now()->addDays(2); diff --git a/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php index 972932ae..402674a6 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/Orders/GetTunnelOrderConfirmedQueryTest.php @@ -19,7 +19,7 @@ use Domain\Models\ValueObjects\ShopperEstablishmentCode; use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('GetTunnelOrderConfirmedQuery', function (): void { it('returns order confirmed output with step, orderDto, shopDto and mapUrl', function (): void { @@ -32,7 +32,7 @@ describe('GetTunnelOrderConfirmedQuery', function (): void { $shop->default = true; $shop->save(); - $reference = new OrderReference(Uuid::uuid7()); + $reference = new OrderReference(UuidHelper::v7()); $order = new Order(); $order->reference = $reference; @@ -70,7 +70,7 @@ describe('GetTunnelOrderConfirmedQuery', function (): void { it('throws UnexpectedValueException when order has no shop', function (): void { // GIVEN - $reference = new OrderReference(Uuid::uuid7()); + $reference = new OrderReference(UuidHelper::v7()); $order = new Order(); $order->reference = $reference; diff --git a/tests/Integration/WithApp/App/Cqs/Queries/ProductIncos/GetProductIncoForEditQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/ProductIncos/GetProductIncoForEditQueryTest.php index 06cb6ecc..c00ba0a7 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/ProductIncos/GetProductIncoForEditQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/ProductIncos/GetProductIncoForEditQueryTest.php @@ -18,7 +18,7 @@ use Domain\Enums\Units\InvoicingUnit; use Domain\Enums\Units\OrderUnit; use Infrastructure\Adapters\Repositories\EloquentProductRepository; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function createTestProductForIncoQuery(): Product { @@ -41,7 +41,7 @@ function createTestProductForIncoQuery(): Product 'description' => 'Description test', 'status' => true, ]); - $product->id = Uuid::uuid7()->toString(); + $product->id = UuidHelper::v7()->toString(); $product->order = random_int(1, 999999); $product->price = Money::EUR(1000); $product->short_description = 'Court'; diff --git a/tests/Integration/WithApp/App/Cqs/Queries/Products/GetProductWithPricingQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/Products/GetProductWithPricingQueryTest.php index 2ad30406..99b4209c 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/Products/GetProductWithPricingQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/Products/GetProductWithPricingQueryTest.php @@ -23,7 +23,7 @@ use Domain\Models\ValueObjects\Entities\ProductId; use Domain\Models\ValueObjects\Slug; use Infrastructure\Adapters\Repositories\EloquentProductRepository; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; afterEach(function (): void { CarbonImmutable::setTestNow(); @@ -95,7 +95,7 @@ describe('GetProductWithPricingQuery', function (): void { ->and($bySlug?->pricing->discountedPriceHt->getAmount())->toBe('1500'); // WHEN: by ProductId - $byId = $query(new GetProductQueryInput(new ProductId(Uuid::fromString($product->id)))); + $byId = $query(new GetProductQueryInput(new ProductId(UuidHelper::fromString($product->id)))); // THEN expect($byId)->toBeInstanceOf(ProductWithPricingDto::class) @@ -109,7 +109,7 @@ describe('GetProductWithPricingQuery', function (): void { // WHEN $bySlug = $query(new GetProductQueryInput(new Slug('non-existent-slug-' . uniqid()))); - $byId = $query(new GetProductQueryInput(new ProductId(Uuid::uuid7()))); + $byId = $query(new GetProductQueryInput(new ProductId(UuidHelper::v7()))); // THEN expect($bySlug)->toBeNull() diff --git a/tests/Integration/WithApp/App/Cqs/Queries/Timeslots/GetAvailableTimeslotsQueryTest.php b/tests/Integration/WithApp/App/Cqs/Queries/Timeslots/GetAvailableTimeslotsQueryTest.php index 3e81c75d..79721470 100644 --- a/tests/Integration/WithApp/App/Cqs/Queries/Timeslots/GetAvailableTimeslotsQueryTest.php +++ b/tests/Integration/WithApp/App/Cqs/Queries/Timeslots/GetAvailableTimeslotsQueryTest.php @@ -17,7 +17,7 @@ use Domain\Services\PickupSchedulingService; use Illuminate\Support\Carbon; use Infrastructure\Adapters\Repositories\EloquentPickupExceptionRepository; use Infrastructure\Adapters\Repositories\EloquentShopRepository; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; afterEach(function (): void { CarbonImmutable::setTestNow(); @@ -31,7 +31,7 @@ describe('GetAvailableTimeslotsQuery', function (): void { new PickupSchedulingService(new EloquentPickupExceptionRepository()), new EloquentShopRepository(), ); - $input = new GetAvailableTimeslotsQueryInput(new ShopId(Uuid::uuid7())); + $input = new GetAvailableTimeslotsQueryInput(new ShopId(UuidHelper::v7())); // WHEN $result = $query($input); @@ -57,7 +57,7 @@ describe('GetAvailableTimeslotsQuery', function (): void { new PickupSchedulingService(new EloquentPickupExceptionRepository()), new EloquentShopRepository(), ); - $input = new GetAvailableTimeslotsQueryInput(new ShopId(Uuid::fromString($shop->id))); + $input = new GetAvailableTimeslotsQueryInput(new ShopId(UuidHelper::fromString($shop->id))); // WHEN $result = $query($input); @@ -100,7 +100,7 @@ describe('GetAvailableTimeslotsQuery', function (): void { new PickupSchedulingService(new EloquentPickupExceptionRepository()), new EloquentShopRepository(), ); - $input = new GetAvailableTimeslotsQueryInput(new ShopId(Uuid::fromString($shop->id))); + $input = new GetAvailableTimeslotsQueryInput(new ShopId(UuidHelper::fromString($shop->id))); // WHEN $result = $query($input); diff --git a/tests/Integration/WithApp/App/Dto/OrderLineDtoTest.php b/tests/Integration/WithApp/App/Dto/OrderLineDtoTest.php index 1f0107c3..6331d804 100644 --- a/tests/Integration/WithApp/App/Dto/OrderLineDtoTest.php +++ b/tests/Integration/WithApp/App/Dto/OrderLineDtoTest.php @@ -27,7 +27,7 @@ use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Illuminate\Support\Facades\Date; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; beforeEach(function (): void { $now = CarbonImmutable::parse('2026-06-15 10:00:00', 'Europe/Paris'); @@ -47,9 +47,9 @@ describe('OrderLineDto Integration', function (): void { // GIVEN $shop = Shop::factory()->create(); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), + 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => Money::EUR(4154), 'employee' => new OrderEmployee( @@ -66,7 +66,7 @@ describe('OrderLineDto Integration', function (): void { $orderLineProduct = new OrderLineProduct( incoId: new IncoId(999), - originalId: new ProductId(Uuid::uuid7()), + originalId: new ProductId(UuidHelper::v7()), name: 'Terrine de Foie Gras de Canard mi-cuit 500g', weight: new ProductWeight(500, false), brand: ProductBrand::loue, diff --git a/tests/Integration/WithApp/App/Models/ProductTest.php b/tests/Integration/WithApp/App/Models/ProductTest.php index 8c051599..f0d34ea2 100644 --- a/tests/Integration/WithApp/App/Models/ProductTest.php +++ b/tests/Integration/WithApp/App/Models/ProductTest.php @@ -14,7 +14,7 @@ use Domain\Enums\Units\InvoicingUnit; use Domain\Enums\Units\OrderUnit; use Illuminate\Support\Facades\Date; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function createOrderableTestProduct( Range $range, @@ -34,7 +34,7 @@ function createOrderableTestProduct( 'orderable_start' => $orderableStart, 'orderable_end' => $orderableEnd, ]); - $product->id = Uuid::uuid7()->toString(); + $product->id = UuidHelper::v7()->toString(); $product->order = random_int(1, 999999); $product->price = Money::EUR(1000); $product->short_description = 'Description courte'; diff --git a/tests/Integration/WithApp/App/Services/CrmServiceTest.php b/tests/Integration/WithApp/App/Services/CrmServiceTest.php index 9a2ae38e..27dc5184 100644 --- a/tests/Integration/WithApp/App/Services/CrmServiceTest.php +++ b/tests/Integration/WithApp/App/Services/CrmServiceTest.php @@ -23,7 +23,7 @@ use LDC\LDCCRM\Models\ClientModel; use LDC\LDCCRM\Models\Customer; use LDC\LDCCRM\Transport\ApiInterface; use LDC\LDCCRM\Utils; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('CrmService', function (): void { @@ -32,7 +32,7 @@ describe('CrmService', function (): void { $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = \Mockery::mock(CacheRepository::class); - $uuidObj = Uuid::uuid4(); + $uuidObj = UuidHelper::v4(); $uuid = $uuidObj->toString(); $libCustomer = new Customer([ @@ -105,7 +105,7 @@ describe('CrmService', function (): void { $cacheKey = 'crm_customer_email_' . hash('sha256', $email); $expectedCustomer = new CrmCustomer( - hashcode: (string) Uuid::uuid4(), + hashcode: (string) UuidHelper::v4(), email: $email, password: 'Secret123!', firstname: 'Jane', @@ -142,7 +142,7 @@ describe('CrmService', function (): void { $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = \Mockery::mock(CacheRepository::class); - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); $cacheKey = "crm_customer_hashcode_{$uuid}"; $cacheRepository->shouldReceive('remember') @@ -171,7 +171,7 @@ describe('CrmService', function (): void { $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = \Mockery::mock(CacheRepository::class); - $uuid = (string) Uuid::uuid4(); + $uuid = (string) UuidHelper::v4(); $customer = new CrmCustomer( hashcode: $uuid, @@ -224,7 +224,7 @@ describe('CrmService', function (): void { $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = new ArrayCacheRepository(new ArrayStore()); - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); $email = 'error@example.com'; $hashKey = "crm_customer_hashcode_{$uuid}"; $emailKey = 'crm_customer_email_' . hash('sha256', $email); @@ -256,7 +256,7 @@ describe('CrmService', function (): void { // GIVEN $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = \Mockery::mock(CacheRepository::class); - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); $expectedHashKey = "crm_customer_hashcode_{$uuid->toString()}"; $cacheRepository->shouldReceive('get')->with($expectedHashKey)->once()->andReturnNull(); @@ -288,7 +288,7 @@ describe('CrmService', function (): void { // GIVEN $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = new ArrayCacheRepository(new ArrayStore()); - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); $apiException = \Mockery::mock(ApiErrorException::class); $apiException->shouldReceive('getApiError')->andReturn(ApiError::modelNotFound); @@ -311,7 +311,7 @@ describe('CrmService', function (): void { // GIVEN $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = new ArrayCacheRepository(new ArrayStore()); - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); $apiInterface = \Mockery::mock(ApiInterface::class); $apiInterface->shouldReceive('call')->once()->andThrow(new CrmException('CRM delete error')); @@ -330,7 +330,7 @@ describe('CrmService', function (): void { /** @var CrmApiV4&\Mockery\MockInterface $crmApi */ $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = new ArrayCacheRepository(new ArrayStore()); - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); $email = new Email('Rollback@Example.com'); $hashKey = "crm_customer_hashcode_{$uuid->toString()}"; $emailKey = 'crm_customer_email_' . hash('sha256', 'rollback@example.com'); @@ -388,7 +388,7 @@ describe('CrmService', function (): void { /** @var CrmApiV4&\Mockery\MockInterface $crmApi */ $crmApi = \Mockery::mock(CrmApiV4::class); $cacheRepository = new ArrayCacheRepository(new ArrayStore()); - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); $hashKey = "crm_customer_hashcode_{$uuid->toString()}"; $emailKey = 'crm_customer_email_' . hash('sha256', 'cached@example.com'); diff --git a/tests/Integration/WithApp/App/Services/MailRegateServiceTest.php b/tests/Integration/WithApp/App/Services/MailRegateServiceTest.php index 047cbb50..59dda112 100644 --- a/tests/Integration/WithApp/App/Services/MailRegateServiceTest.php +++ b/tests/Integration/WithApp/App/Services/MailRegateServiceTest.php @@ -19,7 +19,7 @@ use Illuminate\Mail\PendingMail; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Mail; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('MailRegateService', function (): void { it('generates expected CSV rows and sends RegateOrderMail to configured regate address', function (): void { @@ -27,7 +27,7 @@ describe('MailRegateService', function (): void { Mail::fake(); Config::set('mail.to.regate', 'regate@example.com'); - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); $reference = new OrderReference($uuid); $orderReferenceValue = (string) $reference; $employeeMatricule = new Matricule('1234567'); @@ -104,7 +104,7 @@ describe('MailRegateService', function (): void { // GIVEN Config::set('mail.to.regate', 'regate@example.com'); - $reference = new OrderReference(Uuid::uuid7()); + $reference = new OrderReference(UuidHelper::v7()); $employeeMatricule = new Matricule('1234567'); $pickupDay = CarbonImmutable::parse('2025-01-01'); diff --git a/tests/Integration/WithApp/App/Services/OrderOwnershipServiceTest.php b/tests/Integration/WithApp/App/Services/OrderOwnershipServiceTest.php index 0592e1f2..add14fea 100644 --- a/tests/Integration/WithApp/App/Services/OrderOwnershipServiceTest.php +++ b/tests/Integration/WithApp/App/Services/OrderOwnershipServiceTest.php @@ -23,7 +23,7 @@ use Domain\Models\ValueObjects\ShopperSiteCode; use Illuminate\Support\Facades\Date; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; covers(OrderOwnershipService::class); @@ -44,8 +44,8 @@ describe('OrderOwnershipService', function () { it('returns true if order is owned by customer', function () { // GIVEN $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('owner@example.com'), ]); @@ -64,8 +64,8 @@ describe('OrderOwnershipService', function () { ]); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(Uuid::uuid7()), + 'id' => UuidHelper::v7()->toString(), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -91,8 +91,8 @@ describe('OrderOwnershipService', function () { it('returns false if order is not owned by customer', function () { // GIVEN $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('notowner@example.com'), ]); @@ -111,8 +111,8 @@ describe('OrderOwnershipService', function () { ]); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(Uuid::uuid7()), + 'id' => UuidHelper::v7()->toString(), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee( @@ -138,14 +138,14 @@ describe('OrderOwnershipService', function () { it('returns false if customer has no employee', function () { // GIVEN $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('noemp@example.com'), ]); $order = Order::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'reference' => new OrderReference(Uuid::uuid7()), + 'id' => UuidHelper::v7()->toString(), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), 'employee' => new OrderEmployee( diff --git a/tests/Integration/WithApp/App/Services/StatsServiceTest.php b/tests/Integration/WithApp/App/Services/StatsServiceTest.php index 08bf3ab5..e9758c92 100644 --- a/tests/Integration/WithApp/App/Services/StatsServiceTest.php +++ b/tests/Integration/WithApp/App/Services/StatsServiceTest.php @@ -34,7 +34,7 @@ use Domain\Models\ValueObjects\ShopperSiteCode; use Illuminate\Support\Facades\Date; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; covers(StatsService::class); @@ -80,8 +80,8 @@ describe('StatsService', function (): void { int $totalCents = 1000, ): Order { return Order::query()->forceCreate([ - 'id' => Uuid::uuid7($createdAt)->toString(), - 'reference' => new OrderReference(Uuid::uuid7()), + 'id' => UuidHelper::v7($createdAt)->toString(), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => $status->value, 'total' => new Money($totalCents, new Currency('EUR')), 'pickup_day' => $pickupDay, @@ -103,8 +103,8 @@ describe('StatsService', function (): void { expect($service->getMembershipPercentage())->toBe(0.0); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('member@example.com'), ]); $createEmployee(101, '1000101', $customer); @@ -126,8 +126,8 @@ describe('StatsService', function (): void { $inRange = $now->subDays(3); $outRange = $now->subDays(20); $customer1 = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('range1@example.com'), ]); $createEmployee(201, '1000201', $customer1, $inRange); @@ -152,8 +152,8 @@ describe('StatsService', function (): void { $service = new StatsService(new Currency('EUR')); $now = CarbonImmutable::now(); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('stats@example.com'), ]); $createEmployee(301, '1000301', $customer, $now->subDays(3)); @@ -175,7 +175,7 @@ describe('StatsService', function (): void { $productVo = new OrderLineProduct( incoId: new IncoId(1), - originalId: new ProductId(Uuid::uuid7()), + originalId: new ProductId(UuidHelper::v7()), name: 'Poulet', weight: new ProductWeight(1000, false), brand: ProductBrand::loue, @@ -225,8 +225,8 @@ describe('StatsService', function (): void { $service = new StatsService(new Currency('EUR')); $now = CarbonImmutable::now(); $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('attempts-stats@example.com'), ]); diff --git a/tests/Integration/WithApp/Infra/Adapters/Directories/EloquentShopDirectoryTest.php b/tests/Integration/WithApp/Infra/Adapters/Directories/EloquentShopDirectoryTest.php index 33899d21..c0032a65 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Directories/EloquentShopDirectoryTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Directories/EloquentShopDirectoryTest.php @@ -7,61 +7,63 @@ namespace Tests\Integration\WithApp\Infra\Adapters\Directories; use App\Models\Shop; use Domain\Models\ValueObjects\Entities\ShopId; use Infrastructure\Adapters\Directories\EloquentShopDirectory; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; -it('retrieves all available shops', function () { - // GIVEN - Shop::query()->forceCreate([ - 'name' => 'Shop 1', - 'address' => 'Addr 1', - 'postcode' => '75000', - 'city' => 'Paris', - 'default' => false, - ]); - Shop::query()->forceCreate([ - 'name' => 'Shop 2', - 'address' => 'Addr 2', - 'postcode' => '75001', - 'city' => 'Paris', - 'default' => false, - ]); - $directory = new EloquentShopDirectory(); +describe('EloquentShopDirectory', function (): void { + it('retrieves all available shops', function () { + // GIVEN + Shop::query()->forceCreate([ + 'name' => 'Shop 1', + 'address' => 'Addr 1', + 'postcode' => '75000', + 'city' => 'Paris', + 'default' => false, + ]); + Shop::query()->forceCreate([ + 'name' => 'Shop 2', + 'address' => 'Addr 2', + 'postcode' => '75001', + 'city' => 'Paris', + 'default' => false, + ]); + $directory = new EloquentShopDirectory(); - // WHEN - $shops = $directory->getAll(); + // WHEN + $shops = $directory->getAll(); - // THEN - expect($shops)->toHaveCount(2); -}); - -it('finds a shop by its identifier', function () { - // GIVEN - $model = Shop::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'name' => 'Shop X', - 'address' => 'Addr X', - 'postcode' => '75000', - 'city' => 'Paris', - 'default' => false, - ]); - $directory = new EloquentShopDirectory(); - - // WHEN - $shop = $directory->find(new ShopId(Uuid::fromString($model->id))); - - // THEN - expect($shop)->not->toBeNull() - ->and($shop?->id->value->toString())->toBe($model->id) - ->and($shop?->name)->toBe($model->name); -}); - -it('returns null if shop by id is not found', function () { - // GIVEN - $directory = new EloquentShopDirectory(); - - // WHEN - $shop = $directory->find(new ShopId(Uuid::uuid7())); - - // THEN - expect($shop)->toBeNull(); + // THEN + expect($shops)->toHaveCount(2); + }); + + it('finds a shop by its identifier', function () { + // GIVEN + $model = Shop::query()->forceCreate([ + 'id' => UuidHelper::v7()->toString(), + 'name' => 'Shop X', + 'address' => 'Addr X', + 'postcode' => '75000', + 'city' => 'Paris', + 'default' => false, + ]); + $directory = new EloquentShopDirectory(); + + // WHEN + $shop = $directory->find(new ShopId(UuidHelper::fromString($model->id))); + + // THEN + expect($shop)->not->toBeNull() + ->and($shop?->id->value->toString())->toBe($model->id) + ->and($shop?->name)->toBe($model->name); + }); + + it('returns null if shop by id is not found', function () { + // GIVEN + $directory = new EloquentShopDirectory(); + + // WHEN + $shop = $directory->find(new ShopId(UuidHelper::v7())); + + // THEN + expect($shop)->toBeNull(); + }); }); diff --git a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentOrderRepositoryTest.php b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentOrderRepositoryTest.php index 238fed0f..aa3d4154 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentOrderRepositoryTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentOrderRepositoryTest.php @@ -10,144 +10,146 @@ use Domain\Models\Entities\Order as DomainOrder; use Domain\Models\ValueObjects\Entities\OrderId; use Illuminate\Support\Facades\DB; use Infrastructure\Adapters\Repositories\EloquentOrderRepository; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Webmozart\Assert\Assert; -it('returns null when finding a non-existent order by id', function () { - // GIVEN - $repo = new EloquentOrderRepository(); - $orderId = new OrderId(Uuid::fromString('018e4567-e89b-72d3-a456-426614174001')); +describe('EloquentOrderRepository', function (): void { + it('returns null when finding a non-existent order by id', function () { + // GIVEN + $repo = new EloquentOrderRepository(); + $orderId = new OrderId(UuidHelper::fromString('018e4567-e89b-72d3-a456-426614174001')); - // WHEN - $result = $repo->find($orderId); + // WHEN + $result = $repo->find($orderId); - // THEN - expect($result)->toBeNull(); -}); - -it('updates an existing order in the repository', function () { - // GIVEN - $shopId = Uuid::uuid7()->toString(); - DB::table('shops')->insertOrIgnore(['id' => $shopId, 'name' => 'Shop 1', 'postcode' => '75000', 'city' => 'Paris', 'address' => 'Addr']); - - DB::table('orders')->insert([ - 'id' => '018e4567-e89b-72d3-a456-426614174002', - 'shop_id' => $shopId, - 'reference' => Uuid::uuid7()->toString(), - 'employee' => json_encode([ - 'matricule' => '1234567', - 'firstname' => 'Jean', - 'lastname' => 'Dupont', - 'facility' => 'FAC01', - 'site' => 'HQ', - 'service' => '101', - ]), - 'delivery_address' => '{}', - 'pickup_day' => '2023-01-05', - 'status' => OrderStatus::WAITING->value, - 'total' => 1000, - ]); - - $repo = new EloquentOrderRepository(); - - $domainOrder = $repo->find(new OrderId(Uuid::fromString('018e4567-e89b-72d3-a456-426614174002'))); - Assert::isInstanceOf($domainOrder, DomainOrder::class); - $domainOrder->status = OrderStatus::VALIDATED; - - // WHEN - $repo->persist($domainOrder); - - // THEN - /** @var object{status: int}|null $updatedOrder */ - $updatedOrder = DB::table('orders')->where('id', '018e4567-e89b-72d3-a456-426614174002')->first(); - expect($updatedOrder?->status)->toBe(OrderStatus::VALIDATED->value); -}); - -it('finds an order for update inside a transaction', function (): void { - // GIVEN - $shopId = Uuid::uuid7()->toString(); - $orderId = Uuid::uuid7()->toString(); - DB::table('shops')->insertOrIgnore(['id' => $shopId, 'name' => 'Shop Lock', 'postcode' => '75000', 'city' => 'Paris', 'address' => 'Addr']); - DB::table('orders')->insert([ - 'id' => $orderId, - 'shop_id' => $shopId, - 'reference' => Uuid::uuid7()->toString(), - 'employee' => json_encode([ - 'matricule' => '1234567', - 'firstname' => 'Jean', - 'lastname' => 'Dupont', - 'facility' => 'FAC01', - 'site' => 'HQ', - 'service' => '101', - ]), - 'delivery_address' => '{}', - 'pickup_day' => '2026-11-20', - 'status' => OrderStatus::PENDING->value, - 'total' => 1000, - ]); - - $repo = new EloquentOrderRepository(); - - // WHEN - $found = DB::transaction(static fn () => $repo->findForUpdate(new OrderId(Uuid::fromString($orderId)))); - - // THEN - expect($found)->toBeInstanceOf(DomainOrder::class) - ->and($found?->status)->toBe(OrderStatus::PENDING); -}); - -it('returns only stale PENDING order ids older than cutoff', function (): void { - // GIVEN - $shopId = Uuid::uuid7()->toString(); - $staleId = Uuid::uuid7()->toString(); - $freshId = Uuid::uuid7()->toString(); - $staleWaiting = Uuid::uuid7()->toString(); - $now = CarbonImmutable::parse('2026-11-16 12:00:00', 'UTC'); - - DB::table('shops')->insertOrIgnore(['id' => $shopId, 'name' => 'Shop Stale', 'postcode' => '75000', 'city' => 'Paris', 'address' => 'Addr']); - - $baseRow = [ - 'shop_id' => $shopId, - 'employee' => json_encode([ - 'matricule' => '1234567', - 'firstname' => 'Jean', - 'lastname' => 'Dupont', - 'facility' => 'FAC01', - 'site' => 'HQ', - 'service' => '101', - ]), - 'delivery_address' => '{}', - 'pickup_day' => '2026-11-20', - 'total' => 1000, - ]; - - DB::table('orders')->insert([ - array_merge($baseRow, [ - 'id' => $staleId, - 'reference' => Uuid::uuid7()->toString(), - 'status' => OrderStatus::PENDING->value, - 'updated_at' => $now->subMinutes(15)->toDateTimeString(), - ]), - array_merge($baseRow, [ - 'id' => $freshId, - 'reference' => Uuid::uuid7()->toString(), - 'status' => OrderStatus::PENDING->value, - 'updated_at' => $now->subMinutes(5)->toDateTimeString(), - ]), - array_merge($baseRow, [ - 'id' => $staleWaiting, - 'reference' => Uuid::uuid7()->toString(), - 'status' => OrderStatus::WAITING->value, - 'updated_at' => $now->subMinutes(30)->toDateTimeString(), - ]), - ]); - - $repo = new EloquentOrderRepository(); - - // WHEN - $staleIds = $repo->findStalePendingOrderIds($now->subMinutes(10)); - - // THEN - expect($staleIds)->toHaveCount(1) - ->and($staleIds[0]->value->toString())->toBe($staleId); + // THEN + expect($result)->toBeNull(); + }); + + it('updates an existing order in the repository', function () { + // GIVEN + $shopId = UuidHelper::v7()->toString(); + DB::table('shops')->insertOrIgnore(['id' => $shopId, 'name' => 'Shop 1', 'postcode' => '75000', 'city' => 'Paris', 'address' => 'Addr']); + + DB::table('orders')->insert([ + 'id' => '018e4567-e89b-72d3-a456-426614174002', + 'shop_id' => $shopId, + 'reference' => UuidHelper::v7()->toString(), + 'employee' => json_encode([ + 'matricule' => '1234567', + 'firstname' => 'Jean', + 'lastname' => 'Dupont', + 'facility' => 'FAC01', + 'site' => 'HQ', + 'service' => '101', + ]), + 'delivery_address' => '{}', + 'pickup_day' => '2023-01-05', + 'status' => OrderStatus::WAITING->value, + 'total' => 1000, + ]); + + $repo = new EloquentOrderRepository(); + + $domainOrder = $repo->find(new OrderId(UuidHelper::fromString('018e4567-e89b-72d3-a456-426614174002'))); + Assert::isInstanceOf($domainOrder, DomainOrder::class); + $domainOrder->status = OrderStatus::VALIDATED; + + // WHEN + $repo->persist($domainOrder); + + // THEN + /** @var object{status: int}|null $updatedOrder */ + $updatedOrder = DB::table('orders')->where('id', '018e4567-e89b-72d3-a456-426614174002')->first(); + expect($updatedOrder?->status)->toBe(OrderStatus::VALIDATED->value); + }); + + it('finds an order for update inside a transaction', function (): void { + // GIVEN + $shopId = UuidHelper::v7()->toString(); + $orderId = UuidHelper::v7()->toString(); + DB::table('shops')->insertOrIgnore(['id' => $shopId, 'name' => 'Shop Lock', 'postcode' => '75000', 'city' => 'Paris', 'address' => 'Addr']); + DB::table('orders')->insert([ + 'id' => $orderId, + 'shop_id' => $shopId, + 'reference' => UuidHelper::v7()->toString(), + 'employee' => json_encode([ + 'matricule' => '1234567', + 'firstname' => 'Jean', + 'lastname' => 'Dupont', + 'facility' => 'FAC01', + 'site' => 'HQ', + 'service' => '101', + ]), + 'delivery_address' => '{}', + 'pickup_day' => '2026-11-20', + 'status' => OrderStatus::PENDING->value, + 'total' => 1000, + ]); + + $repo = new EloquentOrderRepository(); + + // WHEN + $found = DB::transaction(static fn () => $repo->findForUpdate(new OrderId(UuidHelper::fromString($orderId)))); + + // THEN + expect($found)->toBeInstanceOf(DomainOrder::class) + ->and($found?->status)->toBe(OrderStatus::PENDING); + }); + + it('returns only stale PENDING order ids older than cutoff', function (): void { + // GIVEN + $shopId = UuidHelper::v7()->toString(); + $staleId = UuidHelper::v7()->toString(); + $freshId = UuidHelper::v7()->toString(); + $staleWaiting = UuidHelper::v7()->toString(); + $now = CarbonImmutable::parse('2026-11-16 12:00:00', 'UTC'); + + DB::table('shops')->insertOrIgnore(['id' => $shopId, 'name' => 'Shop Stale', 'postcode' => '75000', 'city' => 'Paris', 'address' => 'Addr']); + + $baseRow = [ + 'shop_id' => $shopId, + 'employee' => json_encode([ + 'matricule' => '1234567', + 'firstname' => 'Jean', + 'lastname' => 'Dupont', + 'facility' => 'FAC01', + 'site' => 'HQ', + 'service' => '101', + ]), + 'delivery_address' => '{}', + 'pickup_day' => '2026-11-20', + 'total' => 1000, + ]; + + DB::table('orders')->insert([ + array_merge($baseRow, [ + 'id' => $staleId, + 'reference' => UuidHelper::v7()->toString(), + 'status' => OrderStatus::PENDING->value, + 'updated_at' => $now->subMinutes(15)->toDateTimeString(), + ]), + array_merge($baseRow, [ + 'id' => $freshId, + 'reference' => UuidHelper::v7()->toString(), + 'status' => OrderStatus::PENDING->value, + 'updated_at' => $now->subMinutes(5)->toDateTimeString(), + ]), + array_merge($baseRow, [ + 'id' => $staleWaiting, + 'reference' => UuidHelper::v7()->toString(), + 'status' => OrderStatus::WAITING->value, + 'updated_at' => $now->subMinutes(30)->toDateTimeString(), + ]), + ]); + + $repo = new EloquentOrderRepository(); + + // WHEN + $staleIds = $repo->findStalePendingOrderIds($now->subMinutes(10)); + + // THEN + expect($staleIds)->toHaveCount(1) + ->and($staleIds[0]->value->toString())->toBe($staleId); + }); }); diff --git a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentPickupExceptionRepositoryTest.php b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentPickupExceptionRepositoryTest.php index efaa9bc4..13a0d326 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentPickupExceptionRepositoryTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentPickupExceptionRepositoryTest.php @@ -11,110 +11,112 @@ use Domain\Enums\RepeatFrequency; use Domain\Models\ValueObjects\Entities\ShopId; use Illuminate\Support\Facades\DB; use Infrastructure\Adapters\Repositories\EloquentPickupExceptionRepository; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; -it('retrieves exceptions within a period for a shop', function () { - // GIVEN - $shopUuid = Uuid::uuid7(); - $shop = Shop::query()->forceCreate([ - 'id' => $shopUuid->toString(), - 'name' => 'Shop 1', - 'postcode' => '75000', - 'city' => 'Paris', - 'address' => 'Addr', - ]); +describe('EloquentPickupExceptionRepository', function (): void { + it('retrieves exceptions within a period for a shop', function () { + // GIVEN + $shopUuid = UuidHelper::v7(); + $shop = Shop::query()->forceCreate([ + 'id' => $shopUuid->toString(), + 'name' => 'Shop 1', + 'postcode' => '75000', + 'city' => 'Paris', + 'address' => 'Addr', + ]); - $exUuid = Uuid::uuid7(); - $ex1 = PickupException::query()->forceCreate([ - 'id' => $exUuid->toString(), - 'date' => '2023-01-10', - 'label' => 'Fermé', - 'repeatable' => false, - 'repeat_frequency' => RepeatFrequency::WEEKLY->value, - 'auto_updated' => false, - ]); + $exUuid = UuidHelper::v7(); + $ex1 = PickupException::query()->forceCreate([ + 'id' => $exUuid->toString(), + 'date' => '2023-01-10', + 'label' => 'Fermé', + 'repeatable' => false, + 'repeat_frequency' => RepeatFrequency::WEEKLY->value, + 'auto_updated' => false, + ]); - DB::table('shop_pickup_exception')->insert([ - 'shop_id' => $shop->id, - 'pickup_exception_id' => $ex1->id, - 'replacement_date' => '2023-01-11', - 'order_deadline_at' => '2023-01-09 10:00:00', - ]); + DB::table('shop_pickup_exception')->insert([ + 'shop_id' => $shop->id, + 'pickup_exception_id' => $ex1->id, + 'replacement_date' => '2023-01-11', + 'order_deadline_at' => '2023-01-09 10:00:00', + ]); - $shopId = new ShopId($shopUuid); - $period = CarbonPeriod::create('2023-01-01', '2023-01-31'); + $shopId = new ShopId($shopUuid); + $period = CarbonPeriod::create('2023-01-01', '2023-01-31'); - $repo = new EloquentPickupExceptionRepository(); + $repo = new EloquentPickupExceptionRepository(); - // WHEN - $result = $repo->getExceptionsForShop($shopId, $period); + // WHEN + $result = $repo->getExceptionsForShop($shopId, $period); - // THEN - expect($result)->toHaveCount(1) - ->and($result[0]->exception->id->value->toString())->toBe($exUuid->toString()) - ->and($result[0]->replacementDate?->format('Y-m-d'))->toBe('2023-01-11') - ->and($result[0]->orderDeadlineAt?->format('Y-m-d H:i:s'))->toBe('2023-01-09 10:00:00'); -}); - -it('retrieves all exceptions', function () { - // GIVEN - $exUuid = Uuid::uuid7(); - PickupException::query()->forceCreate([ - 'id' => $exUuid->toString(), - 'date' => '2023-01-10', - 'label' => 'Fermé', - 'repeatable' => false, - 'repeat_frequency' => RepeatFrequency::WEEKLY->value, - 'auto_updated' => false, - ]); - - $repo = new EloquentPickupExceptionRepository(); - - // WHEN - $result = $repo->getAllExceptions(); - - // THEN - expect($result)->toHaveCount(1) - ->and($result[0]->id->value->toString())->toBe($exUuid->toString()); -}); - -it('retrieves exceptions associated with a shop', function () { - // GIVEN - $shopUuid = Uuid::uuid7(); - $shop = Shop::query()->forceCreate([ - 'id' => $shopUuid->toString(), - 'name' => 'Shop 1', - 'postcode' => '75000', - 'city' => 'Paris', - 'address' => 'Addr', - ]); - - $exUuid = Uuid::uuid7(); - $ex1 = PickupException::query()->forceCreate([ - 'id' => $exUuid->toString(), - 'date' => '2023-01-10', - 'label' => 'Fermé', - 'repeatable' => false, - 'repeat_frequency' => RepeatFrequency::WEEKLY->value, - 'auto_updated' => false, - ]); - - DB::table('shop_pickup_exception')->insert([ - 'shop_id' => $shop->id, - 'pickup_exception_id' => $ex1->id, - 'replacement_date' => '2023-01-11', - 'order_deadline_at' => '2023-01-09 10:00:00', - ]); - - $shopId = new ShopId($shopUuid); - - $repo = new EloquentPickupExceptionRepository(); - - // WHEN - $result = $repo->getExceptionsAssociatedWithShop($shopId); - - // THEN - expect($result)->toHaveCount(1) - ->and($result[0]->exception->id->value->toString())->toBe($exUuid->toString()) - ->and($result[0]->replacementDate?->format('Y-m-d'))->toBe('2023-01-11'); + // THEN + expect($result)->toHaveCount(1) + ->and($result[0]->exception->id->value->toString())->toBe($exUuid->toString()) + ->and($result[0]->replacementDate?->format('Y-m-d'))->toBe('2023-01-11') + ->and($result[0]->orderDeadlineAt?->format('Y-m-d H:i:s'))->toBe('2023-01-09 10:00:00'); + }); + + it('retrieves all exceptions', function () { + // GIVEN + $exUuid = UuidHelper::v7(); + PickupException::query()->forceCreate([ + 'id' => $exUuid->toString(), + 'date' => '2023-01-10', + 'label' => 'Fermé', + 'repeatable' => false, + 'repeat_frequency' => RepeatFrequency::WEEKLY->value, + 'auto_updated' => false, + ]); + + $repo = new EloquentPickupExceptionRepository(); + + // WHEN + $result = $repo->getAllExceptions(); + + // THEN + expect($result)->toHaveCount(1) + ->and($result[0]->id->value->toString())->toBe($exUuid->toString()); + }); + + it('retrieves exceptions associated with a shop', function () { + // GIVEN + $shopUuid = UuidHelper::v7(); + $shop = Shop::query()->forceCreate([ + 'id' => $shopUuid->toString(), + 'name' => 'Shop 1', + 'postcode' => '75000', + 'city' => 'Paris', + 'address' => 'Addr', + ]); + + $exUuid = UuidHelper::v7(); + $ex1 = PickupException::query()->forceCreate([ + 'id' => $exUuid->toString(), + 'date' => '2023-01-10', + 'label' => 'Fermé', + 'repeatable' => false, + 'repeat_frequency' => RepeatFrequency::WEEKLY->value, + 'auto_updated' => false, + ]); + + DB::table('shop_pickup_exception')->insert([ + 'shop_id' => $shop->id, + 'pickup_exception_id' => $ex1->id, + 'replacement_date' => '2023-01-11', + 'order_deadline_at' => '2023-01-09 10:00:00', + ]); + + $shopId = new ShopId($shopUuid); + + $repo = new EloquentPickupExceptionRepository(); + + // WHEN + $result = $repo->getExceptionsAssociatedWithShop($shopId); + + // THEN + expect($result)->toHaveCount(1) + ->and($result[0]->exception->id->value->toString())->toBe($exUuid->toString()) + ->and($result[0]->replacementDate?->format('Y-m-d'))->toBe('2023-01-11'); + }); }); diff --git a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentProductRepositoryTest.php b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentProductRepositoryTest.php index 80836375..def8aca2 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentProductRepositoryTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentProductRepositoryTest.php @@ -14,7 +14,7 @@ use Illuminate\Support\Facades\DB; use Infrastructure\Adapters\Repositories\EloquentProductRepository; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function createRepoTestProductRange(): int { @@ -28,234 +28,236 @@ function createRepoTestProductRange(): int return $range->id; } -it('retrieves a basket product', function () { - // GIVEN - $uuid = Uuid::uuid7()->toString(); - $currency = new Currency('EUR'); - $rangeId = createRepoTestProductRange(); +describe('EloquentProductRepository', function (): void { + it('retrieves a basket product', function () { + // GIVEN + $uuid = UuidHelper::v7()->toString(); + $currency = new Currency('EUR'); + $rangeId = createRepoTestProductRange(); - Product::query()->forceCreate([ - 'id' => $uuid, - 'name' => 'Product Name', - 'tax_rate' => 1, - 'weight' => 1000, - 'brand' => 'none', - 'order_unit' => OrderUnit::PCE->value, - 'invoicing_unit' => 'PCE', - 'sell_unit' => 'PCE', - 'range_id' => $rangeId, - 'slug' => 'product-name', - 'picture' => 'pic.jpg', - 'picture_alt' => '', - 'picture_title' => '', - 'picture_large_alt' => '', - 'picture_large_title' => '', - 'description' => 'Desc', - 'weight_variable' => false, - 'status' => 1, - 'price' => new Money(100, $currency), - ]); - DB::table('product_incos')->insert(['product_id' => $uuid, 'no_art' => 12345]); + Product::query()->forceCreate([ + 'id' => $uuid, + 'name' => 'Product Name', + 'tax_rate' => 1, + 'weight' => 1000, + 'brand' => 'none', + 'order_unit' => OrderUnit::PCE->value, + 'invoicing_unit' => 'PCE', + 'sell_unit' => 'PCE', + 'range_id' => $rangeId, + 'slug' => 'product-name', + 'picture' => 'pic.jpg', + 'picture_alt' => '', + 'picture_title' => '', + 'picture_large_alt' => '', + 'picture_large_title' => '', + 'description' => 'Desc', + 'weight_variable' => false, + 'status' => 1, + 'price' => new Money(100, $currency), + ]); + DB::table('product_incos')->insert(['product_id' => $uuid, 'no_art' => 12345]); - $id = new ProductId(Uuid::fromString($uuid)); + $id = new ProductId(UuidHelper::fromString($uuid)); - $repo = new EloquentProductRepository(); + $repo = new EloquentProductRepository(); - // WHEN - $result = $repo->getBasketProduct($id, 2); + // WHEN + $result = $repo->getBasketProduct($id, 2); - // THEN - expect($result->name)->toBe('Product Name') - ->and($result->qty)->toBe(2); -}); - -it('throws UnorderableProductException when retrieving a basket product without inco', function (): void { - // GIVEN - $uuid = Uuid::uuid7()->toString(); - $currency = new Currency('EUR'); - $rangeId = createRepoTestProductRange(); - - Product::query()->forceCreate([ - 'id' => $uuid, - 'name' => 'Product Without Inco', - 'tax_rate' => 1, - 'weight' => 1000, - 'brand' => 'none', - 'order_unit' => OrderUnit::PCE->value, - 'invoicing_unit' => 'PCE', - 'sell_unit' => 'PCE', - 'range_id' => $rangeId, - 'slug' => 'product-without-inco', - 'picture' => 'pic.jpg', - 'picture_alt' => '', - 'picture_title' => '', - 'picture_large_alt' => '', - 'picture_large_title' => '', - 'description' => 'Desc', - 'weight_variable' => false, - 'status' => 1, - 'price' => new Money(100, $currency), - ]); - - $id = new ProductId(Uuid::fromString($uuid)); - $repo = new EloquentProductRepository(); - - // WHEN - $action = fn () => $repo->getBasketProduct($id, 1); - - // THEN - expect($action)->toThrow(UnorderableProductException::class); -}); - -it('throws UnorderableProductException when retrieving an unpublished basket product', function (): void { - // GIVEN - $uuid = Uuid::uuid7()->toString(); - $currency = new Currency('EUR'); - $rangeId = createRepoTestProductRange(); - - Product::query()->forceCreate([ - 'id' => $uuid, - 'name' => 'Unpublished Product', - 'tax_rate' => 1, - 'weight' => 1000, - 'brand' => 'none', - 'order_unit' => OrderUnit::PCE->value, - 'invoicing_unit' => 'PCE', - 'sell_unit' => 'PCE', - 'range_id' => $rangeId, - 'slug' => 'unpublished-product', - 'picture' => 'pic.jpg', - 'picture_alt' => '', - 'picture_title' => '', - 'picture_large_alt' => '', - 'picture_large_title' => '', - 'description' => 'Desc', - 'weight_variable' => false, - 'status' => 0, - 'price' => new Money(100, $currency), - ]); - DB::table('product_incos')->insert(['product_id' => $uuid, 'no_art' => 12345]); - - $id = new ProductId(Uuid::fromString($uuid)); - $repo = new EloquentProductRepository(); - - // WHEN - $action = fn () => $repo->getBasketProduct($id, 1); - - // THEN - expect($action)->toThrow(UnorderableProductException::class); -}); - -it('throws UnorderableProductException when retrieving a basket product outside orderable dates', function (): void { - // GIVEN - $expiredUuid = Uuid::uuid7()->toString(); - $futureUuid = Uuid::uuid7()->toString(); - $currency = new Currency('EUR'); - $rangeId = createRepoTestProductRange(); - - Product::query()->forceCreate([ - 'id' => $expiredUuid, - 'name' => 'Expired Product', - 'tax_rate' => 1, - 'weight' => 1000, - 'brand' => 'none', - 'order_unit' => OrderUnit::PCE->value, - 'invoicing_unit' => 'PCE', - 'sell_unit' => 'PCE', - 'range_id' => $rangeId, - 'slug' => 'expired-product', - 'picture' => 'pic.jpg', - 'picture_alt' => '', - 'picture_title' => '', - 'picture_large_alt' => '', - 'picture_large_title' => '', - 'description' => 'Desc', - 'weight_variable' => false, - 'status' => 1, - 'orderable_end' => now()->subDay(), - 'price' => new Money(100, $currency), - ]); - DB::table('product_incos')->insert(['product_id' => $expiredUuid, 'no_art' => 12345]); - - Product::query()->forceCreate([ - 'id' => $futureUuid, - 'name' => 'Future Product', - 'tax_rate' => 1, - 'weight' => 1000, - 'brand' => 'none', - 'order_unit' => OrderUnit::PCE->value, - 'invoicing_unit' => 'PCE', - 'sell_unit' => 'PCE', - 'range_id' => $rangeId, - 'slug' => 'future-product', - 'picture' => 'pic.jpg', - 'picture_alt' => '', - 'picture_title' => '', - 'picture_large_alt' => '', - 'picture_large_title' => '', - 'description' => 'Desc', - 'weight_variable' => false, - 'status' => 1, - 'orderable_start' => now()->addDay(), - 'price' => new Money(100, $currency), - ]); - DB::table('product_incos')->insert(['product_id' => $futureUuid, 'no_art' => 12346]); - - $repo = new EloquentProductRepository(); - - // WHEN - $expiredAction = fn () => $repo->getBasketProduct(new ProductId(Uuid::fromString($expiredUuid)), 1); - $futureAction = fn () => $repo->getBasketProduct(new ProductId(Uuid::fromString($futureUuid)), 1); - - // THEN - expect($expiredAction)->toThrow(UnorderableProductException::class) - ->and($futureAction)->toThrow(UnorderableProductException::class); -}); - -it('finds a product by id', function () { - // GIVEN - $uuid = Uuid::uuid7()->toString(); - $rangeId = createRepoTestProductRange(); - - Product::query()->forceCreate([ - 'id' => $uuid, - 'name' => 'Product Name', - 'tax_rate' => 1, - 'weight' => 1000, - 'brand' => 'none', - 'slug' => 'product-name', - 'invoicing_unit' => 'PCE', - 'sell_unit' => 'PCE', - 'range_id' => $rangeId, - 'picture_alt' => '', - 'picture_title' => '', - 'picture_large_alt' => '', - 'picture_large_title' => '', - 'description' => '', - 'status' => 1, - 'price' => new Money(100, new Currency('EUR')), - ]); - - $id = new ProductId(Uuid::fromString($uuid)); - - $repo = new EloquentProductRepository(); - - // WHEN - $result = $repo->find($id); - - // THEN - expect($result)->toBeInstanceOf(DomainProduct::class); -}); - -it('returns null if product by id is not found', function () { - // GIVEN - $id = new ProductId(Uuid::uuid7()); - - $repo = new EloquentProductRepository(); - - // WHEN - $result = $repo->find($id); - - // THEN - expect($result)->toBeNull(); + // THEN + expect($result->name)->toBe('Product Name') + ->and($result->qty)->toBe(2); + }); + + it('throws UnorderableProductException when retrieving a basket product without inco', function (): void { + // GIVEN + $uuid = UuidHelper::v7()->toString(); + $currency = new Currency('EUR'); + $rangeId = createRepoTestProductRange(); + + Product::query()->forceCreate([ + 'id' => $uuid, + 'name' => 'Product Without Inco', + 'tax_rate' => 1, + 'weight' => 1000, + 'brand' => 'none', + 'order_unit' => OrderUnit::PCE->value, + 'invoicing_unit' => 'PCE', + 'sell_unit' => 'PCE', + 'range_id' => $rangeId, + 'slug' => 'product-without-inco', + 'picture' => 'pic.jpg', + 'picture_alt' => '', + 'picture_title' => '', + 'picture_large_alt' => '', + 'picture_large_title' => '', + 'description' => 'Desc', + 'weight_variable' => false, + 'status' => 1, + 'price' => new Money(100, $currency), + ]); + + $id = new ProductId(UuidHelper::fromString($uuid)); + $repo = new EloquentProductRepository(); + + // WHEN + $action = fn () => $repo->getBasketProduct($id, 1); + + // THEN + expect($action)->toThrow(UnorderableProductException::class); + }); + + it('throws UnorderableProductException when retrieving an unpublished basket product', function (): void { + // GIVEN + $uuid = UuidHelper::v7()->toString(); + $currency = new Currency('EUR'); + $rangeId = createRepoTestProductRange(); + + Product::query()->forceCreate([ + 'id' => $uuid, + 'name' => 'Unpublished Product', + 'tax_rate' => 1, + 'weight' => 1000, + 'brand' => 'none', + 'order_unit' => OrderUnit::PCE->value, + 'invoicing_unit' => 'PCE', + 'sell_unit' => 'PCE', + 'range_id' => $rangeId, + 'slug' => 'unpublished-product', + 'picture' => 'pic.jpg', + 'picture_alt' => '', + 'picture_title' => '', + 'picture_large_alt' => '', + 'picture_large_title' => '', + 'description' => 'Desc', + 'weight_variable' => false, + 'status' => 0, + 'price' => new Money(100, $currency), + ]); + DB::table('product_incos')->insert(['product_id' => $uuid, 'no_art' => 12345]); + + $id = new ProductId(UuidHelper::fromString($uuid)); + $repo = new EloquentProductRepository(); + + // WHEN + $action = fn () => $repo->getBasketProduct($id, 1); + + // THEN + expect($action)->toThrow(UnorderableProductException::class); + }); + + it('throws UnorderableProductException when retrieving a basket product outside orderable dates', function (): void { + // GIVEN + $expiredUuid = UuidHelper::v7()->toString(); + $futureUuid = UuidHelper::v7()->toString(); + $currency = new Currency('EUR'); + $rangeId = createRepoTestProductRange(); + + Product::query()->forceCreate([ + 'id' => $expiredUuid, + 'name' => 'Expired Product', + 'tax_rate' => 1, + 'weight' => 1000, + 'brand' => 'none', + 'order_unit' => OrderUnit::PCE->value, + 'invoicing_unit' => 'PCE', + 'sell_unit' => 'PCE', + 'range_id' => $rangeId, + 'slug' => 'expired-product', + 'picture' => 'pic.jpg', + 'picture_alt' => '', + 'picture_title' => '', + 'picture_large_alt' => '', + 'picture_large_title' => '', + 'description' => 'Desc', + 'weight_variable' => false, + 'status' => 1, + 'orderable_end' => now()->subDay(), + 'price' => new Money(100, $currency), + ]); + DB::table('product_incos')->insert(['product_id' => $expiredUuid, 'no_art' => 12345]); + + Product::query()->forceCreate([ + 'id' => $futureUuid, + 'name' => 'Future Product', + 'tax_rate' => 1, + 'weight' => 1000, + 'brand' => 'none', + 'order_unit' => OrderUnit::PCE->value, + 'invoicing_unit' => 'PCE', + 'sell_unit' => 'PCE', + 'range_id' => $rangeId, + 'slug' => 'future-product', + 'picture' => 'pic.jpg', + 'picture_alt' => '', + 'picture_title' => '', + 'picture_large_alt' => '', + 'picture_large_title' => '', + 'description' => 'Desc', + 'weight_variable' => false, + 'status' => 1, + 'orderable_start' => now()->addDay(), + 'price' => new Money(100, $currency), + ]); + DB::table('product_incos')->insert(['product_id' => $futureUuid, 'no_art' => 12346]); + + $repo = new EloquentProductRepository(); + + // WHEN + $expiredAction = fn () => $repo->getBasketProduct(new ProductId(UuidHelper::fromString($expiredUuid)), 1); + $futureAction = fn () => $repo->getBasketProduct(new ProductId(UuidHelper::fromString($futureUuid)), 1); + + // THEN + expect($expiredAction)->toThrow(UnorderableProductException::class) + ->and($futureAction)->toThrow(UnorderableProductException::class); + }); + + it('finds a product by id', function () { + // GIVEN + $uuid = UuidHelper::v7()->toString(); + $rangeId = createRepoTestProductRange(); + + Product::query()->forceCreate([ + 'id' => $uuid, + 'name' => 'Product Name', + 'tax_rate' => 1, + 'weight' => 1000, + 'brand' => 'none', + 'slug' => 'product-name', + 'invoicing_unit' => 'PCE', + 'sell_unit' => 'PCE', + 'range_id' => $rangeId, + 'picture_alt' => '', + 'picture_title' => '', + 'picture_large_alt' => '', + 'picture_large_title' => '', + 'description' => '', + 'status' => 1, + 'price' => new Money(100, new Currency('EUR')), + ]); + + $id = new ProductId(UuidHelper::fromString($uuid)); + + $repo = new EloquentProductRepository(); + + // WHEN + $result = $repo->find($id); + + // THEN + expect($result)->toBeInstanceOf(DomainProduct::class); + }); + + it('returns null if product by id is not found', function () { + // GIVEN + $id = new ProductId(UuidHelper::v7()); + + $repo = new EloquentProductRepository(); + + // WHEN + $result = $repo->find($id); + + // THEN + expect($result)->toBeNull(); + }); }); diff --git a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentShopRepositoryTest.php b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentShopRepositoryTest.php index d8c6c75a..7cbb58d4 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentShopRepositoryTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentShopRepositoryTest.php @@ -14,182 +14,184 @@ use Domain\Models\ValueObjects\ShopperSiteCode; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\DB; use Infrastructure\Adapters\Repositories\EloquentShopRepository; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; -it('finds exception shop for a matricule', function () { - // GIVEN - $shop = Shop::query()->forceCreate([ - 'name' => 'Shop X', - 'address' => 'Addr X', - 'postcode' => '75000', - 'city' => 'Paris', - 'default' => false, - ]); +describe('EloquentShopRepository', function (): void { + it('finds exception shop for a matricule', function () { + // GIVEN + $shop = Shop::query()->forceCreate([ + 'name' => 'Shop X', + 'address' => 'Addr X', + 'postcode' => '75000', + 'city' => 'Paris', + 'default' => false, + ]); - Employee::query()->forceCreate([ - 'matricule' => new Matricule('1234567'), - 'nom' => 'Doe', - 'prenom' => 'John', - 'etablissement' => 'ETAB', - 'site' => 'SITE', - 'service' => '101', - 'code' => new Code('ABCDEFGH'), - ]); - DB::table('shop_employee_exception')->insert([ - 'matricule' => '1234567', - 'shop_id' => $shop->id, - ]); + Employee::query()->forceCreate([ + 'matricule' => new Matricule('1234567'), + 'nom' => 'Doe', + 'prenom' => 'John', + 'etablissement' => 'ETAB', + 'site' => 'SITE', + 'service' => '101', + 'code' => new Code('ABCDEFGH'), + ]); + DB::table('shop_employee_exception')->insert([ + 'matricule' => '1234567', + 'shop_id' => $shop->id, + ]); - $repo = new EloquentShopRepository(); + $repo = new EloquentShopRepository(); - // WHEN - $result = $repo->findExceptionShopFor(new Matricule('1234567')); + // WHEN + $result = $repo->findExceptionShopFor(new Matricule('1234567')); - // THEN - expect($result)->not->toBeNull() - ->and($result?->id->value->toString())->toBe($shop->id); -}); - -it('returns null if exception shop is not found', function () { - // GIVEN - $repo = new EloquentShopRepository(); - - // WHEN - $result = $repo->findExceptionShopFor(new Matricule('9999999')); - - // THEN - expect($result)->toBeNull(); -}); - -it('finds shop for site and service', function () { - // GIVEN - $shop = Shop::query()->forceCreate([ - 'name' => 'Shop Y', - 'address' => 'Addr Y', - 'postcode' => '75000', - 'city' => 'Paris', - 'default' => false, - ]); - - DB::table('shop_employees')->insert([ - 'site_code' => 'PA', - 'service_code' => '101', - 'shop_id' => $shop->id, - ]); - - $repo = new EloquentShopRepository(); - - // WHEN - $result = $repo->findShopForSiteAndService(new ShopperSiteCode('PA'), new ShopperServiceCode('101')); - - // THEN - expect($result)->not->toBeNull() - ->and($result?->id->value->toString())->toBe($shop->id); -}); - -it('finds shop for site and null service', function () { - // GIVEN - $shop = Shop::query()->forceCreate([ - 'name' => 'Shop Z', - 'address' => 'Addr Z', - 'postcode' => '75000', - 'city' => 'Paris', - 'default' => false, - ]); - - DB::table('shop_employees')->insert([ - 'site_code' => 'LY', - 'service_code' => null, - 'shop_id' => $shop->id, - ]); - - $repo = new EloquentShopRepository(); - - // WHEN - $result = $repo->findShopForSiteAndService(new ShopperSiteCode('LY'), null); - - // THEN - expect($result)->not->toBeNull() - ->and($result?->id->value->toString())->toBe($shop->id); -}); - -it('returns null if shop for site and service is not found', function () { - // GIVEN - $repo = new EloquentShopRepository(); - - // WHEN - $result = $repo->findShopForSiteAndService(new ShopperSiteCode('ZZ'), new ShopperServiceCode('999')); - - // THEN - expect($result)->toBeNull(); -}); - -it('finds shop by id', function () { - // GIVEN - $shop = Shop::query()->forceCreate([ - 'name' => 'Shop 1', - 'address' => 'Addr 1', - 'postcode' => '75000', - 'city' => 'Paris', - 'default' => false, - ]); - - $repo = new EloquentShopRepository(); - - // WHEN - $result = $repo->find(new ShopId(Uuid::fromString($shop->id))); - - // THEN - expect($result)->not->toBeNull() - ->and($result?->id->value->toString())->toBe($shop->id); -}); - -it('returns null if shop by id is not found', function () { - // GIVEN - $repo = new EloquentShopRepository(); - - // WHEN - $result = $repo->find(new ShopId(Uuid::uuid7())); - - // THEN - expect($result)->toBeNull(); -}); - -it('retrieves default shop', function () { - // GIVEN - Shop::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'name' => 'Shop 1', - 'address' => 'Addr 1', - 'postcode' => '75000', - 'city' => 'Paris', - 'default' => false, - ]); - $defaultShop = Shop::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'name' => 'Shop Default', - 'address' => 'Addr Default', - 'postcode' => '75000', - 'city' => 'Paris', - 'default' => true, - ]); - - $repo = new EloquentShopRepository(); - - // WHEN - $result = $repo->getDefaultShop(); - - // THEN - expect($result->id->value->toString())->toBe($defaultShop->id); -}); - -it('throws exception if default shop is not found', function () { - // GIVEN - $repo = new EloquentShopRepository(); - - // WHEN - $action = fn () => $repo->getDefaultShop(); - - // THEN - expect($action)->toThrow(ModelNotFoundException::class); + // THEN + expect($result)->not->toBeNull() + ->and($result?->id->value->toString())->toBe($shop->id); + }); + + it('returns null if exception shop is not found', function () { + // GIVEN + $repo = new EloquentShopRepository(); + + // WHEN + $result = $repo->findExceptionShopFor(new Matricule('9999999')); + + // THEN + expect($result)->toBeNull(); + }); + + it('finds shop for site and service', function () { + // GIVEN + $shop = Shop::query()->forceCreate([ + 'name' => 'Shop Y', + 'address' => 'Addr Y', + 'postcode' => '75000', + 'city' => 'Paris', + 'default' => false, + ]); + + DB::table('shop_employees')->insert([ + 'site_code' => 'PA', + 'service_code' => '101', + 'shop_id' => $shop->id, + ]); + + $repo = new EloquentShopRepository(); + + // WHEN + $result = $repo->findShopForSiteAndService(new ShopperSiteCode('PA'), new ShopperServiceCode('101')); + + // THEN + expect($result)->not->toBeNull() + ->and($result?->id->value->toString())->toBe($shop->id); + }); + + it('finds shop for site and null service', function () { + // GIVEN + $shop = Shop::query()->forceCreate([ + 'name' => 'Shop Z', + 'address' => 'Addr Z', + 'postcode' => '75000', + 'city' => 'Paris', + 'default' => false, + ]); + + DB::table('shop_employees')->insert([ + 'site_code' => 'LY', + 'service_code' => null, + 'shop_id' => $shop->id, + ]); + + $repo = new EloquentShopRepository(); + + // WHEN + $result = $repo->findShopForSiteAndService(new ShopperSiteCode('LY'), null); + + // THEN + expect($result)->not->toBeNull() + ->and($result?->id->value->toString())->toBe($shop->id); + }); + + it('returns null if shop for site and service is not found', function () { + // GIVEN + $repo = new EloquentShopRepository(); + + // WHEN + $result = $repo->findShopForSiteAndService(new ShopperSiteCode('ZZ'), new ShopperServiceCode('999')); + + // THEN + expect($result)->toBeNull(); + }); + + it('finds shop by id', function () { + // GIVEN + $shop = Shop::query()->forceCreate([ + 'name' => 'Shop 1', + 'address' => 'Addr 1', + 'postcode' => '75000', + 'city' => 'Paris', + 'default' => false, + ]); + + $repo = new EloquentShopRepository(); + + // WHEN + $result = $repo->find(new ShopId(UuidHelper::fromString($shop->id))); + + // THEN + expect($result)->not->toBeNull() + ->and($result?->id->value->toString())->toBe($shop->id); + }); + + it('returns null if shop by id is not found', function () { + // GIVEN + $repo = new EloquentShopRepository(); + + // WHEN + $result = $repo->find(new ShopId(UuidHelper::v7())); + + // THEN + expect($result)->toBeNull(); + }); + + it('retrieves default shop', function () { + // GIVEN + Shop::query()->forceCreate([ + 'id' => UuidHelper::v7()->toString(), + 'name' => 'Shop 1', + 'address' => 'Addr 1', + 'postcode' => '75000', + 'city' => 'Paris', + 'default' => false, + ]); + $defaultShop = Shop::query()->forceCreate([ + 'id' => UuidHelper::v7()->toString(), + 'name' => 'Shop Default', + 'address' => 'Addr Default', + 'postcode' => '75000', + 'city' => 'Paris', + 'default' => true, + ]); + + $repo = new EloquentShopRepository(); + + // WHEN + $result = $repo->getDefaultShop(); + + // THEN + expect($result->id->value->toString())->toBe($defaultShop->id); + }); + + it('throws exception if default shop is not found', function () { + // GIVEN + $repo = new EloquentShopRepository(); + + // WHEN + $action = fn () => $repo->getDefaultShop(); + + // THEN + expect($action)->toThrow(ModelNotFoundException::class); + }); }); diff --git a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentShopperRepositoryTest.php b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentShopperRepositoryTest.php index b4fa6011..b98a438c 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentShopperRepositoryTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentShopperRepositoryTest.php @@ -16,164 +16,166 @@ use Domain\Models\ValueObjects\ShopperEstablishmentCode; use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Infrastructure\Adapters\Repositories\EloquentShopperRepository; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; -it('retrieves shopper by id', function () { - // GIVEN - $uuid = Uuid::uuid7()->toString(); +describe('EloquentShopperRepository', function (): void { + it('retrieves shopper by id', function () { + // GIVEN + $uuid = UuidHelper::v7()->toString(); - Customer::query()->forceCreate([ - 'id' => $uuid, - 'email' => new Email('test@example.com'), - 'hashcode' => Uuid::uuid4()->toString(), - ]); + Customer::query()->forceCreate([ + 'id' => $uuid, + 'email' => new Email('test@example.com'), + 'hashcode' => UuidHelper::v4()->toString(), + ]); - Employee::query()->forceCreate([ - 'customer_id' => $uuid, - 'matricule' => new Matricule('1234567'), - 'nom' => 'Doe', - 'prenom' => 'John', - 'etablissement' => 'ETAB', - 'site' => 'SITE', - 'service' => '101', - 'code' => new Code('ABCDEFGH'), - ]); + Employee::query()->forceCreate([ + 'customer_id' => $uuid, + 'matricule' => new Matricule('1234567'), + 'nom' => 'Doe', + 'prenom' => 'John', + 'etablissement' => 'ETAB', + 'site' => 'SITE', + 'service' => '101', + 'code' => new Code('ABCDEFGH'), + ]); - $repo = new EloquentShopperRepository(); + $repo = new EloquentShopperRepository(); - // WHEN - $result = $repo->find(new ShopperId(Uuid::fromString($uuid))); + // WHEN + $result = $repo->find(new ShopperId(UuidHelper::fromString($uuid))); - // THEN - expect($result)->toBeInstanceOf(Shopper::class) - ->and($result?->email->value)->toBe('test@example.com'); -}); - -it('returns null if shopper not found by id', function () { - // GIVEN - $repo = new EloquentShopperRepository(); - - // WHEN - $result = $repo->find(new ShopperId(Uuid::uuid7())); - - // THEN - expect($result)->toBeNull(); -}); - -it('returns null if customer exists but has no employee', function () { - // GIVEN - $uuid = Uuid::uuid7()->toString(); - - Customer::query()->forceCreate([ - 'id' => $uuid, - 'email' => new Email('test@example.com'), - 'hashcode' => Uuid::uuid4()->toString(), - ]); - - $repo = new EloquentShopperRepository(); - - // WHEN - $result = $repo->find(new ShopperId(Uuid::fromString($uuid))); - - // THEN - expect($result)->toBeNull(); -}); - -it('retrieves shopper by id or fails', function () { - // GIVEN - $uuid = Uuid::uuid7()->toString(); - - Customer::query()->forceCreate([ - 'id' => $uuid, - 'email' => new Email('test@example.com'), - 'hashcode' => Uuid::uuid4()->toString(), - ]); - - Employee::query()->forceCreate([ - 'customer_id' => $uuid, - 'matricule' => new Matricule('1234569'), - 'nom' => 'Doe', - 'prenom' => 'John', - 'etablissement' => 'ETAB', - 'site' => 'SITE', - 'service' => '101', - 'code' => new Code('ABCDEFGH'), - ]); - - $repo = new EloquentShopperRepository(); - - // WHEN - $result = $repo->getByIdOrFail(new ShopperId(Uuid::fromString($uuid))); - - // THEN - expect($result->id()->value->toString())->toBe($uuid) - ->and($result->matricule->value)->toBe('1234569'); -}); - -it('throws exception if shopper not found in getByIdOrFail', function () { - // GIVEN - $repo = new EloquentShopperRepository(); - $id = Uuid::uuid7(); - - // WHEN - $action = fn () => $repo->getByIdOrFail(new ShopperId($id)); - - // THEN - expect($action)->toThrow(\DomainException::class, "Shopper with id '{$id->toString()}' not found or is not linked to any employee."); -}); - -it('persists updates to both customer and associated employee', function () { - // GIVEN - $uuid = Uuid::uuid7()->toString(); - $shopperId = new ShopperId(Uuid::fromString($uuid)); - - Customer::query()->forceCreate([ - 'id' => $uuid, - 'email' => new Email('before@example.com'), - 'hashcode' => Uuid::uuid4()->toString(), - ]); - - Employee::query()->forceCreate([ - 'customer_id' => $uuid, - 'matricule' => new Matricule('1234567'), - 'nom' => 'Doe', - 'prenom' => 'John', - 'start_date' => '2026-01-01', - 'end_date' => null, - 'etablissement' => 'ETAB01', - 'site' => 'SITE', - 'service' => '101', - 'code' => new Code('ABCDEFGH'), - ]); - - $repo = new EloquentShopperRepository(); - $updatedShopper = new Shopper( - id: $shopperId, - email: new Email('after@example.com'), - matricule: new Matricule('7654321'), - nom: 'Martin', - prenom: 'Claire', - startDate: CarbonImmutable::parse('2026-02-01'), - endDate: CarbonImmutable::parse('2026-12-31'), - etablissement: new ShopperEstablishmentCode('ETAB02'), - site: new ShopperSiteCode('PA'), - service: new ShopperServiceCode('202'), - ); - - // WHEN - $repo->persist($updatedShopper); - - // THEN - $reloaded = $repo->find($shopperId); - - expect($reloaded)->toBeInstanceOf(Shopper::class) - ->and($reloaded?->email->value)->toBe('after@example.com') - ->and($reloaded?->matricule->value)->toBe('7654321') - ->and($reloaded?->nom)->toBe('Martin') - ->and($reloaded?->prenom)->toBe('Claire') - ->and($reloaded?->startDate->format('Y-m-d'))->toBe('2026-02-01') - ->and($reloaded?->endDate?->format('Y-m-d'))->toBe('2026-12-31') - ->and($reloaded?->etablissement->value)->toBe('ETAB02') - ->and($reloaded?->site->value)->toBe('PA') - ->and($reloaded?->service->value)->toBe('202'); + // THEN + expect($result)->toBeInstanceOf(Shopper::class) + ->and($result?->email->value)->toBe('test@example.com'); + }); + + it('returns null if shopper not found by id', function () { + // GIVEN + $repo = new EloquentShopperRepository(); + + // WHEN + $result = $repo->find(new ShopperId(UuidHelper::v7())); + + // THEN + expect($result)->toBeNull(); + }); + + it('returns null if customer exists but has no employee', function () { + // GIVEN + $uuid = UuidHelper::v7()->toString(); + + Customer::query()->forceCreate([ + 'id' => $uuid, + 'email' => new Email('test@example.com'), + 'hashcode' => UuidHelper::v4()->toString(), + ]); + + $repo = new EloquentShopperRepository(); + + // WHEN + $result = $repo->find(new ShopperId(UuidHelper::fromString($uuid))); + + // THEN + expect($result)->toBeNull(); + }); + + it('retrieves shopper by id or fails', function () { + // GIVEN + $uuid = UuidHelper::v7()->toString(); + + Customer::query()->forceCreate([ + 'id' => $uuid, + 'email' => new Email('test@example.com'), + 'hashcode' => UuidHelper::v4()->toString(), + ]); + + Employee::query()->forceCreate([ + 'customer_id' => $uuid, + 'matricule' => new Matricule('1234569'), + 'nom' => 'Doe', + 'prenom' => 'John', + 'etablissement' => 'ETAB', + 'site' => 'SITE', + 'service' => '101', + 'code' => new Code('ABCDEFGH'), + ]); + + $repo = new EloquentShopperRepository(); + + // WHEN + $result = $repo->getByIdOrFail(new ShopperId(UuidHelper::fromString($uuid))); + + // THEN + expect($result->id()->value->toString())->toBe($uuid) + ->and($result->matricule->value)->toBe('1234569'); + }); + + it('throws exception if shopper not found in getByIdOrFail', function () { + // GIVEN + $repo = new EloquentShopperRepository(); + $id = UuidHelper::v7(); + + // WHEN + $action = fn () => $repo->getByIdOrFail(new ShopperId($id)); + + // THEN + expect($action)->toThrow(\DomainException::class, "Shopper with id '{$id->toString()}' not found or is not linked to any employee."); + }); + + it('persists updates to both customer and associated employee', function () { + // GIVEN + $uuid = UuidHelper::v7()->toString(); + $shopperId = new ShopperId(UuidHelper::fromString($uuid)); + + Customer::query()->forceCreate([ + 'id' => $uuid, + 'email' => new Email('before@example.com'), + 'hashcode' => UuidHelper::v4()->toString(), + ]); + + Employee::query()->forceCreate([ + 'customer_id' => $uuid, + 'matricule' => new Matricule('1234567'), + 'nom' => 'Doe', + 'prenom' => 'John', + 'start_date' => '2026-01-01', + 'end_date' => null, + 'etablissement' => 'ETAB01', + 'site' => 'SITE', + 'service' => '101', + 'code' => new Code('ABCDEFGH'), + ]); + + $repo = new EloquentShopperRepository(); + $updatedShopper = new Shopper( + id: $shopperId, + email: new Email('after@example.com'), + matricule: new Matricule('7654321'), + nom: 'Martin', + prenom: 'Claire', + startDate: CarbonImmutable::parse('2026-02-01'), + endDate: CarbonImmutable::parse('2026-12-31'), + etablissement: new ShopperEstablishmentCode('ETAB02'), + site: new ShopperSiteCode('PA'), + service: new ShopperServiceCode('202'), + ); + + // WHEN + $repo->persist($updatedShopper); + + // THEN + $reloaded = $repo->find($shopperId); + + expect($reloaded)->toBeInstanceOf(Shopper::class) + ->and($reloaded?->email->value)->toBe('after@example.com') + ->and($reloaded?->matricule->value)->toBe('7654321') + ->and($reloaded?->nom)->toBe('Martin') + ->and($reloaded?->prenom)->toBe('Claire') + ->and($reloaded?->startDate->format('Y-m-d'))->toBe('2026-02-01') + ->and($reloaded?->endDate?->format('Y-m-d'))->toBe('2026-12-31') + ->and($reloaded?->etablissement->value)->toBe('ETAB02') + ->and($reloaded?->site->value)->toBe('PA') + ->and($reloaded?->service->value)->toBe('202'); + }); }); diff --git a/tests/Integration/WithApp/Infra/Adapters/Repositories/SessionBasketRepositoryTest.php b/tests/Integration/WithApp/Infra/Adapters/Repositories/SessionBasketRepositoryTest.php index f70bb985..27527893 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Repositories/SessionBasketRepositoryTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Repositories/SessionBasketRepositoryTest.php @@ -19,7 +19,7 @@ use Infrastructure\Adapters\Repositories\SessionBasketRepository; use Infrastructure\Adapters\Serializers\BasketSerializer; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; describe('SessionBasketRepository', function () { @@ -34,7 +34,7 @@ describe('SessionBasketRepository', function () { it('returns null when session is empty', function () { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); // WHEN $basket = getRepository()->find($basketId); @@ -45,7 +45,7 @@ describe('SessionBasketRepository', function () { it('can save a basket into the session and retrieve it identically', function (BasketProduct $product) { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId, [$product->id->value->toString() => $product]); $repository = getRepository(); @@ -78,7 +78,7 @@ describe('SessionBasketRepository', function () { ->and($retrievedProduct->options)->toBe($product->options); })->with([ 'Full product' => fn () => new BasketProduct( - id: new ProductId(Uuid::uuid7()), + id: new ProductId(UuidHelper::v7()), name: 'Poulet Rôti', qty: 2, unitPriceHt: new Money(1200, new Currency('EUR')), @@ -97,7 +97,7 @@ describe('SessionBasketRepository', function () { options: ['cut' => 'halves'] ), 'Minimal product without optional fields' => fn () => new BasketProduct( - id: new ProductId(Uuid::uuid7()), + id: new ProductId(UuidHelper::v7()), name: 'Pâtes', qty: 1, unitPriceHt: new Money(200, new Currency('EUR')), @@ -120,7 +120,7 @@ describe('SessionBasketRepository', function () { it('can destroy the basket from the session', function () { // GIVEN $repository = getRepository(); - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId, []); $repository->persist($basket); diff --git a/tests/Integration/WithApp/Infra/Adapters/Services/AppCustomerAuthServiceTest.php b/tests/Integration/WithApp/Infra/Adapters/Services/AppCustomerAuthServiceTest.php index d4eaa838..c34daa12 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Services/AppCustomerAuthServiceTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Services/AppCustomerAuthServiceTest.php @@ -16,7 +16,7 @@ use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\StatefulGuard; use Infrastructure\Adapters\Services\AppCustomerAuthService; use Mockery; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Shared\ValueObjects\CrmHashcode; describe('AppCustomerAuthService', function (): void { @@ -65,7 +65,7 @@ describe('AppCustomerAuthService', function (): void { $guard = Mockery::spy(StatefulGuard::class); $crmService = Mockery::mock(CrmService::class); $customer = new Customer(); - $customer->id = (string) Uuid::uuid7(); + $customer->id = (string) UuidHelper::v7(); $service = new AppCustomerAuthService($guard, $crmService); @@ -251,7 +251,7 @@ describe('AppCustomerAuthService', function (): void { $guard = Mockery::mock(StatefulGuard::class); $crmService = Mockery::mock(CrmService::class); $customer = new Customer(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer->hashcode = $hashcode; // DO NOT MOCK CrmCustomer @@ -289,7 +289,7 @@ describe('AppCustomerAuthService', function (): void { $guard = Mockery::mock(StatefulGuard::class); $crmService = Mockery::mock(CrmService::class); $customer = new Customer(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer->hashcode = $hashcode; $crmService->shouldReceive('getCustomerFromHashCode')->with($customer->hashcode)->andReturn(null); @@ -308,7 +308,7 @@ describe('AppCustomerAuthService', function (): void { $guard = Mockery::mock(StatefulGuard::class); $crmService = Mockery::mock(CrmService::class); $customer = new Customer(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer->hashcode = $hashcode; $crmCustomer = new CrmCustomer( @@ -349,7 +349,7 @@ describe('AppCustomerAuthService', function (): void { $guard = Mockery::mock(StatefulGuard::class); $crmService = Mockery::mock(CrmService::class); $customer = new Customer(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer->hashcode = $hashcode; $crmService->shouldReceive('getCustomerFromHashCode')->with($customer->hashcode)->andReturn(null); @@ -368,7 +368,7 @@ describe('AppCustomerAuthService', function (): void { $guard = Mockery::mock(StatefulGuard::class); $crmService = Mockery::mock(CrmService::class); $customer = new Customer(); - $hashcode = new CrmHashcode(Uuid::uuid4()); + $hashcode = new CrmHashcode(UuidHelper::v4()); $customer->hashcode = $hashcode; $exception = new CrmServiceException('Crm Error'); diff --git a/tests/Integration/WithApp/Infra/Adapters/Services/AppSessionServiceTest.php b/tests/Integration/WithApp/Infra/Adapters/Services/AppSessionServiceTest.php index 495d1a8b..d95aff3b 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Services/AppSessionServiceTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Services/AppSessionServiceTest.php @@ -6,7 +6,6 @@ namespace Tests\Integration\WithApp\Infra\Adapters\Services; use Illuminate\Support\Facades\Session; use Infrastructure\Adapters\Services\AppSessionService; -use Ramsey\Uuid\Uuid; use Shared\Helpers\UuidHelper; describe('AppSessionService', function (): void { @@ -43,7 +42,7 @@ describe('AppSessionService', function (): void { it('hydrates an existing UUID string already stored in Session under the configured key', function (): void { // GIVEN $sessionKey = 'test_session_id'; - $existingUuid = Uuid::uuid7()->toString(); + $existingUuid = UuidHelper::v7()->toString(); Session::put($sessionKey, $existingUuid); $service = new AppSessionService($sessionKey); diff --git a/tests/Integration/WithApp/Infra/Adapters/Services/DatabaseTunnelAttemptTrackerServiceTest.php b/tests/Integration/WithApp/Infra/Adapters/Services/DatabaseTunnelAttemptTrackerServiceTest.php index 0d857e0f..cc15035a 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Services/DatabaseTunnelAttemptTrackerServiceTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Services/DatabaseTunnelAttemptTrackerServiceTest.php @@ -27,7 +27,7 @@ use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\Session; use Infrastructure\Adapters\Services\DatabaseTunnelAttemptTrackerService; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; covers(DatabaseTunnelAttemptTrackerService::class); @@ -46,11 +46,11 @@ describe('DatabaseTunnelAttemptTrackerService', function (): void { /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('attempt-reuse@example.com'), ]); - $shopperId = new ShopperId(Uuid::fromString($customer->id)); + $shopperId = new ShopperId(UuidHelper::fromString($customer->id)); // WHEN $tracker->recordEntry($shopperId); @@ -82,16 +82,16 @@ describe('DatabaseTunnelAttemptTrackerService', function (): void { /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('attempt-convert@example.com'), ]); - $shopperId = new ShopperId(Uuid::fromString($customer->id)); + $shopperId = new ShopperId(UuidHelper::fromString($customer->id)); - $orderId = Uuid::uuid7()->toString(); + $orderId = UuidHelper::v7()->toString(); Order::query()->forceCreate([ 'id' => $orderId, - 'reference' => new OrderReference(Uuid::uuid7()), + 'reference' => new OrderReference(UuidHelper::v7()), 'status' => OrderStatus::VALIDATED->value, 'total' => Money::EUR(1500), 'employee' => new OrderEmployee( @@ -108,7 +108,7 @@ describe('DatabaseTunnelAttemptTrackerService', function (): void { $tracker->recordEntry($shopperId); // WHEN - $tracker->markConverted(new OrderId(Uuid::fromString($orderId))); + $tracker->markConverted(new OrderId(UuidHelper::fromString($orderId))); // THEN expect($session->has('order_tunnel_attempt_id'))->toBeFalse(); @@ -131,14 +131,14 @@ describe('DatabaseTunnelAttemptTrackerService', function (): void { /** @var Customer $customer */ $customer = Customer::query()->forceCreate([ - 'id' => Uuid::uuid7()->toString(), - 'hashcode' => Uuid::uuid4()->toString(), + 'id' => UuidHelper::v7()->toString(), + 'hashcode' => UuidHelper::v4()->toString(), 'email' => new Email('attempt-clear@example.com'), ]); - $tracker->recordEntry(new ShopperId(Uuid::fromString($customer->id))); + $tracker->recordEntry(new ShopperId(UuidHelper::fromString($customer->id))); // WHEN - $listener->handle(new BasketRemoved(new BasketId(Uuid::uuid7()))); + $listener->handle(new BasketRemoved(new BasketId(UuidHelper::v7()))); // THEN expect($session->has('order_tunnel_attempt_id'))->toBeFalse() diff --git a/tests/Integration/WithApp/Infra/Adapters/Services/EloquentEmployeeStatisticsServiceTest.php b/tests/Integration/WithApp/Infra/Adapters/Services/EloquentEmployeeStatisticsServiceTest.php index 89aac542..4c41a9f8 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Services/EloquentEmployeeStatisticsServiceTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Services/EloquentEmployeeStatisticsServiceTest.php @@ -10,102 +10,104 @@ use Domain\Enums\OrderStatus; use Domain\Models\ValueObjects\Matricule; use Illuminate\Support\Facades\DB; use Infrastructure\Adapters\Services\EloquentEmployeeStatisticsService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; -it('retrieves the weekly order total for a given employee', function () { - // GIVEN - $shop = Shop::factory()->create(); +describe('EloquentEmployeeStatisticsService', function (): void { + it('retrieves the weekly order total for a given employee', function () { + // GIVEN + $shop = Shop::factory()->create(); - DB::table('orders')->insert([ - 'id' => '018e4567-e89b-72d3-a456-426614174000', - 'shop_id' => $shop->id, - 'reference' => Uuid::uuid7()->toString(), - 'employee' => json_encode([ - 'matricule' => '1234567', - 'firstname' => 'Jean', - 'lastname' => 'Dupont', - 'facility' => 'Main Facility', - 'site' => 'HQ', - 'service' => 'IT', - ]), - 'delivery_address' => '{}', - 'pickup_day' => '2023-01-05', - 'status' => OrderStatus::VALIDATED->value, - 'total' => 1500, // 15.00 EUR - ]); + DB::table('orders')->insert([ + 'id' => '018e4567-e89b-72d3-a456-426614174000', + 'shop_id' => $shop->id, + 'reference' => UuidHelper::v7()->toString(), + 'employee' => json_encode([ + 'matricule' => '1234567', + 'firstname' => 'Jean', + 'lastname' => 'Dupont', + 'facility' => 'Main Facility', + 'site' => 'HQ', + 'service' => 'IT', + ]), + 'delivery_address' => '{}', + 'pickup_day' => '2023-01-05', + 'status' => OrderStatus::VALIDATED->value, + 'total' => 1500, // 15.00 EUR + ]); - $service = new EloquentEmployeeStatisticsService(); - $start = CarbonImmutable::parse('2023-01-01'); - $end = CarbonImmutable::parse('2023-01-07'); + $service = new EloquentEmployeeStatisticsService(); + $start = CarbonImmutable::parse('2023-01-01'); + $end = CarbonImmutable::parse('2023-01-07'); - // WHEN - $result = $service->getWeeklyTotalForEmployee(new Matricule('1234567'), $start, $end); + // WHEN + $result = $service->getWeeklyTotalForEmployee(new Matricule('1234567'), $start, $end); - // THEN - expect($result->getAmount())->toBe('1500') - ->and($result->getCurrency()->getCode())->toBe('EUR'); -}); - -it('includes VALIDATED and PENDING orders and excludes WAITING, FAILED, and CANCELED orders in weekly total', function (): void { - // GIVEN - $shop = Shop::factory()->create(); - - $baseRow = [ - 'shop_id' => $shop->id, - 'employee' => json_encode([ - 'matricule' => '1234567', - 'firstname' => 'Jean', - 'lastname' => 'Dupont', - 'facility' => 'Main Facility', - 'site' => 'HQ', - 'service' => 'IT', - ]), - 'delivery_address' => '{}', - 'pickup_day' => '2023-01-05', - ]; - - DB::table('orders')->insert([ - array_merge($baseRow, [ - 'id' => Uuid::uuid7()->toString(), - 'reference' => Uuid::uuid7()->toString(), - 'status' => OrderStatus::VALIDATED->value, - 'total' => 1000, - ]), - array_merge($baseRow, [ - 'id' => Uuid::uuid7()->toString(), - 'reference' => Uuid::uuid7()->toString(), - 'status' => OrderStatus::PENDING->value, - 'total' => 2500, - ]), - array_merge($baseRow, [ - 'id' => Uuid::uuid7()->toString(), - 'reference' => Uuid::uuid7()->toString(), - 'status' => OrderStatus::WAITING->value, - 'total' => 4000, - ]), - array_merge($baseRow, [ - 'id' => Uuid::uuid7()->toString(), - 'reference' => Uuid::uuid7()->toString(), - 'status' => OrderStatus::FAILED->value, - 'total' => 5000, - ]), - array_merge($baseRow, [ - 'id' => Uuid::uuid7()->toString(), - 'reference' => Uuid::uuid7()->toString(), - 'status' => OrderStatus::CANCELED->value, - 'total' => 9000, - ]), - ]); - - $service = new EloquentEmployeeStatisticsService(); - - // WHEN - $result = $service->getWeeklyTotalForEmployee( - new Matricule('1234567'), - CarbonImmutable::parse('2023-01-01'), - CarbonImmutable::parse('2023-01-07') - ); - - // THEN - expect($result->getAmount())->toBe('3500'); + // THEN + expect($result->getAmount())->toBe('1500') + ->and($result->getCurrency()->getCode())->toBe('EUR'); + }); + + it('includes VALIDATED and PENDING orders and excludes WAITING, FAILED, and CANCELED orders in weekly total', function (): void { + // GIVEN + $shop = Shop::factory()->create(); + + $baseRow = [ + 'shop_id' => $shop->id, + 'employee' => json_encode([ + 'matricule' => '1234567', + 'firstname' => 'Jean', + 'lastname' => 'Dupont', + 'facility' => 'Main Facility', + 'site' => 'HQ', + 'service' => 'IT', + ]), + 'delivery_address' => '{}', + 'pickup_day' => '2023-01-05', + ]; + + DB::table('orders')->insert([ + array_merge($baseRow, [ + 'id' => UuidHelper::v7()->toString(), + 'reference' => UuidHelper::v7()->toString(), + 'status' => OrderStatus::VALIDATED->value, + 'total' => 1000, + ]), + array_merge($baseRow, [ + 'id' => UuidHelper::v7()->toString(), + 'reference' => UuidHelper::v7()->toString(), + 'status' => OrderStatus::PENDING->value, + 'total' => 2500, + ]), + array_merge($baseRow, [ + 'id' => UuidHelper::v7()->toString(), + 'reference' => UuidHelper::v7()->toString(), + 'status' => OrderStatus::WAITING->value, + 'total' => 4000, + ]), + array_merge($baseRow, [ + 'id' => UuidHelper::v7()->toString(), + 'reference' => UuidHelper::v7()->toString(), + 'status' => OrderStatus::FAILED->value, + 'total' => 5000, + ]), + array_merge($baseRow, [ + 'id' => UuidHelper::v7()->toString(), + 'reference' => UuidHelper::v7()->toString(), + 'status' => OrderStatus::CANCELED->value, + 'total' => 9000, + ]), + ]); + + $service = new EloquentEmployeeStatisticsService(); + + // WHEN + $result = $service->getWeeklyTotalForEmployee( + new Matricule('1234567'), + CarbonImmutable::parse('2023-01-01'), + CarbonImmutable::parse('2023-01-07') + ); + + // THEN + expect($result->getAmount())->toBe('3500'); + }); }); diff --git a/tests/Unit/App/Cqs/Actions/Orders/ApplyPickTimeSlotTest.php b/tests/Unit/App/Cqs/Actions/Orders/ApplyPickTimeSlotTest.php index ad9ab7d3..be4eadf6 100644 --- a/tests/Unit/App/Cqs/Actions/Orders/ApplyPickTimeSlotTest.php +++ b/tests/Unit/App/Cqs/Actions/Orders/ApplyPickTimeSlotTest.php @@ -14,12 +14,12 @@ use Domain\Models\ValueObjects\Entities\ShopId; use Domain\Models\ValueObjects\Entities\ShopperId; use Domain\Models\ValueObjects\PickupTimeSlot; use Domain\Services\OrderTunnelService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ApplyPickTimeSlot', function (): void { it('applies time slot to order builder via OrderTunnelService', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $timeslot = CarbonImmutable::parse('2026-10-15'); $input = new ApplyPickTimeSlotInput( shopperId: $shopperId, @@ -28,7 +28,7 @@ describe('ApplyPickTimeSlot', function (): void { $builder = \Mockery::mock(OrderBuilderWithBasket::class); $shop = new Shop( - id: new ShopId(Uuid::uuid7()), + id: new ShopId(UuidHelper::v7()), name: 'Shop 1', address: '1 rue Test', postcode: '75001', @@ -66,7 +66,7 @@ describe('ApplyPickTimeSlot', function (): void { it('returns unavailable output when no time slot matches', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $timeslot = CarbonImmutable::parse('2026-10-15'); $input = new ApplyPickTimeSlotInput( shopperId: $shopperId, @@ -75,7 +75,7 @@ describe('ApplyPickTimeSlot', function (): void { $builder = \Mockery::mock(OrderBuilderWithBasket::class); $shop = new Shop( - id: new ShopId(Uuid::uuid7()), + id: new ShopId(UuidHelper::v7()), name: 'Shop 1', address: '1 rue Test', postcode: '75001', diff --git a/tests/Unit/App/Cqs/Actions/Orders/CancelOrderTest.php b/tests/Unit/App/Cqs/Actions/Orders/CancelOrderTest.php index 3786e299..03c99c59 100644 --- a/tests/Unit/App/Cqs/Actions/Orders/CancelOrderTest.php +++ b/tests/Unit/App/Cqs/Actions/Orders/CancelOrderTest.php @@ -10,12 +10,12 @@ use App\Cqs\Actions\Orders\CancelOrderOutput; use App\Models\Order; use Domain\Models\ValueObjects\Entities\OrderId; use Domain\Services\OrderService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('CancelOrder', function (): void { it('cancels the order and returns CANCELLED when OrderService succeeds', function (): void { // GIVEN - $orderId = new OrderId(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); $order = new Order(); $order->id = $orderId->value->toString(); @@ -35,7 +35,7 @@ describe('CancelOrder', function (): void { it('returns NOT_FOUND when OrderService throws DomainException', function (): void { // GIVEN - $orderId = new OrderId(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); $order = new Order(); $order->id = $orderId->value->toString(); diff --git a/tests/Unit/App/Cqs/Actions/Orders/PlacePendingOrderTest.php b/tests/Unit/App/Cqs/Actions/Orders/PlacePendingOrderTest.php index dc13eebd..7517aba5 100644 --- a/tests/Unit/App/Cqs/Actions/Orders/PlacePendingOrderTest.php +++ b/tests/Unit/App/Cqs/Actions/Orders/PlacePendingOrderTest.php @@ -44,18 +44,18 @@ use Domain\Models\ValueObjects\ShopperSiteCode; use Domain\Ports\Repositories\BasketRepository; use Domain\Services\OrderTunnelService; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('PlacePendingOrder', function (): void { it('places a pending order and returns id and reference via OrderTunnelService', function (): void { // GIVEN $input = new PlacePendingOrderInput(); - $orderId = new OrderId(Uuid::uuid7()); - $orderReference = new OrderReference(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); + $orderReference = new OrderReference(UuidHelper::v7()); $builder = \Mockery::mock(OrderBuilderCompleted::class); $order = new Order( id: $orderId, - shopId: new ShopId(Uuid::uuid7()), + shopId: new ShopId(UuidHelper::v7()), reference: $orderReference, employee: new OrderEmployee( matricule: new Matricule('1234567'), @@ -163,7 +163,7 @@ describe('PlacePendingOrder', function (): void { // GIVEN $input = new PlacePendingOrderInput(); $builder = \Mockery::mock(OrderBuilderCompleted::class); - $refreshedBasket = new Basket(new BasketId(Uuid::uuid7()), []); + $refreshedBasket = new Basket(new BasketId(UuidHelper::v7()), []); /** @var \Mockery\MockInterface&OrderTunnelService $orderTunnelService */ $orderTunnelService = \Mockery::mock(OrderTunnelService::class); $orderTunnelService->shouldReceive('getBuilderCompletedOrFail')->once()->andReturn($builder); @@ -191,7 +191,7 @@ describe('PlacePendingOrder', function (): void { it('builds shopper lock key and returns LOCK_TIMEOUT output on lock timeout', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $input = new PlacePendingOrderInput(shopperId: $shopperId); /** @var \Mockery\MockInterface&OrderTunnelService $orderTunnelService */ $orderTunnelService = \Mockery::mock(OrderTunnelService::class); @@ -213,7 +213,7 @@ describe('PlacePendingOrder', function (): void { describe('ExportOrderToRegate, ConfirmPlacedOrder and FailPendingOrder', function (): void { it('exports order via OrderTunnelService and handles lock timeout', function (): void { // GIVEN - $orderId = new OrderId(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); $input = new ExportOrderToRegateInput($orderId); /** @var \Mockery\MockInterface&OrderTunnelService $orderTunnelService */ @@ -233,11 +233,11 @@ describe('ExportOrderToRegate, ConfirmPlacedOrder and FailPendingOrder', functio it('confirms a placed order and fails a pending order', function (): void { // GIVEN - $orderId = new OrderId(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); $order = new Order( id: $orderId, - shopId: new ShopId(Uuid::uuid7()), - reference: new OrderReference(Uuid::uuid7()), + shopId: new ShopId(UuidHelper::v7()), + reference: new OrderReference(UuidHelper::v7()), employee: new OrderEmployee( matricule: new Matricule('1234567'), firstname: 'Jean', diff --git a/tests/Unit/App/Cqs/Actions/ProductIncos/AssociateProductIncoInputTest.php b/tests/Unit/App/Cqs/Actions/ProductIncos/AssociateProductIncoInputTest.php index 9729cd7f..447273d8 100644 --- a/tests/Unit/App/Cqs/Actions/ProductIncos/AssociateProductIncoInputTest.php +++ b/tests/Unit/App/Cqs/Actions/ProductIncos/AssociateProductIncoInputTest.php @@ -6,12 +6,12 @@ namespace Tests\Unit\App\Cqs\Actions\ProductIncos; use App\Cqs\Actions\ProductIncos\AssociateProductIncoInput; use Domain\Models\ValueObjects\Entities\ProductId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('AssociateProductIncoInput', function (): void { it('creates input successfully with valid parameters', function (): void { // GIVEN - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $noArt = 27996; // WHEN @@ -24,7 +24,7 @@ describe('AssociateProductIncoInput', function (): void { it('throws when no_art is less than 1', function (): void { // GIVEN - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $noArt = 0; // WHEN & THEN diff --git a/tests/Unit/App/Cqs/Queries/Orders/GetBasketSummaryQueryTest.php b/tests/Unit/App/Cqs/Queries/Orders/GetBasketSummaryQueryTest.php index 4acaf9d9..23e88b06 100644 --- a/tests/Unit/App/Cqs/Queries/Orders/GetBasketSummaryQueryTest.php +++ b/tests/Unit/App/Cqs/Queries/Orders/GetBasketSummaryQueryTest.php @@ -10,12 +10,12 @@ use Domain\Enums\OrderTunnelStep; use Domain\Models\Entities\Basket; use Domain\Models\ValueObjects\Entities\BasketId; use Domain\Services\BasketService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('GetBasketSummaryQuery', function (): void { it('returns basket summary output with step REVIEW and basket', function (): void { // GIVEN - $basket = new Basket(new BasketId(Uuid::uuid7())); + $basket = new Basket(new BasketId(UuidHelper::v7())); $basketService = \Mockery::mock(BasketService::class); $basketService->shouldReceive('getBasket') ->once() diff --git a/tests/Unit/App/Cqs/Queries/Orders/GetOrderConfirmationQueryTest.php b/tests/Unit/App/Cqs/Queries/Orders/GetOrderConfirmationQueryTest.php index 49302843..f013ac16 100644 --- a/tests/Unit/App/Cqs/Queries/Orders/GetOrderConfirmationQueryTest.php +++ b/tests/Unit/App/Cqs/Queries/Orders/GetOrderConfirmationQueryTest.php @@ -14,14 +14,14 @@ use Domain\Models\ValueObjects\Entities\BasketId; use Domain\Models\ValueObjects\Entities\ShopId; use Domain\Ports\Repositories\ShopRepository; use Domain\Services\OrderTunnelService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; describe('GetOrderConfirmationQuery', function (): void { it('returns order confirmation output with step, basket, builder and shop', function (): void { // GIVEN - $shopId = new ShopId(Uuid::uuid7()); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $shopId = new ShopId(UuidHelper::v7()); + $basket = new Basket(new BasketId(UuidHelper::v7())); $builder = \Mockery::mock(OrderBuilderCompleted::class); $builder->shouldReceive('getBasket')->once()->andReturn($basket); $builder->shouldReceive('getShopId')->once()->andReturn($shopId); @@ -60,8 +60,8 @@ describe('GetOrderConfirmationQuery', function (): void { it('throws NotFoundHttpException when shop is not found', function (): void { // GIVEN - $shopId = new ShopId(Uuid::uuid7()); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $shopId = new ShopId(UuidHelper::v7()); + $basket = new Basket(new BasketId(UuidHelper::v7())); $builder = \Mockery::mock(OrderBuilderCompleted::class); $builder->shouldReceive('getBasket')->once()->andReturn($basket); $builder->shouldReceive('getShopId')->once()->andReturn($shopId); diff --git a/tests/Unit/App/Cqs/Queries/Orders/GetPickTimeSlotQueryTest.php b/tests/Unit/App/Cqs/Queries/Orders/GetPickTimeSlotQueryTest.php index 87493ad7..013797b4 100644 --- a/tests/Unit/App/Cqs/Queries/Orders/GetPickTimeSlotQueryTest.php +++ b/tests/Unit/App/Cqs/Queries/Orders/GetPickTimeSlotQueryTest.php @@ -15,16 +15,16 @@ use Domain\Models\ValueObjects\Entities\ShopId; use Domain\Models\ValueObjects\Entities\ShopperId; use Domain\Models\ValueObjects\PickupTimeSlot; use Domain\Services\OrderTunnelService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('GetPickTimeSlotQuery', function (): void { it('returns pick time slot output with step BOOKING, shop, mapUrl and timeslots', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $input = new GetPickTimeSlotQueryInput($shopperId); $shop = new Shop( - id: new ShopId(Uuid::uuid7()), + id: new ShopId(UuidHelper::v7()), name: 'Shop 1', address: '1 rue Test', postcode: '75001', diff --git a/tests/Unit/App/Dto/ShopDtoTest.php b/tests/Unit/App/Dto/ShopDtoTest.php index d9d89ccf..fe52d65c 100644 --- a/tests/Unit/App/Dto/ShopDtoTest.php +++ b/tests/Unit/App/Dto/ShopDtoTest.php @@ -7,12 +7,12 @@ namespace Tests\Unit\App\Dto; use App\Dto\ShopDto; use Domain\Models\Entities\Shop; use Domain\Models\ValueObjects\Entities\ShopId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ShopDto', function (): void { it('creates a DTO from domain Shop entity', function (): void { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); $shopId = new ShopId($uuid); $domainShop = new Shop( id: $shopId, diff --git a/tests/Unit/App/Listeners/Orders/EmptyBasketOnOrderPlacedTest.php b/tests/Unit/App/Listeners/Orders/EmptyBasketOnOrderPlacedTest.php index 363625cc..972f8c2b 100644 --- a/tests/Unit/App/Listeners/Orders/EmptyBasketOnOrderPlacedTest.php +++ b/tests/Unit/App/Listeners/Orders/EmptyBasketOnOrderPlacedTest.php @@ -26,13 +26,13 @@ use Domain\Ports\Repositories\ProductRepository; use Domain\Ports\Services\SessionService; use Domain\Services\BasketService; use Money\Money; -use Ramsey\Uuid\Uuid; use Shared\DDD\DomainEventDispatcher; +use Shared\Helpers\UuidHelper; describe('EmptyBasketOnOrderPlaced', function (): void { it('empties the basket when an order has been placed', function (): void { // GIVEN - $sessionUuid = Uuid::uuid7(); + $sessionUuid = UuidHelper::v7(); $basket = new Basket(new BasketId($sessionUuid)); /** @var BasketRepository&\Mockery\MockInterface $basketRepository */ @@ -54,8 +54,8 @@ describe('EmptyBasketOnOrderPlaced', function (): void { $listener = new EmptyBasketOnOrderPlaced($basketService); $event = new AnOrderHasBeenPlaced( - orderId: new OrderId(Uuid::uuid7()), - reference: new OrderReference(Uuid::uuid7()), + orderId: new OrderId(UuidHelper::v7()), + reference: new OrderReference(UuidHelper::v7()), totalTtc: Money::EUR(1000), byMatricule: new Matricule('1234567'), employee: new OrderEmployee( diff --git a/tests/Unit/App/Listeners/Orders/InvalidateOrderBuilderOnBasketChangeTest.php b/tests/Unit/App/Listeners/Orders/InvalidateOrderBuilderOnBasketChangeTest.php index 8f5727c3..b23e81ec 100644 --- a/tests/Unit/App/Listeners/Orders/InvalidateOrderBuilderOnBasketChangeTest.php +++ b/tests/Unit/App/Listeners/Orders/InvalidateOrderBuilderOnBasketChangeTest.php @@ -9,7 +9,7 @@ use Domain\Events\BasketHasBeenModified; use Domain\Events\BasketRemoved; use Domain\Models\ValueObjects\Entities\BasketId; use Domain\Ports\Services\OrderBuilderSessionManager; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('InvalidateOrderBuilderOnBasketChange', function (): void { it('clears the order builder session manager when basket is modified', function (): void { @@ -17,7 +17,7 @@ describe('InvalidateOrderBuilderOnBasketChange', function (): void { /** @var OrderBuilderSessionManager&\Mockery\MockInterface $manager */ $manager = \Mockery::spy(OrderBuilderSessionManager::class); $listener = new InvalidateOrderBuilderOnBasketChange($manager); - $event = new BasketHasBeenModified(new BasketId(Uuid::uuid7())); + $event = new BasketHasBeenModified(new BasketId(UuidHelper::v7())); // WHEN $listener->handle($event); @@ -31,7 +31,7 @@ describe('InvalidateOrderBuilderOnBasketChange', function (): void { /** @var OrderBuilderSessionManager&\Mockery\MockInterface $manager */ $manager = \Mockery::spy(OrderBuilderSessionManager::class); $listener = new InvalidateOrderBuilderOnBasketChange($manager); - $event = new BasketRemoved(new BasketId(Uuid::uuid7())); + $event = new BasketRemoved(new BasketId(UuidHelper::v7())); // WHEN $listener->handle($event); diff --git a/tests/Unit/App/Policies/Backend/ProductPolicyTest.php b/tests/Unit/App/Policies/Backend/ProductPolicyTest.php index fed9c41f..16757ddf 100644 --- a/tests/Unit/App/Policies/Backend/ProductPolicyTest.php +++ b/tests/Unit/App/Policies/Backend/ProductPolicyTest.php @@ -16,7 +16,7 @@ use Domain\Models\Entities\Product as DomainProduct; use Domain\Models\ValueObjects\Entities\ProductId; use Domain\Ports\Repositories\ProductRepository; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ProductPolicy', function () { function getProductPolicy(?ProductRepository $repo = null): ProductPolicy @@ -29,7 +29,7 @@ describe('ProductPolicy', function () { function createDomainProduct(bool $status = true): DomainProduct { return new DomainProduct( - new ProductId(Uuid::uuid7()), + new ProductId(UuidHelper::v7()), Money::EUR(100), TaxRate::TVA_20, null, @@ -254,7 +254,7 @@ describe('ProductPolicy', function () { test('viewPublished returns false when product not found in domain repo', function () { // GIVEN $product = \Mockery::mock(Product::class); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $product->shouldReceive('getId')->andReturn($productId); $repo = \Mockery::mock(ProductRepository::class); @@ -271,7 +271,7 @@ describe('ProductPolicy', function () { test('viewPublished returns true when product found and is published', function () { // GIVEN $product = \Mockery::mock(Product::class); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $product->shouldReceive('getId')->andReturn($productId); $domainProduct = createDomainProduct(status: true); @@ -290,7 +290,7 @@ describe('ProductPolicy', function () { test('viewPublished returns false when product found and is not published', function () { // GIVEN $product = \Mockery::mock(Product::class); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $product->shouldReceive('getId')->andReturn($productId); $domainProduct = createDomainProduct(status: false); diff --git a/tests/Unit/App/Policies/Frontend/BasketPolicyTest.php b/tests/Unit/App/Policies/Frontend/BasketPolicyTest.php index 1c9db103..d0e0ebe4 100644 --- a/tests/Unit/App/Policies/Frontend/BasketPolicyTest.php +++ b/tests/Unit/App/Policies/Frontend/BasketPolicyTest.php @@ -14,7 +14,7 @@ use Domain\Models\ValueObjects\BasketProduct; use Domain\Models\ValueObjects\DiscountRate; use Domain\Models\ValueObjects\Entities\ProductId; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; covers(BasketPolicy::class); @@ -22,7 +22,7 @@ function createDummyBasketProductDto(bool $isPublished = true): BasketProductDto { return new BasketProductDto( product: new BasketProduct( - new ProductId(Uuid::uuid7()), + new ProductId(UuidHelper::v7()), 'Dummy', 1, Money::EUR(1000), diff --git a/tests/Unit/Domain/Builders/OrderBuilderTest.php b/tests/Unit/Domain/Builders/OrderBuilderTest.php index 246146c3..c0e7a9d8 100644 --- a/tests/Unit/Domain/Builders/OrderBuilderTest.php +++ b/tests/Unit/Domain/Builders/OrderBuilderTest.php @@ -14,14 +14,14 @@ use Domain\Models\ValueObjects\Entities\BasketId; use Domain\Models\ValueObjects\Entities\ShopId; use Domain\Models\ValueObjects\Entities\ShopperId; use Domain\Models\ValueObjects\PickupTimeSlot; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('OrderBuilder', function (): void { it('initializes from basket as an immutable BasketOrderBuilder', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $customerId = new ShopperId(Uuid::uuid7()); + $customerId = new ShopperId(UuidHelper::v7()); // WHEN $builder = OrderBuilder::fromBasket($basket, $customerId); @@ -37,10 +37,10 @@ describe('OrderBuilder', function (): void { it('returns a new immutable CompletedOrderBuilder when applying a timeslot', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $customerId = new ShopperId(Uuid::uuid7()); - $shopId = new ShopId(Uuid::uuid7()); + $customerId = new ShopperId(UuidHelper::v7()); + $shopId = new ShopId(UuidHelper::v7()); $timeSlot = new PickupTimeSlot(new \DateTimeImmutable(), new \DateInterval('PT1H')); $builder = OrderBuilder::fromBasket($basket, $customerId); @@ -63,11 +63,11 @@ describe('OrderBuilder', function (): void { it('returns a new immutable CompletedOrderBuilder when updating the timeslot', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $customerId = new ShopperId(Uuid::uuid7()); - $firstShop = new ShopId(Uuid::uuid7()); - $secondShop = new ShopId(Uuid::uuid7()); + $customerId = new ShopperId(UuidHelper::v7()); + $firstShop = new ShopId(UuidHelper::v7()); + $secondShop = new ShopId(UuidHelper::v7()); $firstSlot = new PickupTimeSlot(new \DateTimeImmutable('+1 day'), new \DateInterval('PT1H')); $secondSlot = new PickupTimeSlot(new \DateTimeImmutable('+2 days'), new \DateInterval('PT1H')); $firstStep = OrderBuilder::fromBasket($basket, $customerId)->withPickupTimeSlot($firstShop, $firstSlot); diff --git a/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php b/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php index d0ef4c7a..3a4bd084 100644 --- a/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php +++ b/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php @@ -18,14 +18,14 @@ use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('AnOrderHasBeenPlaced', function () { it('creates an event when valid', function () { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); $orderId = new OrderId($uuid); - $reference = new OrderReference(Uuid::uuid7()); + $reference = new OrderReference(UuidHelper::v7()); $totalTtc = new Money(1000, new Currency('EUR')); $matricule = new Matricule('1234567'); $employee = new OrderEmployee( @@ -52,9 +52,9 @@ describe('AnOrderHasBeenPlaced', function () { it('throws exception if lines are empty', function () { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); $orderId = new OrderId($uuid); - $reference = new OrderReference(Uuid::uuid7()); + $reference = new OrderReference(UuidHelper::v7()); $totalTtc = new Money(1000, new Currency('EUR')); $matricule = new Matricule('1234567'); $employee = new OrderEmployee( diff --git a/tests/Unit/Domain/Events/BasketHasBeenModifiedTest.php b/tests/Unit/Domain/Events/BasketHasBeenModifiedTest.php index e0f0be0e..81bd38ee 100644 --- a/tests/Unit/Domain/Events/BasketHasBeenModifiedTest.php +++ b/tests/Unit/Domain/Events/BasketHasBeenModifiedTest.php @@ -6,12 +6,12 @@ namespace Tests\Unit\Domain\Events; use Domain\Events\BasketHasBeenModified; use Domain\Models\ValueObjects\Entities\BasketId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('BasketHasBeenModified', function (): void { it('stores the basket id and implements Event', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); // WHEN $event = new BasketHasBeenModified($basketId); diff --git a/tests/Unit/Domain/Events/BasketRemovedTest.php b/tests/Unit/Domain/Events/BasketRemovedTest.php index 6fbdde8c..1d783442 100644 --- a/tests/Unit/Domain/Events/BasketRemovedTest.php +++ b/tests/Unit/Domain/Events/BasketRemovedTest.php @@ -6,12 +6,12 @@ namespace Tests\Unit\Domain\Events; use Domain\Events\BasketRemoved; use Domain\Models\ValueObjects\Entities\BasketId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('BasketRemoved', function (): void { it('stores the basket id and implements Event', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); // WHEN $event = new BasketRemoved($basketId); diff --git a/tests/Unit/Domain/Events/DtoTest.php b/tests/Unit/Domain/Events/DtoTest.php index e23a3791..e3962677 100644 --- a/tests/Unit/Domain/Events/DtoTest.php +++ b/tests/Unit/Domain/Events/DtoTest.php @@ -19,7 +19,7 @@ use Domain\Models\ValueObjects\OrderLineProduct; use Domain\Models\ValueObjects\ProductWeight; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('OrderPlacedLine', function () { it('creates OrderPlacedLine correctly', function () { @@ -54,7 +54,7 @@ describe('OrderPlacedLine', function () { // GIVEN $product = new OrderLineProduct( incoId: new IncoId(42), - originalId: new ProductId(Uuid::uuid7()), + originalId: new ProductId(UuidHelper::v7()), name: 'Poulet rôti', weight: new ProductWeight(1000, false), brand: ProductBrand::none, diff --git a/tests/Unit/Domain/Models/Entities/BasketTest.php b/tests/Unit/Domain/Models/Entities/BasketTest.php index fdb4f57c..d99a5daf 100644 --- a/tests/Unit/Domain/Models/Entities/BasketTest.php +++ b/tests/Unit/Domain/Models/Entities/BasketTest.php @@ -14,7 +14,7 @@ use Domain\Models\ValueObjects\Entities\BasketId; use Domain\Models\ValueObjects\Entities\ProductId; use Domain\Models\ValueObjects\IncoId; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; describe('Basket and BasketProduct', function (): void { @@ -28,7 +28,7 @@ describe('Basket and BasketProduct', function (): void { function getNewBasketProduct(array $overrides = []): BasketProduct { return new BasketProduct( - id: $overrides['id'] ?? new ProductId(Uuid::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')), + id: $overrides['id'] ?? new ProductId(UuidHelper::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')), name: 'Poulet Rôti', qty: $overrides['qty'] ?? 2, unitPriceHt: Money::EUR(1000), @@ -50,7 +50,7 @@ describe('Basket and BasketProduct', function (): void { it('can instantiate a basket product with all new typed properties', function (): void { // GIVEN - $productId = new ProductId(Uuid::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); + $productId = new ProductId(UuidHelper::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); $brand = ProductBrand::marie; $orderUnit = OrderUnit::PCE; $price = Money::EUR(1000); @@ -100,9 +100,9 @@ describe('Basket and BasketProduct', function (): void { it('can clone a basket product with new quantity and keep properties', function (): void { // GIVEN - $productId = new ProductId(Uuid::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); + $productId = new ProductId(UuidHelper::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); $item = getNewBasketProduct(['id' => $productId, 'qty' => 2]); - $basketId = new BasketId(Uuid::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); + $basketId = new BasketId(UuidHelper::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); $basket = new Basket($basketId); // WHEN @@ -133,7 +133,7 @@ describe('Basket and BasketProduct', function (): void { describe('Basket additional coverage', function (): void { it('throws if item is not BasketProduct', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); // WHEN $action = fn () => (new \ReflectionClass(Basket::class))->newInstance($basketId, ['not-an-item']); // THEN @@ -142,7 +142,7 @@ describe('Basket additional coverage', function (): void { it('returns id', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); // WHEN $id = $basket->id(); @@ -152,9 +152,9 @@ describe('Basket additional coverage', function (): void { it('removes item completely if quantity is greater or equal', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $item = getNewBasketProduct(['id' => $productId, 'qty' => 2]); $basket->addOrUpdate($item); @@ -168,9 +168,9 @@ describe('Basket additional coverage', function (): void { it('decreases quantity when removing', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $item = getNewBasketProduct(['id' => $productId, 'qty' => 5]); $basket->addOrUpdate($item); @@ -184,9 +184,9 @@ describe('Basket additional coverage', function (): void { it('throws when removing less than 1', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); // WHEN $action = fn () => $basket->remove($productId, 0); @@ -196,9 +196,9 @@ describe('Basket additional coverage', function (): void { it('throws when removing non-existing item', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); // WHEN $action = fn () => $basket->remove($productId, 1); @@ -208,9 +208,9 @@ describe('Basket additional coverage', function (): void { it('removes line directly', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $item = getNewBasketProduct(['id' => $productId, 'qty' => 5]); $basket->addOrUpdate($item); @@ -224,9 +224,9 @@ describe('Basket additional coverage', function (): void { it('throws when removeLine on non-existing item', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); // WHEN $action = fn () => $basket->removeLine($productId); @@ -236,9 +236,9 @@ describe('Basket additional coverage', function (): void { it('computes totals', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $item = getNewBasketProduct(['id' => $productId, 'qty' => 1]); $basket->addOrUpdate($item); diff --git a/tests/Unit/Domain/Models/Entities/OrderTest.php b/tests/Unit/Domain/Models/Entities/OrderTest.php index 90906637..690a1f04 100644 --- a/tests/Unit/Domain/Models/Entities/OrderTest.php +++ b/tests/Unit/Domain/Models/Entities/OrderTest.php @@ -35,7 +35,7 @@ use Domain\Models\ValueObjects\ShopperEstablishmentCode; use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; /** @@ -55,7 +55,7 @@ function makeOrderLine(array $overrides = []): OrderLine { $product = new OrderLineProduct( incoId: new IncoId(1), - originalId: new ProductId(Uuid::uuid7()), + originalId: new ProductId(UuidHelper::v7()), name: $overrides['productName'] ?? 'Poulet Rôti', weight: new ProductWeight(1600, false), brand: ProductBrand::none, @@ -95,10 +95,10 @@ function makeOrderLine(array $overrides = []): OrderLine function makeOrder(array $overrides = []): Order { return new Order( - id: $overrides['id'] ?? new OrderId(Uuid::uuid7()), - shopId: $overrides['shopId'] ?? new ShopId(Uuid::uuid7()), + id: $overrides['id'] ?? new OrderId(UuidHelper::v7()), + shopId: $overrides['shopId'] ?? new ShopId(UuidHelper::v7()), reference: $overrides['reference'] ?? new OrderReference( - Uuid::uuid7() + UuidHelper::v7() ), employee: $overrides['employee'] ?? new OrderEmployee( matricule: new Matricule('1234567'), @@ -261,11 +261,11 @@ describe('Order - id', function (): void { describe('Order - fromBasket factory', function (): void { it('creates an order from a basket with all lines mapped', function (): void { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); $basketProduct = new BasketProduct( - id: new ProductId(Uuid::uuid7()), + id: new ProductId(UuidHelper::v7()), name: 'Poulet Rôti', qty: 2, unitPriceHt: Money::EUR(1000), @@ -284,15 +284,15 @@ describe('Order - fromBasket factory', function (): void { ); $basket->addOrUpdate($basketProduct); - $orderId = new OrderId(Uuid::uuid7()); - $reference = new OrderReference(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); + $reference = new OrderReference(UuidHelper::v7()); $pickupTimeSlot = new PickupTimeSlot( new \DateTimeImmutable('+1 day 10:00'), new \DateInterval('PT10M') ); $shopper = new Shopper( - id: new ShopperId(Uuid::uuid7()), + id: new ShopperId(UuidHelper::v7()), email: new Email('jean.dupont@example.com'), matricule: new Matricule('1234567'), nom: 'Dupont', @@ -305,7 +305,7 @@ describe('Order - fromBasket factory', function (): void { ); $shop = new Shop( - id: new ShopId(Uuid::uuid7()), + id: new ShopId(UuidHelper::v7()), name: 'Cocotte Lyon', address: '12 rue de la Paix', postcode: '69001', @@ -330,9 +330,9 @@ describe('Order - fromBasket factory', function (): void { it('creates an order in PENDING status via pendingFromBasket and validates it to VALIDATED', function (): void { // GIVEN - $basket = new Basket(new BasketId(Uuid::uuid7()), [ + $basket = new Basket(new BasketId(UuidHelper::v7()), [ new BasketProduct( - id: new ProductId(Uuid::uuid7()), + id: new ProductId(UuidHelper::v7()), name: 'Poulet Rôti', qty: 1, unitPriceHt: Money::EUR(1000), @@ -351,7 +351,7 @@ describe('Order - fromBasket factory', function (): void { ), ]); $shopper = new Shopper( - id: new ShopperId(Uuid::uuid7()), + id: new ShopperId(UuidHelper::v7()), email: new Email('jean.dupont@example.com'), matricule: new Matricule('1234567'), nom: 'Dupont', @@ -363,7 +363,7 @@ describe('Order - fromBasket factory', function (): void { service: new ShopperServiceCode('101') ); $shop = new Shop( - id: new ShopId(Uuid::uuid7()), + id: new ShopId(UuidHelper::v7()), name: 'Cocotte Lyon', address: '12 rue de la Paix', postcode: '69001', @@ -373,8 +373,8 @@ describe('Order - fromBasket factory', function (): void { // WHEN $order = Order::pendingFromBasket( - new OrderId(Uuid::uuid7()), - new OrderReference(Uuid::uuid7()), + new OrderId(UuidHelper::v7()), + new OrderReference(UuidHelper::v7()), $basket, new PickupTimeSlot(new \DateTimeImmutable('+1 day 10:00'), new \DateInterval('PT10M')), $shopper, diff --git a/tests/Unit/Domain/Models/Entities/PickupExceptionOnDateTest.php b/tests/Unit/Domain/Models/Entities/PickupExceptionOnDateTest.php index cdbb4b77..a0de477f 100644 --- a/tests/Unit/Domain/Models/Entities/PickupExceptionOnDateTest.php +++ b/tests/Unit/Domain/Models/Entities/PickupExceptionOnDateTest.php @@ -9,7 +9,7 @@ use Carbon\CarbonImmutable; use Domain\Enums\RepeatFrequency; use Domain\Models\Entities\PickupExceptionOnDate; use Domain\Models\ValueObjects\Entities\PickupExceptionId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; beforeEach(function (): void { $now = CarbonImmutable::parse('2026-06-15 10:00:00', 'Europe/Paris'); @@ -25,7 +25,7 @@ afterEach(function (): void { describe('PickupExceptionOnDate', function (): void { it('can instantiate correctly', function (): void { // GIVEN - $id = new PickupExceptionId(Uuid::uuid7()); + $id = new PickupExceptionId(UuidHelper::v7()); $date = CarbonImmutable::now(); $label = 'Férié'; $repeatable = true; @@ -58,7 +58,7 @@ describe('PickupExceptionOnDate', function (): void { $mondayDate = CarbonImmutable::parse('2025-01-06'); // 2025-01-06 is Monday $fridayException = new PickupExceptionOnDate( - new PickupExceptionId(Uuid::uuid7()), + new PickupExceptionId(UuidHelper::v7()), $fridayDate, 'Friday holiday', false, @@ -67,7 +67,7 @@ describe('PickupExceptionOnDate', function (): void { ); $mondayException = new PickupExceptionOnDate( - new PickupExceptionId(Uuid::uuid7()), + new PickupExceptionId(UuidHelper::v7()), $mondayDate, 'Monday holiday', false, diff --git a/tests/Unit/Domain/Models/Entities/ProductTest.php b/tests/Unit/Domain/Models/Entities/ProductTest.php index ce8d49de..3660b975 100644 --- a/tests/Unit/Domain/Models/Entities/ProductTest.php +++ b/tests/Unit/Domain/Models/Entities/ProductTest.php @@ -14,7 +14,7 @@ use Domain\Models\ValueObjects\DiscountValue; use Domain\Models\ValueObjects\Entities\ProductId; use Domain\Models\ValueObjects\ProductWeight; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function makeProduct( ?Money $price = null, @@ -29,7 +29,7 @@ function makeProduct( bool $hasInco = true ): Product { return new Product( - id: new ProductId(Uuid::uuid7()), + id: new ProductId(UuidHelper::v7()), price: $price ?? Money::EUR(1000), tax_rate: $taxRate, product_weight: $weight, @@ -57,7 +57,7 @@ afterEach(function (): void { describe('Product', function (): void { it('can instantiate correctly', function (): void { // GIVEN - $id = new ProductId(Uuid::uuid7()); + $id = new ProductId(UuidHelper::v7()); $price = Money::EUR(1000); $taxRate = TaxRate::TVA_5_5; $weight = new ProductWeight(500, false); diff --git a/tests/Unit/Domain/Models/Entities/ShopTest.php b/tests/Unit/Domain/Models/Entities/ShopTest.php index 55407ed5..4562562f 100644 --- a/tests/Unit/Domain/Models/Entities/ShopTest.php +++ b/tests/Unit/Domain/Models/Entities/ShopTest.php @@ -6,12 +6,12 @@ namespace Tests\Unit\Domain\Models\Entities; use Domain\Models\Entities\Shop; use Domain\Models\ValueObjects\Entities\ShopId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('Shop', function (): void { it('can instantiate correctly', function (): void { // GIVEN - $id = new ShopId(Uuid::uuid7()); + $id = new ShopId(UuidHelper::v7()); $name = 'Boutique'; $address = '123 Rue de Paris'; $postcode = '75001'; @@ -49,7 +49,7 @@ describe('Shop', function (): void { it('throws exception if name is empty', function (): void { // GIVEN - $id = new ShopId(Uuid::uuid7()); + $id = new ShopId(UuidHelper::v7()); // WHEN $action = fn () => new Shop($id, '', 'Address', '12345', 'City'); @@ -60,7 +60,7 @@ describe('Shop', function (): void { it('throws exception if address is empty', function (): void { // GIVEN - $id = new ShopId(Uuid::uuid7()); + $id = new ShopId(UuidHelper::v7()); // WHEN $action = fn () => new Shop($id, 'Name', '', '12345', 'City'); @@ -71,7 +71,7 @@ describe('Shop', function (): void { it('throws exception if postcode is empty', function (): void { // GIVEN - $id = new ShopId(Uuid::uuid7()); + $id = new ShopId(UuidHelper::v7()); // WHEN $action = fn () => new Shop($id, 'Name', 'Address', '', 'City'); @@ -82,7 +82,7 @@ describe('Shop', function (): void { it('throws exception if city is empty', function (): void { // GIVEN - $id = new ShopId(Uuid::uuid7()); + $id = new ShopId(UuidHelper::v7()); // WHEN $action = fn () => new Shop($id, 'Name', 'Address', '12345', ''); diff --git a/tests/Unit/Domain/Models/Entities/ShopperTest.php b/tests/Unit/Domain/Models/Entities/ShopperTest.php index e561bd85..d021dc5a 100644 --- a/tests/Unit/Domain/Models/Entities/ShopperTest.php +++ b/tests/Unit/Domain/Models/Entities/ShopperTest.php @@ -12,12 +12,12 @@ use Domain\Models\ValueObjects\Matricule; use Domain\Models\ValueObjects\ShopperEstablishmentCode; use Domain\Models\ValueObjects\ShopperServiceCode; use Domain\Models\ValueObjects\ShopperSiteCode; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('Shopper', function (): void { it('can instantiate correctly and check active status (active)', function (): void { // GIVEN - $id = new ShopperId(Uuid::uuid7()); + $id = new ShopperId(UuidHelper::v7()); $email = new Email('test@example.com'); $matricule = new Matricule('1234567'); $startDate = CarbonImmutable::now()->subDay(); @@ -60,7 +60,7 @@ describe('Shopper', function (): void { // WHEN $entity = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', @@ -82,7 +82,7 @@ describe('Shopper', function (): void { // WHEN $entity = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', @@ -104,7 +104,7 @@ describe('Shopper', function (): void { // WHEN $entity = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', @@ -127,7 +127,7 @@ describe('Shopper', function (): void { // WHEN $entity = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', @@ -151,7 +151,7 @@ describe('Shopper', function (): void { try { // WHEN $entity = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', @@ -178,7 +178,7 @@ describe('Shopper', function (): void { try { // WHEN $entity = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', @@ -203,7 +203,7 @@ describe('Shopper', function (): void { try { $entity = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', @@ -228,7 +228,7 @@ describe('Shopper', function (): void { try { $entity = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', @@ -250,7 +250,7 @@ describe('Shopper', function (): void { it('throws exception if nom is empty', function (): void { // WHEN $action = fn () => new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), '', @@ -269,7 +269,7 @@ describe('Shopper', function (): void { it('throws exception if prenom is empty', function (): void { // WHEN $action = fn () => new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', diff --git a/tests/Unit/Domain/Models/ValueObjects/BasketProductTest.php b/tests/Unit/Domain/Models/ValueObjects/BasketProductTest.php index cb871fe1..84662577 100644 --- a/tests/Unit/Domain/Models/ValueObjects/BasketProductTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/BasketProductTest.php @@ -12,7 +12,7 @@ use Domain\Models\ValueObjects\DiscountRate; use Domain\Models\ValueObjects\Entities\ProductId; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('BasketProduct', function () { @@ -36,7 +36,7 @@ describe('BasketProduct', function () { function getNewProduct(array $overrides = []): BasketProduct { return new BasketProduct( - id: new ProductId(Uuid::uuid7()), + id: new ProductId(UuidHelper::v7()), name: $overrides['name'] ?? 'Product Name', qty: $overrides['qty'] ?? 1, unitPriceHt: $overrides['unitPriceHt'] ?? getMoney(100), @@ -59,7 +59,7 @@ describe('BasketProduct', function () { it('can instantiate', function () { // GIVEN - $id = new ProductId(Uuid::uuid7()); + $id = new ProductId(UuidHelper::v7()); $name = 'Product Name'; $qty = 2; $unitPriceHt = getMoney(100); diff --git a/tests/Unit/Domain/Models/ValueObjects/ContactFormDataTest.php b/tests/Unit/Domain/Models/ValueObjects/ContactFormDataTest.php index dba19bb9..b047edab 100644 --- a/tests/Unit/Domain/Models/ValueObjects/ContactFormDataTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/ContactFormDataTest.php @@ -6,7 +6,7 @@ namespace Tests\Unit\Domain\Models\ValueObjects; use Domain\Models\ValueObjects\ContactFormData; use Domain\Models\ValueObjects\OrderReference; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ContactFormData', function () { @@ -41,7 +41,7 @@ describe('ContactFormData', function () { $email = 'john@example.com'; $subject = 'Inquiry'; $message = 'This is a message.'; - $orderRef = new OrderReference(Uuid::uuid7()); + $orderRef = new OrderReference(UuidHelper::v7()); $file = null; // WHEN diff --git a/tests/Unit/Domain/Models/ValueObjects/EditablePickupExceptionForShopTest.php b/tests/Unit/Domain/Models/ValueObjects/EditablePickupExceptionForShopTest.php index aeecf155..b80cc4c4 100644 --- a/tests/Unit/Domain/Models/ValueObjects/EditablePickupExceptionForShopTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/EditablePickupExceptionForShopTest.php @@ -10,7 +10,7 @@ use Domain\Enums\RepeatFrequency; use Domain\Models\Entities\PickupExceptionOnDate; use Domain\Models\ValueObjects\EditablePickupExceptionForShop; use Domain\Models\ValueObjects\Entities\PickupExceptionId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; beforeEach(function (): void { $now = CarbonImmutable::parse('2026-06-15 10:00:00', 'Europe/Paris'); @@ -27,7 +27,7 @@ describe('EditablePickupExceptionForShop', function (): void { it('can instantiate and clones the exception', function (): void { // GIVEN $exception = new PickupExceptionOnDate( - new PickupExceptionId(Uuid::uuid7()), + new PickupExceptionId(UuidHelper::v7()), CarbonImmutable::now(), 'Label', true, diff --git a/tests/Unit/Domain/Models/ValueObjects/Entities/BasketIdTest.php b/tests/Unit/Domain/Models/ValueObjects/Entities/BasketIdTest.php index 636ec9fa..a2eab978 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Entities/BasketIdTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Entities/BasketIdTest.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects\Entities; use Domain\Models\ValueObjects\Entities\BasketId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('BasketId', function (): void { it('can be instantiated with a Uuid', function (): void { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); // WHEN $id = new BasketId($uuid); // THEN @@ -19,7 +19,7 @@ describe('BasketId', function (): void { it('throws exception with non v7 uuid', function (): void { // GIVEN - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); // WHEN $action = fn () => new BasketId($uuid); // THEN diff --git a/tests/Unit/Domain/Models/ValueObjects/Entities/OrderIdTest.php b/tests/Unit/Domain/Models/ValueObjects/Entities/OrderIdTest.php index f041a985..a3dc6aa6 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Entities/OrderIdTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Entities/OrderIdTest.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects\Entities; use Domain\Models\ValueObjects\Entities\OrderId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('OrderId', function (): void { it('can be instantiated with uuid v7', function (): void { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); // WHEN $id = new OrderId($uuid); // THEN @@ -19,7 +19,7 @@ describe('OrderId', function (): void { it('throws exception with non v7 uuid', function (): void { // GIVEN - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); // WHEN $action = fn () => new OrderId($uuid); // THEN diff --git a/tests/Unit/Domain/Models/ValueObjects/Entities/PickupExceptionIdTest.php b/tests/Unit/Domain/Models/ValueObjects/Entities/PickupExceptionIdTest.php index 22198a86..b90e7cda 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Entities/PickupExceptionIdTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Entities/PickupExceptionIdTest.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects\Entities; use Domain\Models\ValueObjects\Entities\PickupExceptionId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('PickupExceptionId', function (): void { it('can be instantiated with uuid', function (): void { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); // WHEN $id = new PickupExceptionId($uuid); // THEN @@ -19,7 +19,7 @@ describe('PickupExceptionId', function (): void { it('throws exception with non v7 uuid', function (): void { // GIVEN - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); // WHEN $action = fn () => new PickupExceptionId($uuid); // THEN diff --git a/tests/Unit/Domain/Models/ValueObjects/Entities/ProductIdTest.php b/tests/Unit/Domain/Models/ValueObjects/Entities/ProductIdTest.php index 038fe1c4..210f0c1c 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Entities/ProductIdTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Entities/ProductIdTest.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects\Entities; use Domain\Models\ValueObjects\Entities\ProductId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ProductId', function (): void { it('can be instantiated with uuid v7', function (): void { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); // WHEN $id = new ProductId($uuid); // THEN @@ -19,7 +19,7 @@ describe('ProductId', function (): void { it('throws exception with non v7 uuid', function (): void { // GIVEN - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); // WHEN $action = fn () => new ProductId($uuid); // THEN diff --git a/tests/Unit/Domain/Models/ValueObjects/Entities/ShopIdTest.php b/tests/Unit/Domain/Models/ValueObjects/Entities/ShopIdTest.php index bf78dcf3..760ec452 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Entities/ShopIdTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Entities/ShopIdTest.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects\Entities; use Domain\Models\ValueObjects\Entities\ShopId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ShopId', function (): void { it('can be instantiated with uuid', function (): void { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); // WHEN $id = new ShopId($uuid); // THEN @@ -19,7 +19,7 @@ describe('ShopId', function (): void { it('throws exception with non v7 uuid', function (): void { // GIVEN - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); // WHEN $action = fn () => new ShopId($uuid); // THEN diff --git a/tests/Unit/Domain/Models/ValueObjects/Entities/ShopperIdTest.php b/tests/Unit/Domain/Models/ValueObjects/Entities/ShopperIdTest.php index 46e8a2d9..2cdf257e 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Entities/ShopperIdTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Entities/ShopperIdTest.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects\Entities; use Domain\Models\ValueObjects\Entities\ShopperId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('ShopperId', function (): void { it('can be instantiated with uuid v7', function (): void { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); // WHEN $id = new ShopperId($uuid); // THEN @@ -19,7 +19,7 @@ describe('ShopperId', function (): void { it('throws exception with non v7 uuid', function (): void { // GIVEN - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); // WHEN $action = fn () => new ShopperId($uuid); // THEN diff --git a/tests/Unit/Domain/Models/ValueObjects/OrderLineProductTest.php b/tests/Unit/Domain/Models/ValueObjects/OrderLineProductTest.php index 3d262ae6..a414ee18 100644 --- a/tests/Unit/Domain/Models/ValueObjects/OrderLineProductTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/OrderLineProductTest.php @@ -12,14 +12,14 @@ use Domain\Models\ValueObjects\IncoId; use Domain\Models\ValueObjects\OrderLineProduct; use Domain\Models\ValueObjects\ProductWeight; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; describe('OrderLineProduct', function (): void { it('can instantiate correctly', function (): void { // GIVEN $incoId = new IncoId(123); - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $weight = new ProductWeight(500, false); $product = new OrderLineProduct( @@ -56,7 +56,7 @@ describe('OrderLineProduct', function (): void { // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), - new ProductId(Uuid::uuid7()), + new ProductId(UuidHelper::v7()), '', new ProductWeight(1, false), ProductBrand::marie, @@ -75,7 +75,7 @@ describe('OrderLineProduct', function (): void { // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), - new ProductId(Uuid::uuid7()), + new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, @@ -94,7 +94,7 @@ describe('OrderLineProduct', function (): void { // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), - new ProductId(Uuid::uuid7()), + new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, @@ -113,7 +113,7 @@ describe('OrderLineProduct', function (): void { // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), - new ProductId(Uuid::uuid7()), + new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, @@ -132,7 +132,7 @@ describe('OrderLineProduct', function (): void { // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), - new ProductId(Uuid::uuid7()), + new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, @@ -151,7 +151,7 @@ describe('OrderLineProduct', function (): void { // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), - new ProductId(Uuid::uuid7()), + new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, diff --git a/tests/Unit/Domain/Models/ValueObjects/OrderLineTest.php b/tests/Unit/Domain/Models/ValueObjects/OrderLineTest.php index be8082be..e18c659b 100644 --- a/tests/Unit/Domain/Models/ValueObjects/OrderLineTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/OrderLineTest.php @@ -13,14 +13,14 @@ use Domain\Models\ValueObjects\OrderLine; use Domain\Models\ValueObjects\OrderLineProduct; use Domain\Models\ValueObjects\ProductWeight; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('OrderLine', function (): void { function getNewOrderLineProduct(): OrderLineProduct { return new OrderLineProduct( incoId: new IncoId(1), - originalId: new ProductId(Uuid::uuid7()), + originalId: new ProductId(UuidHelper::v7()), name: 'poulet blanc', weight: new ProductWeight(200, false), brand: ProductBrand::loue, diff --git a/tests/Unit/Domain/Models/ValueObjects/OrderReferenceTest.php b/tests/Unit/Domain/Models/ValueObjects/OrderReferenceTest.php index bfb0eb79..fca35822 100644 --- a/tests/Unit/Domain/Models/ValueObjects/OrderReferenceTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/OrderReferenceTest.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects; use Domain\Models\ValueObjects\OrderReference; -use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; use Shared\Helpers\UuidHelper; @@ -17,7 +16,7 @@ describe('OrderReference', function () { it('can instantiate with a valid UUID v7', function () { // GIVEN - $uuidV7 = Uuid::uuid7(); + $uuidV7 = UuidHelper::v7(); // WHEN $vo = getNewOrderReference($uuidV7); @@ -29,7 +28,7 @@ describe('OrderReference', function () { it('can instantiate from a valid base-58 UUID v7 string', function () { // GIVEN - $uuidV7 = Uuid::uuid7(); + $uuidV7 = UuidHelper::v7(); $base58 = UuidHelper::toBase58($uuidV7); // WHEN @@ -42,7 +41,7 @@ describe('OrderReference', function () { it('can instantiate from a valid UUID v7 string via fromString', function () { // GIVEN - $uuidV7 = Uuid::uuid7(); + $uuidV7 = UuidHelper::v7(); $uuidString = $uuidV7->toString(); // WHEN @@ -55,7 +54,7 @@ describe('OrderReference', function () { it('can instantiate from a valid base-58 string via fromString', function () { // GIVEN - $uuidV7 = Uuid::uuid7(); + $uuidV7 = UuidHelper::v7(); $base58 = UuidHelper::toBase58($uuidV7); // WHEN @@ -68,7 +67,7 @@ describe('OrderReference', function () { it('throws exception if provided UUID is not v7', function () { // GIVEN - $uuidV4 = Uuid::uuid4(); + $uuidV4 = UuidHelper::v4(); // WHEN $action = fn () => getNewOrderReference($uuidV4); @@ -90,7 +89,7 @@ describe('OrderReference', function () { it('throws exception if base-58 string is not from a UUID v7', function () { // GIVEN - $uuidV4 = Uuid::uuid4(); + $uuidV4 = UuidHelper::v4(); $base58 = UuidHelper::toBase58($uuidV4); // WHEN diff --git a/tests/Unit/Domain/Models/ValueObjects/SessionIdTest.php b/tests/Unit/Domain/Models/ValueObjects/SessionIdTest.php index 45774709..659d560c 100644 --- a/tests/Unit/Domain/Models/ValueObjects/SessionIdTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/SessionIdTest.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects; use Domain\Models\ValueObjects\SessionId; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; describe('SessionId', function (): void { it('can be instantiated with a valid uuid', function (): void { // GIVEN - $uuid = Uuid::uuid7(); + $uuid = UuidHelper::v7(); // WHEN $id = new SessionId($uuid); // THEN @@ -19,7 +19,7 @@ describe('SessionId', function (): void { it('throws exception with non v7 uuid', function (): void { // GIVEN - $uuid = Uuid::uuid4(); + $uuid = UuidHelper::v4(); // WHEN $action = fn () => new SessionId($uuid); // THEN diff --git a/tests/Unit/Domain/Models/ValueObjects/ShopPickupOverrideTest.php b/tests/Unit/Domain/Models/ValueObjects/ShopPickupOverrideTest.php index 5ba7c9fe..bcbb9894 100644 --- a/tests/Unit/Domain/Models/ValueObjects/ShopPickupOverrideTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/ShopPickupOverrideTest.php @@ -10,7 +10,7 @@ use Domain\Enums\RepeatFrequency; use Domain\Models\Entities\PickupExceptionOnDate; use Domain\Models\ValueObjects\Entities\PickupExceptionId; use Domain\Models\ValueObjects\ShopPickupOverride; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; beforeEach(function (): void { $now = CarbonImmutable::parse('2026-06-15 10:00:00', 'Europe/Paris'); @@ -27,7 +27,7 @@ describe('ShopPickupOverride', function (): void { it('can instantiate correctly', function (): void { // GIVEN $exception = new PickupExceptionOnDate( - new PickupExceptionId(Uuid::uuid7()), + new PickupExceptionId(UuidHelper::v7()), CarbonImmutable::now(), 'Label', true, @@ -54,7 +54,7 @@ describe('ShopPickupOverride', function (): void { it('throws exception if orderDeadlineAt is not strictly before replacementDate', function (): void { // GIVEN $exception = new PickupExceptionOnDate( - new PickupExceptionId(Uuid::uuid7()), + new PickupExceptionId(UuidHelper::v7()), CarbonImmutable::now(), 'Label', true, @@ -79,7 +79,7 @@ describe('ShopPickupOverride', function (): void { it('correctly handles replacement and deadlines', function (): void { // GIVEN $exception = new PickupExceptionOnDate( - new PickupExceptionId(Uuid::uuid7()), + new PickupExceptionId(UuidHelper::v7()), CarbonImmutable::parse('2025-05-01'), 'Labour Day', false, diff --git a/tests/Unit/Domain/Services/BasketServiceTest.php b/tests/Unit/Domain/Services/BasketServiceTest.php index 8ec78b91..79859e5a 100644 --- a/tests/Unit/Domain/Services/BasketServiceTest.php +++ b/tests/Unit/Domain/Services/BasketServiceTest.php @@ -22,15 +22,15 @@ use Domain\Ports\Services\SessionService; use Domain\Services\BasketService; use Mockery; use Money\Money; -use Ramsey\Uuid\Uuid; use Shared\DDD\DomainEventDispatcher; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; /** @param array{id?: ProductId, qty?: int, unitPriceHt?: Money, unitDiscount?: Money} $overrides */ function makeBasketProduct(array $overrides = []): BasketProduct { return new BasketProduct( - id: $overrides['id'] ?? new ProductId(Uuid::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')), + id: $overrides['id'] ?? new ProductId(UuidHelper::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')), name: 'Poulet Rôti', qty: $overrides['qty'] ?? 1, unitPriceHt: $overrides['unitPriceHt'] ?? Money::EUR(1000), @@ -52,14 +52,14 @@ function makeBasketProduct(array $overrides = []): BasketProduct describe('BasketService', function (): void { it('adds a new product to the basket and dispatches BasketHasBeenModified', function (): void { // GIVEN - $productId = new ProductId(Uuid::uuid7()); + $productId = new ProductId(UuidHelper::v7()); $qty = 2; - $basket = new Basket(new BasketId(Uuid::uuid7())); + $basket = new Basket(new BasketId(UuidHelper::v7())); $basketProduct = makeBasketProduct(['id' => $productId, 'qty' => $qty]); $basketRepository = Mockery::mock(BasketRepository::class); $sessionService = Mockery::mock(SessionService::class); - $sessionService->shouldReceive('get')->andReturn(new SessionId(Uuid::uuid7()))->byDefault(); + $sessionService->shouldReceive('get')->andReturn(new SessionId(UuidHelper::v7()))->byDefault(); $basketRepository->shouldReceive('find')->once()->andReturn($basket); $basketRepository->shouldReceive('persist')->once()->with(Mockery::on(function (Basket $b) use ($productId) { return $b->has($productId) && $b->countItems() === 2; @@ -84,13 +84,13 @@ describe('BasketService', function (): void { it('removes a quantity from the basket and dispatches BasketHasBeenModified', function (): void { // GIVEN - $productId = new ProductId(Uuid::uuid7()); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $productId = new ProductId(UuidHelper::v7()); + $basket = new Basket(new BasketId(UuidHelper::v7())); $basket->addOrUpdate(makeBasketProduct(['id' => $productId, 'qty' => 3])); $basketRepository = Mockery::mock(BasketRepository::class); $sessionService = Mockery::mock(SessionService::class); - $sessionService->shouldReceive('get')->andReturn(new SessionId(Uuid::uuid7()))->byDefault(); + $sessionService->shouldReceive('get')->andReturn(new SessionId(UuidHelper::v7()))->byDefault(); $basketRepository->shouldReceive('find')->once()->andReturn($basket); $basketRepository->shouldReceive('persist')->once()->with(Mockery::on(function (Basket $b) use ($productId) { $items = $b->items(); @@ -117,13 +117,13 @@ describe('BasketService', function (): void { it('removes the entire line when quantity to remove equals current quantity', function (): void { // GIVEN - $productId = new ProductId(Uuid::uuid7()); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $productId = new ProductId(UuidHelper::v7()); + $basket = new Basket(new BasketId(UuidHelper::v7())); $basket->addOrUpdate(makeBasketProduct(['id' => $productId, 'qty' => 3])); $basketRepository = Mockery::mock(BasketRepository::class); $sessionService = Mockery::mock(SessionService::class); - $sessionService->shouldReceive('get')->andReturn(new SessionId(Uuid::uuid7()))->byDefault(); + $sessionService->shouldReceive('get')->andReturn(new SessionId(UuidHelper::v7()))->byDefault(); $basketRepository->shouldReceive('find')->once()->andReturn($basket); $basketRepository->shouldReceive('persist')->once()->with(Mockery::on(function (Basket $b) use ($productId) { return ! $b->has($productId); @@ -147,13 +147,13 @@ describe('BasketService', function (): void { it('removes an entire line directly via removeLine and dispatches BasketHasBeenModified', function (): void { // GIVEN - $productId = new ProductId(Uuid::uuid7()); - $basket = new Basket(new BasketId(Uuid::uuid7())); + $productId = new ProductId(UuidHelper::v7()); + $basket = new Basket(new BasketId(UuidHelper::v7())); $basket->addOrUpdate(makeBasketProduct(['id' => $productId, 'qty' => 5])); $basketRepository = Mockery::mock(BasketRepository::class); $sessionService = Mockery::mock(SessionService::class); - $sessionService->shouldReceive('get')->andReturn(new SessionId(Uuid::uuid7()))->byDefault(); + $sessionService->shouldReceive('get')->andReturn(new SessionId(UuidHelper::v7()))->byDefault(); $basketRepository->shouldReceive('find')->once()->andReturn($basket); $basketRepository->shouldReceive('persist')->once()->with(Mockery::on(function (Basket $b) use ($productId) { return ! $b->has($productId); @@ -177,13 +177,13 @@ describe('BasketService', function (): void { it('empties the basket by destroying it from repository and dispatches BasketRemoved', function (): void { // GIVEN - $basket = new Basket(new BasketId(Uuid::uuid7())); + $basket = new Basket(new BasketId(UuidHelper::v7())); /** @var BasketRepository&\Mockery\MockInterface $basketRepository */ $basketRepository = Mockery::spy(BasketRepository::class); $basketRepository->allows('find')->andReturn($basket); $sessionService = Mockery::mock(SessionService::class); - $sessionService->shouldReceive('get')->andReturn(new SessionId(Uuid::uuid7()))->byDefault(); + $sessionService->shouldReceive('get')->andReturn(new SessionId(UuidHelper::v7()))->byDefault(); $productRepository = Mockery::mock(ProductRepository::class); @@ -204,10 +204,10 @@ describe('BasketService', function (): void { it('gets the basket from repository without dispatching events', function (): void { // GIVEN - $basket = new Basket(new BasketId(Uuid::uuid7())); + $basket = new Basket(new BasketId(UuidHelper::v7())); $basketRepository = Mockery::mock(BasketRepository::class); $sessionService = Mockery::mock(SessionService::class); - $sessionService->shouldReceive('get')->andReturn(new SessionId(Uuid::uuid7()))->byDefault(); + $sessionService->shouldReceive('get')->andReturn(new SessionId(UuidHelper::v7()))->byDefault(); $basketRepository->shouldReceive('find')->once()->andReturn($basket); $productRepository = Mockery::mock(ProductRepository::class); @@ -226,7 +226,7 @@ describe('BasketService', function (): void { it('returns a new basket if not found in repository', function (): void { // GIVEN - $sessionId = new SessionId(Uuid::uuid7()); + $sessionId = new SessionId(UuidHelper::v7()); $basketRepository = Mockery::mock(BasketRepository::class); $sessionService = Mockery::mock(SessionService::class); $sessionService->shouldReceive('get')->andReturn($sessionId)->byDefault(); @@ -249,7 +249,7 @@ describe('BasketService', function (): void { it('reports whether the basket has items', function (): void { // GIVEN - $sessionId = new SessionId(Uuid::uuid7()); + $sessionId = new SessionId(UuidHelper::v7()); $nonEmpty = new Basket(new BasketId($sessionId->value), [makeBasketProduct()]); $empty = new Basket(new BasketId($sessionId->value), []); $basketRepo = Mockery::mock(BasketRepository::class); diff --git a/tests/Unit/Domain/Services/OrderServiceTest.php b/tests/Unit/Domain/Services/OrderServiceTest.php index a19ada33..58089baa 100644 --- a/tests/Unit/Domain/Services/OrderServiceTest.php +++ b/tests/Unit/Domain/Services/OrderServiceTest.php @@ -38,7 +38,6 @@ use Domain\Ports\Repositories\OrderRepository; use Domain\Services\OrderService; use Mockery; use Money\Money; -use Ramsey\Uuid\Uuid; use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; @@ -56,12 +55,12 @@ afterEach(function (): void { describe('Order Cancellation', function () { it('cancels a validated order successfully', function () { // GIVEN - $orderId = new OrderId(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); $order = new Order( id: $orderId, - shopId: new ShopId(Uuid::uuid7()), - reference: new OrderReference(Uuid::uuid7()), + shopId: new ShopId(UuidHelper::v7()), + reference: new OrderReference(UuidHelper::v7()), employee: new OrderEmployee( new Matricule('1234567'), 'Jean', @@ -87,7 +86,7 @@ describe('Order Cancellation', function () { new OrderLine( product: new OrderLineProduct( incoId: new IncoId(45), - originalId: new ProductId(Uuid::uuid7()), + originalId: new ProductId(UuidHelper::v7()), name: 'Poulet Rôti', weight: new ProductWeight(1200, false), brand: ProductBrand::marie, @@ -125,7 +124,7 @@ describe('Order Cancellation', function () { it('throws exception if order not found', function () { // GIVEN - $orderId = new OrderId(Uuid::uuid7()); + $orderId = new OrderId(UuidHelper::v7()); /** @var OrderRepository|\Mockery\MockInterface $repository */ $repository = Mockery::mock(OrderRepository::class); @@ -142,13 +141,13 @@ describe('Order Cancellation', function () { it('validates and fails pending orders using findForUpdate', function () { // GIVEN - $pendingId = new OrderId(Uuid::uuid7()); - $failedId = new OrderId(Uuid::uuid7()); + $pendingId = new OrderId(UuidHelper::v7()); + $failedId = new OrderId(UuidHelper::v7()); $makeOrderWithStatus = static fn (OrderId $id, OrderStatus $status): Order => new Order( id: $id, - shopId: new ShopId(Uuid::uuid7()), - reference: new OrderReference(Uuid::uuid7()), + shopId: new ShopId(UuidHelper::v7()), + reference: new OrderReference(UuidHelper::v7()), employee: new OrderEmployee( new Matricule('1234567'), 'Jean', @@ -174,7 +173,7 @@ describe('Order Cancellation', function () { new OrderLine( product: new OrderLineProduct( incoId: new IncoId(45), - originalId: new ProductId(Uuid::uuid7()), + originalId: new ProductId(UuidHelper::v7()), name: 'Poulet Rôti', weight: new ProductWeight(1200, false), brand: ProductBrand::marie, @@ -221,11 +220,11 @@ describe('Order Cancellation', function () { describe('Order Creation', function () { it('creates an order from a basket correctly', function () { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); $basketProduct = new BasketProduct( - id: new ProductId(Uuid::uuid7()), + id: new ProductId(UuidHelper::v7()), name: 'Poulet Rôti', qty: 2, unitPriceHt: Money::EUR(1000), @@ -250,7 +249,7 @@ describe('Order Creation', function () { ); $shopper = new Shopper( - id: new ShopperId(Uuid::uuid7()), + id: new ShopperId(UuidHelper::v7()), email: new Email('jean.dupont@example.com'), matricule: new Matricule('1234567'), nom: 'Dupont', @@ -263,7 +262,7 @@ describe('Order Creation', function () { ); $shop = new Shop( - id: new ShopId(Uuid::uuid7()), + id: new ShopId(UuidHelper::v7()), name: 'Cocotte Lyon', address: '12 rue de la Paix', postcode: '69001', @@ -330,11 +329,11 @@ describe('Order Creation', function () { it('throws exception if basket product has no incoId', function () { // GIVEN - $basketId = new BasketId(Uuid::uuid7()); + $basketId = new BasketId(UuidHelper::v7()); $basket = new Basket($basketId); $basketProduct = new BasketProduct( - id: new ProductId(Uuid::uuid7()), + id: new ProductId(UuidHelper::v7()), name: 'Poulet Rôti', qty: 2, unitPriceHt: Money::EUR(1000), @@ -355,7 +354,7 @@ describe('Order Creation', function () { $pickupTimeSlot = new PickupTimeSlot(new \DateTimeImmutable(), new \DateInterval('PT10M')); $shopper = new Shopper( - id: new ShopperId(Uuid::uuid7()), + id: new ShopperId(UuidHelper::v7()), email: new Email('a@a.com'), matricule: new Matricule('1234567'), nom: 'A', @@ -367,7 +366,7 @@ describe('Order Creation', function () { service: new ShopperServiceCode('101') ); $shop = new Shop( - id: new ShopId(Uuid::uuid7()), + id: new ShopId(UuidHelper::v7()), name: 'S', address: 'A', postcode: 'P', diff --git a/tests/Unit/Domain/Services/OrderTunnelServiceTest.php b/tests/Unit/Domain/Services/OrderTunnelServiceTest.php index 360c6b3d..d4b97612 100644 --- a/tests/Unit/Domain/Services/OrderTunnelServiceTest.php +++ b/tests/Unit/Domain/Services/OrderTunnelServiceTest.php @@ -55,15 +55,15 @@ use Domain\Services\PickupSchedulingService; use Domain\Services\ShopperService; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; use Shared\DDD\DomainEventDispatcher; +use Shared\Helpers\UuidHelper; function createTestBasket(int $qty = 0): Basket { $items = []; if ($qty > 0) { - $productId = new ProductId(Uuid::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); + $productId = new ProductId(UuidHelper::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); $basketProduct = new BasketProduct( id: $productId, name: 'Test Product', @@ -85,7 +85,7 @@ function createTestBasket(int $qty = 0): Basket $items[(string) $productId->value] = $basketProduct; } - $basketId = new BasketId(Uuid::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); + $basketId = new BasketId(UuidHelper::fromString('019e9e37-f2a1-74ef-b9c2-66d222470128')); return new Basket($basketId, $items); } @@ -96,11 +96,11 @@ function createTestBasket(int $qty = 0): Basket function createTestBuilder(bool $completed = false): OrderBuilderWithBasket { $basket = createTestBasket(1); - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $builder = OrderBuilder::fromBasket($basket, $shopperId); if ($completed) { - $shopId = new ShopId(Uuid::uuid7()); + $shopId = new ShopId(UuidHelper::v7()); $nextFriday = CarbonImmutable::now('Europe/Paris')->next(WeekDay::Friday->value)->addWeek()->startOfDay(); $timeSlot = new PickupTimeSlot($nextFriday, new \DateInterval('PT1H')); @@ -224,7 +224,7 @@ describe('OrderTunnelService', function (): void { it('denies access to BOOKING step when builder has an empty basket', function (): void { // GIVEN - $builder = OrderBuilder::fromBasket(createTestBasket(0), new ShopperId(Uuid::uuid7())); + $builder = OrderBuilder::fromBasket(createTestBasket(0), new ShopperId(UuidHelper::v7())); $orderBuilderRepository = \Mockery::mock(OrderBuilderSessionManager::class); $orderBuilderRepository->shouldReceive('get')->andReturn($builder); @@ -291,10 +291,11 @@ describe('OrderTunnelService', function (): void { it('denies access to CONFIRMATION step when builder has an empty basket', function (): void { // GIVEN - $shopId = new ShopId(Uuid::uuid7()); + $shopId = new ShopId(UuidHelper::v7()); $nextFriday = CarbonImmutable::now('Europe/Paris')->next(WeekDay::Friday->value)->addWeek()->startOfDay(); $timeSlot = new PickupTimeSlot($nextFriday, new \DateInterval('PT1H')); - $builder = OrderBuilder::fromBasket(createTestBasket(0), new ShopperId(Uuid::uuid7()))->withPickupTimeSlot($shopId, $timeSlot); + $builder = OrderBuilder::fromBasket(createTestBasket(0), new ShopperId(UuidHelper::v7())) + ->withPickupTimeSlot($shopId, $timeSlot); $orderBuilderRepository = \Mockery::mock(OrderBuilderSessionManager::class); $orderBuilderRepository->shouldReceive('get')->andReturn($builder); @@ -327,7 +328,7 @@ describe('OrderTunnelService', function (): void { it('gets shop for customer successfully', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $shopper = new Shopper( id: $shopperId, email: new Email('test@test.com'), @@ -341,7 +342,7 @@ describe('OrderTunnelService', function (): void { service: new ShopperServiceCode('101') ); - $shopId = new ShopId(Uuid::uuid7()); + $shopId = new ShopId(UuidHelper::v7()); $shop = new Shop( id: $shopId, name: 'Shop', @@ -373,7 +374,7 @@ describe('OrderTunnelService', function (): void { it('throws exception when get shop for customer fails', function (): void { // GIVEN - $shopperId = new ShopperId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); $shopperRepo = \Mockery::mock(ShopperRepository::class); $shopperRepo->shouldReceive('find')->with($shopperId)->andReturn(null); @@ -387,7 +388,7 @@ describe('OrderTunnelService', function (): void { it('gets available time slots', function (): void { // GIVEN - $shopId = new ShopId(Uuid::uuid7()); + $shopId = new ShopId(UuidHelper::v7()); $shop = new Shop($shopId, 'Shop', 'Address', '75000', 'Paris'); $pickupExceptionRepo = \Mockery::mock(PickupExceptionRepository::class); @@ -405,7 +406,7 @@ describe('OrderTunnelService', function (): void { it('initializes order from basket', function (): void { // GIVEN $basket = createTestBasket(1); - $customerId = new ShopperId(Uuid::uuid7()); + $customerId = new ShopperId(UuidHelper::v7()); /** @var OrderBuilderSessionManager&\Mockery\MockInterface $orderBuilderRepo */ $orderBuilderRepo = \Mockery::spy(OrderBuilderSessionManager::class); @@ -449,7 +450,7 @@ describe('OrderTunnelService', function (): void { it('throws exception in getBuilderFromBasketOrFail when builder has an empty basket', function (): void { // GIVEN - $builder = OrderBuilder::fromBasket(createTestBasket(0), new ShopperId(Uuid::uuid7())); + $builder = OrderBuilder::fromBasket(createTestBasket(0), new ShopperId(UuidHelper::v7())); $orderBuilderRepo = \Mockery::mock(OrderBuilderSessionManager::class); $orderBuilderRepo->shouldReceive('get')->once()->andReturn($builder); @@ -493,10 +494,10 @@ describe('OrderTunnelService', function (): void { it('throws exception in getBuilderCompletedOrFail when builder has an empty basket', function (): void { // GIVEN - $shopId = new ShopId(Uuid::uuid7()); + $shopId = new ShopId(UuidHelper::v7()); $nextFriday = CarbonImmutable::now('Europe/Paris')->next(WeekDay::Friday->value)->addWeek()->startOfDay(); $timeSlot = new PickupTimeSlot($nextFriday, new \DateInterval('PT1H')); - $builder = OrderBuilder::fromBasket(createTestBasket(0), new ShopperId(Uuid::uuid7()))->withPickupTimeSlot($shopId, $timeSlot); + $builder = OrderBuilder::fromBasket(createTestBasket(0), new ShopperId(UuidHelper::v7()))->withPickupTimeSlot($shopId, $timeSlot); $orderBuilderRepo = \Mockery::mock(OrderBuilderSessionManager::class); $orderBuilderRepo->shouldReceive('get')->once()->andReturn($builder); @@ -513,7 +514,7 @@ describe('OrderTunnelService', function (): void { it('applies time slot', function (): void { // GIVEN $builder = createTestBuilder(completed: false); - $shop = new Shop(new ShopId(Uuid::uuid7()), 'Shop', 'Address', '75000', 'Paris'); + $shop = new Shop(new ShopId(UuidHelper::v7()), 'Shop', 'Address', '75000', 'Paris'); $selectedDate = CarbonImmutable::parse('2025-01-01'); $ts1 = new PickupTimeSlot($selectedDate, new \DateInterval('PT1H')); $ts2 = new PickupTimeSlot(CarbonImmutable::parse('2025-01-02'), new \DateInterval('PT1H')); @@ -534,7 +535,7 @@ describe('OrderTunnelService', function (): void { it('returns null if no matching time slot', function (): void { // GIVEN $builder = createTestBuilder(completed: false); - $shop = new Shop(new ShopId(Uuid::uuid7()), 'Shop', 'Address', '75000', 'Paris'); + $shop = new Shop(new ShopId(UuidHelper::v7()), 'Shop', 'Address', '75000', 'Paris'); $selectedDate = CarbonImmutable::parse('2025-01-01'); $ts1 = new PickupTimeSlot(CarbonImmutable::parse('2025-01-02'), new \DateInterval('PT1H')); $availableSlots = [$ts1]; @@ -765,8 +766,8 @@ describe('OrderTunnelService', function (): void { it('throws ExpiredPickupTimeSlotException when finalizing order with an expired or unavailable pickup time slot', function (): void { // GIVEN $basket = createTestBasket(1); - $shopperId = new ShopperId(Uuid::uuid7()); - $shopId = new ShopId(Uuid::uuid7()); + $shopperId = new ShopperId(UuidHelper::v7()); + $shopId = new ShopId(UuidHelper::v7()); $expiredSlot = new PickupTimeSlot(CarbonImmutable::parse('2025-01-01'), new \DateInterval('PT1H')); $builder = OrderBuilder::fromBasket($basket, $shopperId)->withPickupTimeSlot($shopId, $expiredSlot); @@ -984,10 +985,10 @@ describe('OrderTunnelService', function (): void { it('exports, confirms and fails a pending order across split steps', function (): void { // GIVEN - $shopId = new ShopId(Uuid::uuid7()); + $shopId = new ShopId(UuidHelper::v7()); $shop = new Shop($shopId, 'Shop', 'Address', '75000', 'Paris'); $shopper = new Shopper( - id: new ShopperId(Uuid::uuid7()), + id: new ShopperId(UuidHelper::v7()), email: new Email('split@test.com'), matricule: new Matricule('1234567'), nom: 'Doe', @@ -1000,16 +1001,16 @@ describe('OrderTunnelService', function (): void { ); $basket = createTestBasket(1); $orderToOk = Order::pendingFromBasket( - new OrderId(Uuid::uuid7()), - new OrderReference(Uuid::uuid7()), + new OrderId(UuidHelper::v7()), + new OrderReference(UuidHelper::v7()), $basket, new PickupTimeSlot(CarbonImmutable::now()->next('Friday'), new \DateInterval('PT1H')), $shopper, $shop ); $orderToKo = Order::pendingFromBasket( - new OrderId(Uuid::uuid7()), - new OrderReference(Uuid::uuid7()), + new OrderId(UuidHelper::v7()), + new OrderReference(UuidHelper::v7()), $basket, new PickupTimeSlot(CarbonImmutable::now()->next('Friday'), new \DateInterval('PT1H')), $shopper, @@ -1050,7 +1051,7 @@ describe('OrderTunnelService', function (): void { it('records a tunnel attempt when initializing from basket', function (): void { // GIVEN $basket = createTestBasket(1); - $customerId = new ShopperId(Uuid::uuid7()); + $customerId = new ShopperId(UuidHelper::v7()); $recorded = false; $orderBuilderSessionManager = \Mockery::mock(OrderBuilderSessionManager::class); @@ -1078,10 +1079,10 @@ describe('OrderTunnelService', function (): void { it('marks the tunnel attempt converted when confirming a placed order', function (): void { // GIVEN - $shopId = new ShopId(Uuid::uuid7()); + $shopId = new ShopId(UuidHelper::v7()); $shop = new Shop($shopId, 'Shop', 'Address', '75000', 'Paris'); $shopper = new Shopper( - id: new ShopperId(Uuid::uuid7()), + id: new ShopperId(UuidHelper::v7()), email: new Email('convert@test.com'), matricule: new Matricule('1234567'), nom: 'Doe', @@ -1094,8 +1095,8 @@ describe('OrderTunnelService', function (): void { ); $basket = createTestBasket(1); $order = Order::pendingFromBasket( - new OrderId(Uuid::uuid7()), - new OrderReference(Uuid::uuid7()), + new OrderId(UuidHelper::v7()), + new OrderReference(UuidHelper::v7()), $basket, new PickupTimeSlot(CarbonImmutable::now()->next('Friday'), new \DateInterval('PT1H')), $shopper, diff --git a/tests/Unit/Domain/Services/PickupSchedulingServiceTest.php b/tests/Unit/Domain/Services/PickupSchedulingServiceTest.php index 9996f64e..db191a6b 100644 --- a/tests/Unit/Domain/Services/PickupSchedulingServiceTest.php +++ b/tests/Unit/Domain/Services/PickupSchedulingServiceTest.php @@ -16,12 +16,12 @@ use Domain\Models\ValueObjects\PickupWindow; use Domain\Models\ValueObjects\ShopPickupOverride; use Domain\Ports\Repositories\PickupExceptionRepository; use Domain\Services\PickupSchedulingService; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; function createTestShop(int $id = 1): Shop { return new Shop( - id: new ShopId(Uuid::uuid7()), + id: new ShopId(UuidHelper::v7()), name: 'Test Shop', address: '1 rue de Paris', postcode: '75000', @@ -314,7 +314,7 @@ describe('Pickup Scheduling Service', function (): void { $now = CarbonImmutable::parse('2026-05-04 10:00:00'); $exception1 = new PickupExceptionOnDate( - id: new PickupExceptionId(Uuid::uuid7()), + id: new PickupExceptionId(UuidHelper::v7()), date: CarbonImmutable::parse('2026-05-08'), // Friday label: 'Test 1', repeatable: false, @@ -323,7 +323,7 @@ describe('Pickup Scheduling Service', function (): void { ); $exception2 = new PickupExceptionOnDate( - id: new PickupExceptionId(Uuid::uuid7()), + id: new PickupExceptionId(UuidHelper::v7()), date: CarbonImmutable::parse('2026-05-09'), // Saturday label: 'Test 2', repeatable: false, @@ -528,7 +528,7 @@ function createExceptionPivot(string $date, ?string $replacementDate = null, ?st static $idCounter = 1; $pickupSchedulingService = new PickupSchedulingService(\Mockery::mock(PickupExceptionRepository::class)); $exception = new PickupExceptionOnDate( - id: new PickupExceptionId(Uuid::uuid7()), + id: new PickupExceptionId(UuidHelper::v7()), date: CarbonImmutable::parse($date, $pickupSchedulingService->getCutoffTimezone()), label: 'Test Exception', repeatable: false, diff --git a/tests/Unit/Domain/Services/ShopperServiceTest.php b/tests/Unit/Domain/Services/ShopperServiceTest.php index 87901734..26b5b6b0 100644 --- a/tests/Unit/Domain/Services/ShopperServiceTest.php +++ b/tests/Unit/Domain/Services/ShopperServiceTest.php @@ -19,7 +19,7 @@ use Domain\Ports\Repositories\ShopperRepository; use Domain\Ports\Repositories\ShopRepository; use Domain\Services\ShopperService; use Mockery; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; beforeEach(function (): void { $now = CarbonImmutable::parse('2026-06-15 10:00:00', 'Europe/Paris'); @@ -40,7 +40,7 @@ describe('ShopperService', function (): void { $shopperRepo = Mockery::mock(ShopperRepository::class); $service = new ShopperService($shopRepo, $shopperRepo); - $id = new ShopperId(Uuid::uuid7()); + $id = new ShopperId(UuidHelper::v7()); $shopper = new Shopper( $id, new Email('test@test.com'), @@ -69,7 +69,7 @@ describe('ShopperService', function (): void { $service = new ShopperService($shopRepo, $shopperRepo); $shopper = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@test.com'), new Matricule('1234567'), 'Nom', @@ -82,7 +82,7 @@ describe('ShopperService', function (): void { ); $shop = new Shop( - new ShopId(Uuid::uuid7()), + new ShopId(UuidHelper::v7()), 'Shop', 'Addr', '00000', @@ -104,7 +104,7 @@ describe('ShopperService', function (): void { $service = new ShopperService($shopRepo, $shopperRepo); $shopper = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@test.com'), new Matricule('1234567'), 'Nom', @@ -116,7 +116,7 @@ describe('ShopperService', function (): void { new ShopperServiceCode('101') ); - $shop = new Shop(new ShopId(Uuid::uuid7()), 'Shop', 'Addr', '00000', 'City'); + $shop = new Shop(new ShopId(UuidHelper::v7()), 'Shop', 'Addr', '00000', 'City'); $shopRepo->shouldReceive('findExceptionShopFor')->once()->with($shopper->matricule)->andReturn(null); $shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, $shopper->service)->andReturn($shop); @@ -134,7 +134,7 @@ describe('ShopperService', function (): void { $service = new ShopperService($shopRepo, $shopperRepo); $shopper = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@test.com'), new Matricule('1234567'), 'Nom', @@ -146,7 +146,7 @@ describe('ShopperService', function (): void { new ShopperServiceCode('101') ); - $shop = new Shop(new ShopId(Uuid::uuid7()), 'Shop', 'Addr', '00000', 'City'); + $shop = new Shop(new ShopId(UuidHelper::v7()), 'Shop', 'Addr', '00000', 'City'); $shopRepo->shouldReceive('findExceptionShopFor')->once()->with($shopper->matricule)->andReturn(null); $shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, $shopper->service)->andReturn(null); $shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, null)->andReturn($shop); @@ -165,7 +165,7 @@ describe('ShopperService', function (): void { $service = new ShopperService($shopRepo, $shopperRepo); $shopper = new Shopper( - new ShopperId(Uuid::uuid7()), + new ShopperId(UuidHelper::v7()), new Email('test@test.com'), new Matricule('1234567'), 'Nom', @@ -177,7 +177,7 @@ describe('ShopperService', function (): void { new ShopperServiceCode('101') ); - $shop = new Shop(new ShopId(Uuid::uuid7()), 'Shop', 'Addr', '00000', 'City'); + $shop = new Shop(new ShopId(UuidHelper::v7()), 'Shop', 'Addr', '00000', 'City'); $shopRepo->shouldReceive('findExceptionShopFor')->once()->with($shopper->matricule)->andReturn(null); $shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, $shopper->service)->andReturn(null); $shopRepo->shouldReceive('findShopForSiteAndService')->once()->with($shopper->site, null)->andReturn(null); @@ -196,7 +196,7 @@ describe('ShopperService', function (): void { $shopperRepo = Mockery::mock(ShopperRepository::class); $service = new ShopperService($shopRepo, $shopperRepo); - $id = new ShopperId(Uuid::uuid7()); + $id = new ShopperId(UuidHelper::v7()); $shopperRepo->shouldReceive('find')->once()->with($id)->andReturn(null); // WHEN @@ -212,7 +212,7 @@ describe('ShopperService', function (): void { $shopperRepo = Mockery::mock(ShopperRepository::class); $service = new ShopperService($shopRepo, $shopperRepo); - $id = new ShopperId(Uuid::uuid7()); + $id = new ShopperId(UuidHelper::v7()); $shopper = new Shopper( $id, new Email('test@test.com'), @@ -227,7 +227,7 @@ describe('ShopperService', function (): void { ); $shop = new Shop( - new ShopId(Uuid::uuid7()), + new ShopId(UuidHelper::v7()), 'Shop', 'Addr', '00000', @@ -249,7 +249,7 @@ describe('ShopperService', function (): void { $shopperRepo = Mockery::mock(ShopperRepository::class); $service = new ShopperService($shopRepo, $shopperRepo); - $id = new ShopperId(Uuid::uuid7()); + $id = new ShopperId(UuidHelper::v7()); $shopperRepo->shouldReceive('find')->once()->with($id)->andReturn(null); // WHEN @@ -265,7 +265,7 @@ describe('ShopperService', function (): void { $shopperRepo = Mockery::mock(ShopperRepository::class); $service = new ShopperService($shopRepo, $shopperRepo); - $id = new ShopperId(Uuid::uuid7()); + $id = new ShopperId(UuidHelper::v7()); $shopper = new Shopper( $id, new Email('test@test.com'), diff --git a/tests/Unit/Infra/Adapters/Serializers/BasketSerializerTest.php b/tests/Unit/Infra/Adapters/Serializers/BasketSerializerTest.php index f71ef3db..b7dcebd8 100644 --- a/tests/Unit/Infra/Adapters/Serializers/BasketSerializerTest.php +++ b/tests/Unit/Infra/Adapters/Serializers/BasketSerializerTest.php @@ -16,192 +16,194 @@ use Domain\Models\ValueObjects\IncoId; use Infrastructure\Adapters\Serializers\BasketSerializer; use Money\Currency; use Money\Money; -use Ramsey\Uuid\Uuid; +use Shared\Helpers\UuidHelper; use Uwil\Storage\Lib\ValueObjects\StorageFilePath; -it('serializes and deserializes basket correctly', function () { - // GIVEN - $serializer = new BasketSerializer(); +describe('BasketSerializer', function (): void { + it('serializes and deserializes basket correctly', function () { + // GIVEN + $serializer = new BasketSerializer(); - $basketIdStr = \Symfony\Component\Uid\Uuid::v7()->toRfc4122(); - $productIdStr = \Symfony\Component\Uid\Uuid::v7()->toRfc4122(); + $basketIdStr = UuidHelper::v7()->toString(); + $productIdStr = UuidHelper::v7()->toString(); - $basketProduct = new BasketProduct( - id: new ProductId(Uuid::fromString($productIdStr)), - name: 'Product 1', - qty: 2, - unitPriceHt: new Money(1000, new Currency('EUR')), - unitDiscount: new Money(100, new Currency('EUR')), - taxRate: TaxRate::TVA_20, - weightGrams: 500, - brand: ProductBrand::loue, - incoId: new IncoId(12345), - orderUnit: OrderUnit::PCE, - slug: 'product-1', - picture: new StorageFilePath('pic.png'), - description: 'desc', - weightVariable: true, - discountRate: DiscountRate::fromRatio(0.1), - priceKgTtc: new Money(2000, new Currency('EUR')), - options: ['color' => 'red'] - ); + $basketProduct = new BasketProduct( + id: new ProductId(UuidHelper::fromString($productIdStr)), + name: 'Product 1', + qty: 2, + unitPriceHt: new Money(1000, new Currency('EUR')), + unitDiscount: new Money(100, new Currency('EUR')), + taxRate: TaxRate::TVA_20, + weightGrams: 500, + brand: ProductBrand::loue, + incoId: new IncoId(12345), + orderUnit: OrderUnit::PCE, + slug: 'product-1', + picture: new StorageFilePath('pic.png'), + description: 'desc', + weightVariable: true, + discountRate: DiscountRate::fromRatio(0.1), + priceKgTtc: new Money(2000, new Currency('EUR')), + options: ['color' => 'red'] + ); - $basket = new Basket( - id: new BasketId(Uuid::fromString($basketIdStr)), - items: [$productIdStr => $basketProduct] - ); + $basket = new Basket( + id: new BasketId(UuidHelper::fromString($basketIdStr)), + items: [$productIdStr => $basketProduct] + ); - // WHEN - $array = $serializer->toArray($basket); - $json = json_encode($array, JSON_THROW_ON_ERROR); - /** @var array{id: string, items: array>} $array */ - $array = json_decode($json, true, 512, JSON_THROW_ON_ERROR); - $deserializedBasket = $serializer->fromArray($array); + // WHEN + $array = $serializer->toArray($basket); + $json = json_encode($array, JSON_THROW_ON_ERROR); + /** @var array{id: string, items: array>} $array */ + $array = json_decode($json, true, 512, JSON_THROW_ON_ERROR); + $deserializedBasket = $serializer->fromArray($array); - // THEN - expect($array['id'])->toBe($basketIdStr) - ->and($array['items'][0]['id'])->toBe($productIdStr) - ->and($array['items'][0]['name'])->toBe('Product 1') - ->and($array['items'][0]['taxRate'])->toBe(TaxRate::TVA_20->value) - ->and($deserializedBasket->id->value->toString())->toBe($basketIdStr) - ->and($deserializedBasket->items())->toHaveCount(1) - ->and($deserializedBasket->items()[$productIdStr]->name)->toBe('Product 1') - ->and($deserializedBasket->items()[$productIdStr]->weightVariable)->toBeTrue() - ->and($deserializedBasket->items()[$productIdStr]->options)->toBe(['color' => 'red']) - ->and($array['items'][0]['discountRateBp'])->toBe(1000) - ->and($deserializedBasket->items()[$productIdStr]->discountRate->basisPoints())->toBe(1000); -}); + // THEN + expect($array['id'])->toBe($basketIdStr) + ->and($array['items'][0]['id'])->toBe($productIdStr) + ->and($array['items'][0]['name'])->toBe('Product 1') + ->and($array['items'][0]['taxRate'])->toBe(TaxRate::TVA_20->value) + ->and($deserializedBasket->id->value->toString())->toBe($basketIdStr) + ->and($deserializedBasket->items())->toHaveCount(1) + ->and($deserializedBasket->items()[$productIdStr]->name)->toBe('Product 1') + ->and($deserializedBasket->items()[$productIdStr]->weightVariable)->toBeTrue() + ->and($deserializedBasket->items()[$productIdStr]->options)->toBe(['color' => 'red']) + ->and($array['items'][0]['discountRateBp'])->toBe(1000) + ->and($deserializedBasket->items()[$productIdStr]->discountRate->basisPoints())->toBe(1000); + }); -it('hydrates the discount rate from the legacy float ratio stored in older sessions', function (float $legacyRatio, int $expectedBasisPoints) { - // GIVEN - $serializer = new BasketSerializer(); - $productIdStr = \Symfony\Component\Uid\Uuid::v7()->toRfc4122(); - $data = [ - 'id' => \Symfony\Component\Uid\Uuid::v7()->toRfc4122(), - 'items' => [ - [ - 'id' => $productIdStr, - 'name' => 'Test', - 'qty' => 1, - 'unitPriceHt' => ['amount' => 1000, 'currency' => 'EUR'], - 'unitDiscount' => ['amount' => 100, 'currency' => 'EUR'], - 'taxRate' => TaxRate::TVA_20->value, - 'weightGrams' => 500, - 'orderUnit' => OrderUnit::PCE->value, - 'slug' => 'test', - 'weightVariable' => false, - 'discountRate' => $legacyRatio, - 'priceKgTtc' => ['amount' => 2000, 'currency' => 'EUR'], + it('hydrates the discount rate from the legacy float ratio stored in older sessions', function (float $legacyRatio, int $expectedBasisPoints) { + // GIVEN + $serializer = new BasketSerializer(); + $productIdStr = UuidHelper::v7()->toString(); + $data = [ + 'id' => UuidHelper::v7()->toString(), + 'items' => [ + [ + 'id' => $productIdStr, + 'name' => 'Test', + 'qty' => 1, + 'unitPriceHt' => ['amount' => 1000, 'currency' => 'EUR'], + 'unitDiscount' => ['amount' => 100, 'currency' => 'EUR'], + 'taxRate' => TaxRate::TVA_20->value, + 'weightGrams' => 500, + 'orderUnit' => OrderUnit::PCE->value, + 'slug' => 'test', + 'weightVariable' => false, + 'discountRate' => $legacyRatio, + 'priceKgTtc' => ['amount' => 2000, 'currency' => 'EUR'], + ], ], - ], - ]; + ]; - // WHEN - $basket = $serializer->fromArray($data); + // WHEN + $basket = $serializer->fromArray($data); - // THEN - expect($basket->items()[$productIdStr]->discountRate->basisPoints())->toBe($expectedBasisPoints); -})->with([ - 'regular ratio' => [0.15, 1500], - 'no discount' => [0.0, 0], - 'out of range value is clamped' => [20.0, 10000], -]); + // THEN + expect($basket->items()[$productIdStr]->discountRate->basisPoints())->toBe($expectedBasisPoints); + })->with([ + 'regular ratio' => [0.15, 1500], + 'no discount' => [0.0, 0], + 'out of range value is clamped' => [20.0, 10000], + ]); -it('throws exception if currency is missing during deserialization', function () { - // GIVEN - $serializer = new BasketSerializer(); - $productIdStr = \Symfony\Component\Uid\Uuid::v7()->toRfc4122(); - $data = [ - 'id' => \Symfony\Component\Uid\Uuid::v7()->toRfc4122(), - 'items' => [ - [ - 'id' => $productIdStr, - 'name' => 'Test', - 'qty' => 1, - 'unitPriceHt' => ['amount' => 1000, 'currency' => ''], - 'unitDiscount' => ['amount' => 100, 'currency' => 'EUR'], - 'taxRate' => TaxRate::TVA_20->value, - 'weightGrams' => 500, - 'orderUnit' => OrderUnit::PCE->value, - 'slug' => 'test', - 'weightVariable' => false, - 'priceKgTtc' => ['amount' => 2000, 'currency' => 'EUR'], + it('throws exception if currency is missing during deserialization', function () { + // GIVEN + $serializer = new BasketSerializer(); + $productIdStr = UuidHelper::v7()->toString(); + $data = [ + 'id' => UuidHelper::v7()->toString(), + 'items' => [ + [ + 'id' => $productIdStr, + 'name' => 'Test', + 'qty' => 1, + 'unitPriceHt' => ['amount' => 1000, 'currency' => ''], + 'unitDiscount' => ['amount' => 100, 'currency' => 'EUR'], + 'taxRate' => TaxRate::TVA_20->value, + 'weightGrams' => 500, + 'orderUnit' => OrderUnit::PCE->value, + 'slug' => 'test', + 'weightVariable' => false, + 'priceKgTtc' => ['amount' => 2000, 'currency' => 'EUR'], + ], ], - ], - ]; + ]; - // WHEN - $action = fn () => $serializer->fromArray($data); + // WHEN + $action = fn () => $serializer->fromArray($data); - // THEN - expect($action)->toThrow( - \DomainException::class, - 'Currency is required for unitPriceHt of item with id ' . $productIdStr - ); -}); + // THEN + expect($action)->toThrow( + \DomainException::class, + 'Currency is required for unitPriceHt of item with id ' . $productIdStr + ); + }); -it('throws exception if currency is missing for unitDiscount', function () { - // GIVEN - $serializer = new BasketSerializer(); - $productIdStr = \Symfony\Component\Uid\Uuid::v7()->toRfc4122(); - $data = [ - 'id' => \Symfony\Component\Uid\Uuid::v7()->toRfc4122(), - 'items' => [ - [ - 'id' => $productIdStr, - 'name' => 'Test', - 'qty' => 1, - 'unitPriceHt' => ['amount' => 1000, 'currency' => 'EUR'], - 'unitDiscount' => ['amount' => 100, 'currency' => ''], - 'taxRate' => TaxRate::TVA_20->value, - 'weightGrams' => 500, - 'orderUnit' => OrderUnit::PCE->value, - 'slug' => 'test', - 'weightVariable' => false, - 'priceKgTtc' => ['amount' => 2000, 'currency' => 'EUR'], + it('throws exception if currency is missing for unitDiscount', function () { + // GIVEN + $serializer = new BasketSerializer(); + $productIdStr = UuidHelper::v7()->toString(); + $data = [ + 'id' => UuidHelper::v7()->toString(), + 'items' => [ + [ + 'id' => $productIdStr, + 'name' => 'Test', + 'qty' => 1, + 'unitPriceHt' => ['amount' => 1000, 'currency' => 'EUR'], + 'unitDiscount' => ['amount' => 100, 'currency' => ''], + 'taxRate' => TaxRate::TVA_20->value, + 'weightGrams' => 500, + 'orderUnit' => OrderUnit::PCE->value, + 'slug' => 'test', + 'weightVariable' => false, + 'priceKgTtc' => ['amount' => 2000, 'currency' => 'EUR'], + ], ], - ], - ]; + ]; - // WHEN - $action = fn () => $serializer->fromArray($data); + // WHEN + $action = fn () => $serializer->fromArray($data); - // THEN - expect($action)->toThrow( - \DomainException::class, - 'Currency is required for unitDiscount of item with id ' . $productIdStr - ); -}); + // THEN + expect($action)->toThrow( + \DomainException::class, + 'Currency is required for unitDiscount of item with id ' . $productIdStr + ); + }); -it('throws exception if currency is missing for priceKgTtc', function () { - // GIVEN - $serializer = new BasketSerializer(); - $productIdStr = \Symfony\Component\Uid\Uuid::v7()->toRfc4122(); - $data = [ - 'id' => \Symfony\Component\Uid\Uuid::v7()->toRfc4122(), - 'items' => [ - [ - 'id' => $productIdStr, - 'name' => 'Test', - 'qty' => 1, - 'unitPriceHt' => ['amount' => 1000, 'currency' => 'EUR'], - 'unitDiscount' => ['amount' => 100, 'currency' => 'EUR'], - 'taxRate' => TaxRate::TVA_20->value, - 'weightGrams' => 500, - 'orderUnit' => OrderUnit::PCE->value, - 'slug' => 'test', - 'weightVariable' => false, - 'priceKgTtc' => ['amount' => 2000, 'currency' => ''], + it('throws exception if currency is missing for priceKgTtc', function () { + // GIVEN + $serializer = new BasketSerializer(); + $productIdStr = UuidHelper::v7()->toString(); + $data = [ + 'id' => UuidHelper::v7()->toString(), + 'items' => [ + [ + 'id' => $productIdStr, + 'name' => 'Test', + 'qty' => 1, + 'unitPriceHt' => ['amount' => 1000, 'currency' => 'EUR'], + 'unitDiscount' => ['amount' => 100, 'currency' => 'EUR'], + 'taxRate' => TaxRate::TVA_20->value, + 'weightGrams' => 500, + 'orderUnit' => OrderUnit::PCE->value, + 'slug' => 'test', + 'weightVariable' => false, + 'priceKgTtc' => ['amount' => 2000, 'currency' => ''], + ], ], - ], - ]; + ]; - // WHEN - $action = fn () => $serializer->fromArray($data); + // WHEN + $action = fn () => $serializer->fromArray($data); - // THEN - expect($action)->toThrow( - \DomainException::class, - 'Currency is required for priceKgTtc of item with id ' . $productIdStr - ); + // THEN + expect($action)->toThrow( + \DomainException::class, + 'Currency is required for priceKgTtc of item with id ' . $productIdStr + ); + }); });