diff --git a/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php b/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php index 8173a078..efba6867 100644 --- a/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Bo/OrdersControllerTest.php @@ -60,7 +60,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2500, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000101'), 'Alice', 'Smith', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000101'), + 'Alice', + 'Smith', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); @@ -87,7 +94,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2500, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule((string) (1000100 + $i)), 'Alice', 'Smith', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule((string) (1000100 + $i)), + 'Alice', + 'Smith', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); @@ -117,7 +131,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => $reference, 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1500, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000102'), 'Bob', 'Jones', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000102'), + 'Bob', + 'Jones', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); @@ -145,7 +166,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000198'), 'Old', 'Order', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000198'), + 'Old', + 'Order', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->addDays(7)->toDateString(), ]); @@ -155,7 +183,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000199'), 'New', 'Order', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000199'), + 'New', + 'Order', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->addDays(7)->toDateString(), ]); @@ -181,7 +216,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(3000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000103'), 'Charlie', 'Brown', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000103'), + 'Charlie', + 'Brown', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->addDays(7)->toDateString(), ]); @@ -191,7 +233,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(4000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000104'), 'Past', 'Order', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000104'), + 'Past', + 'Order', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); @@ -241,7 +290,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(4000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000999'), 'Jean', 'Dupont', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000999'), + 'Jean', + 'Dupont', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); @@ -265,7 +321,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(2000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000104'), 'David', 'Clark', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000104'), + 'David', + 'Clark', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); @@ -304,7 +367,14 @@ describe('Bo\OrdersController', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::CANCELED->value, 'total' => new Money(2000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000105'), 'Eve', 'Stone', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000105'), + 'Eve', + 'Stone', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); diff --git a/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php b/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php index 1729e719..0bbd1288 100644 --- a/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Fo/Customers/OrderControllerTest.php @@ -141,7 +141,14 @@ describe('OrderController', function () { 'reference' => $reference, 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(5000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('8888001'), 'Jean', 'Dupont', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('8888001'), + 'Jean', + 'Dupont', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); @@ -183,7 +190,10 @@ describe('OrderController', function () { $first = $orders->items()[0] ?? null; - return is_object($first) && property_exists($first, 'reference') && ($first->reference instanceof \Stringable || is_string($first->reference)) && (string) $first->reference === $ref; + return is_object($first) + && property_exists($first, 'reference') + && ($first->reference instanceof \Stringable || is_string($first->reference)) + && (string) $first->reference === $ref; }); }); @@ -228,7 +238,14 @@ describe('OrderController', function () { 'reference' => $reference, 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(5000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('8888002'), 'Paul', 'Martin', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('8888002'), + 'Paul', + 'Martin', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); diff --git a/tests/Feature/App/Http/Middleware/EnsureCustomerEmailIsVerifiedTest.php b/tests/Feature/App/Http/Middleware/EnsureCustomerEmailIsVerifiedTest.php index 87cdc285..7d76b095 100644 --- a/tests/Feature/App/Http/Middleware/EnsureCustomerEmailIsVerifiedTest.php +++ b/tests/Feature/App/Http/Middleware/EnsureCustomerEmailIsVerifiedTest.php @@ -28,7 +28,9 @@ describe('EnsureCustomerEmailIsVerified', function () { $request = Request::create('/some-url', 'GET'); URL::shouldReceive('route')->with('fo.auth.verification.notice')->andReturn('http://localhost/verification-notice'); - Redirect::shouldReceive('guest')->with('http://localhost/verification-notice')->andReturn(new RedirectResponse('http://localhost/verification-notice')); + Redirect::shouldReceive('guest') + ->with('http://localhost/verification-notice') + ->andReturn(new RedirectResponse('http://localhost/verification-notice')); // WHEN $response = $middleware->handle($request, function ($req) { diff --git a/tests/Feature/App/Http/Requests/Basket/AddBasketRequestTest.php b/tests/Feature/App/Http/Requests/Basket/AddBasketRequestTest.php index 3410854e..9f4dd9b1 100644 --- a/tests/Feature/App/Http/Requests/Basket/AddBasketRequestTest.php +++ b/tests/Feature/App/Http/Requests/Basket/AddBasketRequestTest.php @@ -42,7 +42,13 @@ function makeAddBasketRequest(): AddBasketRequest describe('AddBasketRequest', function () { it('authorizes when product exists and gate allows', function () { // GIVEN - $range = Range::query()->first() ?? Range::query()->forceCreate(['name' => 'Test', 'slug' => 'test', 'order' => 1, 'picture_alt' => '', 'picture_title' => '']); + $range = Range::query()->first() ?? Range::query()->forceCreate([ + 'name' => 'Test', + 'slug' => 'test', + 'order' => 1, + 'picture_alt' => '', + 'picture_title' => '', + ]); $product = Product::query()->forceCreate([ 'id' => Uuid::uuid7()->toString(), 'name' => 'Test', @@ -92,7 +98,13 @@ describe('AddBasketRequest', function () { it('does not authorize when gate denies', function () { // GIVEN - $range = Range::query()->first() ?? Range::query()->forceCreate(['name' => 'Test', 'slug' => 'test', 'order' => 1, 'picture_alt' => '', 'picture_title' => '']); + $range = Range::query()->first() ?? Range::query()->forceCreate([ + 'name' => 'Test', + 'slug' => 'test', + 'order' => 1, + 'picture_alt' => '', + 'picture_title' => '', + ]); $product = Product::query()->forceCreate([ 'id' => Uuid::uuid7()->toString(), 'name' => 'Test', @@ -130,7 +142,13 @@ describe('AddBasketRequest', function () { it('validates correct rules', function () { // GIVEN - $range = Range::query()->first() ?? Range::query()->forceCreate(['name' => 'Test', 'slug' => 'test', 'order' => 1, 'picture_alt' => '', 'picture_title' => '']); + $range = Range::query()->first() ?? Range::query()->forceCreate([ + 'name' => 'Test', + 'slug' => 'test', + 'order' => 1, + 'picture_alt' => '', + 'picture_title' => '', + ]); $product = Product::query()->forceCreate([ 'id' => Uuid::uuid7()->toString(), 'name' => 'Test', diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Products/CreateProductTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Products/CreateProductTest.php index 1f406510..a8df85d1 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Products/CreateProductTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Products/CreateProductTest.php @@ -196,11 +196,17 @@ describe('CreateProduct action', function (): void { ->andReturnTrue(); $storage->shouldReceive('fileExistsOnDisk') ->once() - ->with(\Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'products/orphan-large.jpg'), $disk->disk) + ->with( + \Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'products/orphan-large.jpg'), + $disk->disk, + ) ->andReturnTrue(); $storage->shouldReceive('removeFromDisk') ->once() - ->with(\Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'products/orphan-large.jpg'), $disk->disk) + ->with( + \Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'products/orphan-large.jpg'), + $disk->disk, + ) ->andReturnTrue(); $action = new CreateProduct( diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Ranges/CreateRangeTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Ranges/CreateRangeTest.php index b5f472d6..15d128cf 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Ranges/CreateRangeTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Ranges/CreateRangeTest.php @@ -99,11 +99,17 @@ describe('CreateRange action', function () { ->andReturn(new StorageFilePath('media/orphan-create-range.jpg')); $storage->shouldReceive('fileExistsOnDisk') ->once() - ->with(\Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'media/orphan-create-range.jpg'), $disk->disk) + ->with( + \Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'media/orphan-create-range.jpg'), + $disk->disk, + ) ->andReturnTrue(); $storage->shouldReceive('removeFromDisk') ->once() - ->with(\Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'media/orphan-create-range.jpg'), $disk->disk) + ->with( + \Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'media/orphan-create-range.jpg'), + $disk->disk, + ) ->andReturnTrue(); $action = new CreateRange( diff --git a/tests/Integration/WithApp/App/Cqs/Actions/Ranges/UpdateRangeTest.php b/tests/Integration/WithApp/App/Cqs/Actions/Ranges/UpdateRangeTest.php index 0c769422..6756cdfa 100644 --- a/tests/Integration/WithApp/App/Cqs/Actions/Ranges/UpdateRangeTest.php +++ b/tests/Integration/WithApp/App/Cqs/Actions/Ranges/UpdateRangeTest.php @@ -156,11 +156,17 @@ describe('UpdateRange action', function () { $storage->shouldReceive('storeFileOntoDisk')->once()->andReturn($newPicture); $storage->shouldReceive('fileExistsOnDisk') ->once() - ->with(\Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'media/orphan-new-range.jpg'), $disk->disk) + ->with( + \Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'media/orphan-new-range.jpg'), + $disk->disk, + ) ->andReturnTrue(); $storage->shouldReceive('removeFromDisk') ->once() - ->with(\Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'media/orphan-new-range.jpg'), $disk->disk) + ->with( + \Mockery::on(static fn (mixed $p): bool => $p instanceof StorageFilePath && $p->value === 'media/orphan-new-range.jpg'), + $disk->disk, + ) ->andReturnTrue(); $action = new UpdateRange( diff --git a/tests/Integration/WithApp/App/Dto/OrderLineDtoTest.php b/tests/Integration/WithApp/App/Dto/OrderLineDtoTest.php index e3743241..1f0107c3 100644 --- a/tests/Integration/WithApp/App/Dto/OrderLineDtoTest.php +++ b/tests/Integration/WithApp/App/Dto/OrderLineDtoTest.php @@ -52,7 +52,14 @@ describe('OrderLineDto Integration', function (): void { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => Money::EUR(4154), - 'employee' => new OrderEmployee(new Matricule('8888001'), 'Jean', 'Dupont', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('8888001'), + 'Jean', + 'Dupont', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); diff --git a/tests/Integration/WithApp/App/Services/ActionExecutorServiceTest.php b/tests/Integration/WithApp/App/Services/ActionExecutorServiceTest.php index 4026cea5..a3922c21 100644 --- a/tests/Integration/WithApp/App/Services/ActionExecutorServiceTest.php +++ b/tests/Integration/WithApp/App/Services/ActionExecutorServiceTest.php @@ -113,26 +113,26 @@ describe('ActionExecutorService', function (): void { $store = new ArrayStore(); $innerLock = new LaravelCacheLock(new Repository($store)); $initialLevel = DB::transactionLevel(); - $levelAtAcquire = null; - $levelInsideAction = null; - $lockHeldInsideAction = false; - $levelAfterCommit = null; - $lockHeldAfterCommit = false; - $capturedKey = null; - $capturedTtl = null; - $capturedWait = null; + $lvl1 = null; + $lvl2 = null; + $held2 = false; + $lvl3 = null; + $held3 = false; + $key = null; + $ttl = null; + $wait = null; - $recordingLock = new class ($innerLock, $store, $levelAtAcquire, $levelAfterCommit, $lockHeldAfterCommit, $capturedKey, $capturedTtl, $capturedWait) implements Lock + $recordingLock = new class ($innerLock, $store, $lvl1, $lvl3, $held3, $key, $ttl, $wait) implements Lock { public function __construct( private readonly Lock $inner, private readonly ArrayStore $store, - public ?int &$levelAtAcquire, - public ?int &$levelAfterCommit, - public bool &$lockHeldAfterCommit, - public ?string &$capturedKey, - public ?int &$capturedTtl, - public ?int &$capturedWait, + public ?int &$lvl1, + public ?int &$lvl3, + public bool &$held3, + public ?string &$key, + public ?int &$ttl, + public ?int &$wait, ) { } @@ -143,18 +143,18 @@ describe('ActionExecutorService', function (): void { int $ttlSeconds = 30, int $waitSeconds = 10, ): mixed { - $this->capturedKey = $key; - $this->capturedTtl = $ttlSeconds; - $this->capturedWait = $waitSeconds; - $this->levelAtAcquire = DB::transactionLevel(); + $this->key = $key; + $this->ttl = $ttlSeconds; + $this->wait = $waitSeconds; + $this->lvl1 = DB::transactionLevel(); return $this->inner->synchronize( key: $key, callback: function () use ($callback, $key, $ttlSeconds): mixed { $result = $callback(); - $this->levelAfterCommit = DB::transactionLevel(); - $this->lockHeldAfterCommit = ! $this->store->lock($key, $ttlSeconds)->get(); + $this->lvl3 = DB::transactionLevel(); + $this->held3 = ! $this->store->lock($key, $ttlSeconds)->get(); return $result; }, @@ -164,12 +164,12 @@ describe('ActionExecutorService', function (): void { } }; - $action = new #[Locked(ttlSeconds: 45, waitSeconds: 7)] class ($store, $levelInsideAction, $lockHeldInsideAction) implements Action, ProvidesLockKey + $action = new #[Locked(ttlSeconds: 45, waitSeconds: 7)] class ($store, $lvl2, $held2) implements Action, ProvidesLockKey { public function __construct( private readonly ArrayStore $store, - public ?int &$levelInsideAction, - public bool &$lockHeldInsideAction, + public ?int &$lvl2, + public bool &$held2, ) { } @@ -182,8 +182,8 @@ describe('ActionExecutorService', function (): void { #[\Override] public function __invoke(ActionInput $input): string { - $this->levelInsideAction = DB::transactionLevel(); - $this->lockHeldInsideAction = ! $this->store->lock('test:lock:order', 45)->get(); + $this->lvl2 = DB::transactionLevel(); + $this->held2 = ! $this->store->lock('test:lock:order', 45)->get(); return 'committed'; } @@ -200,14 +200,14 @@ describe('ActionExecutorService', function (): void { // THEN expect($result)->toBe('committed') - ->and($capturedKey)->toBe('test:lock:order') - ->and($capturedTtl)->toBe(45) - ->and($capturedWait)->toBe(7) - ->and($levelAtAcquire)->toBe($initialLevel) - ->and($levelInsideAction)->toBe($initialLevel + 1) - ->and($lockHeldInsideAction)->toBeTrue() - ->and($levelAfterCommit)->toBe($initialLevel) - ->and($lockHeldAfterCommit)->toBeTrue() + ->and($key)->toBe('test:lock:order') + ->and($ttl)->toBe(45) + ->and($wait)->toBe(7) + ->and($lvl1)->toBe($initialLevel) + ->and($lvl2)->toBe($initialLevel + 1) + ->and($held2)->toBeTrue() + ->and($lvl3)->toBe($initialLevel) + ->and($held3)->toBeTrue() ->and($store->lock('test:lock:order', 45)->get())->toBeTrue(); }); @@ -696,13 +696,13 @@ describe('ActionExecutorService', function (): void { $eventDispatcher->shouldReceive('discard')->once(); $eventDispatcher->shouldNotReceive('flush'); - $onSuccessCalled = false; - $lockReleasedInHook = false; - $action = new #[Locked(key: 'test:locked:failure')] class ($onSuccessCalled, $lockReleasedInHook, $store) implements Action, HandlesFailure, HandlesSuccess + $ok = false; + $free = false; + $action = new #[Locked(key: 'test:locked:failure')] class ($ok, $free, $store) implements Action, HandlesFailure, HandlesSuccess { public function __construct( - public bool &$onSuccessCalled, - public bool &$lockReleasedInHook, + public bool &$ok, + public bool &$free, private readonly ArrayStore $store, ) { } @@ -722,9 +722,9 @@ describe('ActionExecutorService', function (): void { public function onFailure(ActionInput $input, \Throwable $exception): void { $lock = $this->store->lock('test:locked:failure', 30); - $this->lockReleasedInHook = (bool) $lock->get(); + $this->free = (bool) $lock->get(); - if ($this->lockReleasedInHook) { + if ($this->free) { $lock->release(); } } @@ -732,7 +732,7 @@ describe('ActionExecutorService', function (): void { #[\Override] public function onSuccess(ActionInput $input, mixed $result): void { - $this->onSuccessCalled = true; + $this->ok = true; } }; @@ -747,8 +747,8 @@ describe('ActionExecutorService', function (): void { ->toThrow(\DomainException::class, 'Locked domain failure'); expect(Tag::query()->where('label', 'Locked rollback test')->exists())->toBeFalse() - ->and($onSuccessCalled)->toBeFalse() - ->and($lockReleasedInHook)->toBeTrue() + ->and($ok)->toBeFalse() + ->and($free)->toBeTrue() ->and($store->lock('test:locked:failure', 30)->get())->toBeTrue(); }); @@ -818,11 +818,11 @@ describe('ActionExecutorService', function (): void { $eventDispatcher->shouldReceive('flush')->once()->ordered(); $eventDispatcher->shouldReceive('dispatch')->once()->with($postHookEvent)->ordered(); - $txLevelInsideAction = null; - $action = new #[WithoutTransaction] class ($txLevelInsideAction, $postHookEvent, $eventDispatcher) implements Action, HandlesSuccess + $txLevel = null; + $action = new #[WithoutTransaction] class ($txLevel, $postHookEvent, $eventDispatcher) implements Action, HandlesSuccess { public function __construct( - public ?int &$txLevelInsideAction, + public ?int &$txLevel, private readonly Event $event, private readonly LaravelDomainEventDispatcher $dispatcher, ) { @@ -831,7 +831,7 @@ describe('ActionExecutorService', function (): void { #[\Override] public function __invoke(ActionInput $input): string { - $this->txLevelInsideAction = DB::transactionLevel(); + $this->txLevel = DB::transactionLevel(); return 'exported'; } @@ -855,6 +855,6 @@ describe('ActionExecutorService', function (): void { // THEN expect($result)->toBe('exported') - ->and($txLevelInsideAction)->toBe($baseTx); + ->and($txLevel)->toBe($baseTx); }); }); diff --git a/tests/Integration/WithApp/App/Services/OrderOwnershipServiceTest.php b/tests/Integration/WithApp/App/Services/OrderOwnershipServiceTest.php index 87981f17..0592e1f2 100644 --- a/tests/Integration/WithApp/App/Services/OrderOwnershipServiceTest.php +++ b/tests/Integration/WithApp/App/Services/OrderOwnershipServiceTest.php @@ -68,7 +68,14 @@ describe('OrderOwnershipService', function () { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000301'), 'John', 'Doe', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000301'), + 'John', + 'Doe', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Name', 'Addr', '00000', 'City'), ]); @@ -108,7 +115,14 @@ describe('OrderOwnershipService', function () { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000999'), 'Other', 'Person', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000999'), + 'Other', + 'Person', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Name', 'Addr', '00000', 'City'), ]); @@ -134,7 +148,14 @@ describe('OrderOwnershipService', function () { 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => new Money(1000, new Currency('EUR')), - 'employee' => new OrderEmployee(new Matricule('1000999'), 'Other', 'Person', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), + 'employee' => new OrderEmployee( + new Matricule('1000999'), + 'Other', + 'Person', + new ShopperEstablishmentCode('FAC01'), + new ShopperSiteCode('SITE'), + new ShopperServiceCode('101'), + ), 'delivery_address' => new DeliveryAddress('Name', 'Addr', '00000', 'City'), ]); diff --git a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentPickupExceptionRepositoryTest.php b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentPickupExceptionRepositoryTest.php index 4e316351..efaa9bc4 100644 --- a/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentPickupExceptionRepositoryTest.php +++ b/tests/Integration/WithApp/Infra/Adapters/Repositories/EloquentPickupExceptionRepositoryTest.php @@ -16,7 +16,13 @@ use Ramsey\Uuid\Uuid; 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']); + $shop = Shop::query()->forceCreate([ + 'id' => $shopUuid->toString(), + 'name' => 'Shop 1', + 'postcode' => '75000', + 'city' => 'Paris', + 'address' => 'Addr', + ]); $exUuid = Uuid::uuid7(); $ex1 = PickupException::query()->forceCreate([ @@ -75,7 +81,13 @@ it('retrieves all exceptions', function () { 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']); + $shop = Shop::query()->forceCreate([ + 'id' => $shopUuid->toString(), + 'name' => 'Shop 1', + 'postcode' => '75000', + 'city' => 'Paris', + 'address' => 'Addr', + ]); $exUuid = Uuid::uuid7(); $ex1 = PickupException::query()->forceCreate([ diff --git a/tests/Unit/App/Cqs/Actions/Orders/PlacePendingOrderTest.php b/tests/Unit/App/Cqs/Actions/Orders/PlacePendingOrderTest.php index 73d40df6..6e85b58b 100644 --- a/tests/Unit/App/Cqs/Actions/Orders/PlacePendingOrderTest.php +++ b/tests/Unit/App/Cqs/Actions/Orders/PlacePendingOrderTest.php @@ -159,7 +159,7 @@ describe('PlacePendingOrder', function (): void { ], ]); - it('persists refreshed basket and returns basketPriceChanged output when placePendingOrder throws BasketPriceChangedException', function (): void { + it('persists refreshed basket and returns basketPriceChanged when BasketPriceChangedException is thrown', function (): void { // GIVEN $input = new PlacePendingOrderInput(); $builder = \Mockery::mock(OrderBuilderCompleted::class); diff --git a/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php b/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php index fa95f53e..d0ef4c7a 100644 --- a/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php +++ b/tests/Unit/Domain/Events/AnOrderHasBeenPlacedTest.php @@ -28,7 +28,14 @@ describe('AnOrderHasBeenPlaced', function () { $reference = new OrderReference(Uuid::uuid7()); $totalTtc = new Money(1000, new Currency('EUR')); $matricule = new Matricule('1234567'); - $employee = new OrderEmployee($matricule, 'John', 'Doe', new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITEA'), new ShopperServiceCode('101')); + $employee = new OrderEmployee( + $matricule, + 'John', + 'Doe', + new ShopperEstablishmentCode('ETAB01'), + new ShopperSiteCode('SITEA'), + new ShopperServiceCode('101'), + ); $shop = new OrderPlacedShop('Shop', 'Address', '12345', 'City'); $pickupDay = new \DateTimeImmutable(); $lines = [ @@ -50,7 +57,14 @@ describe('AnOrderHasBeenPlaced', function () { $reference = new OrderReference(Uuid::uuid7()); $totalTtc = new Money(1000, new Currency('EUR')); $matricule = new Matricule('1234567'); - $employee = new OrderEmployee($matricule, 'John', 'Doe', new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITEA'), new ShopperServiceCode('101')); + $employee = new OrderEmployee( + $matricule, + 'John', + 'Doe', + new ShopperEstablishmentCode('ETAB01'), + new ShopperSiteCode('SITEA'), + new ShopperServiceCode('101'), + ); $shop = new OrderPlacedShop('Shop', 'Address', '12345', 'City'); $pickupDay = new \DateTimeImmutable(); $lines = []; diff --git a/tests/Unit/Domain/Models/ValueObjects/OrderLineProductTest.php b/tests/Unit/Domain/Models/ValueObjects/OrderLineProductTest.php index 35cc5a57..3d262ae6 100644 --- a/tests/Unit/Domain/Models/ValueObjects/OrderLineProductTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/OrderLineProductTest.php @@ -54,7 +54,18 @@ describe('OrderLineProduct', function (): void { it('throws exception if name is empty', function (): void { // GIVEN // WHEN - $action = fn () => new OrderLineProduct(new IncoId(1), new ProductId(Uuid::uuid7()), '', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(100), Money::EUR(100), TaxRate::TVA_5_5); + $action = fn () => new OrderLineProduct( + new IncoId(1), + new ProductId(Uuid::uuid7()), + '', + new ProductWeight(1, false), + ProductBrand::marie, + OrderUnit::KGM, + Money::EUR(100), + Money::EUR(100), + Money::EUR(100), + TaxRate::TVA_5_5, + ); // THEN expect($action)->toThrow(\DomainException::class, 'Product name cannot be empty'); }); @@ -62,7 +73,18 @@ describe('OrderLineProduct', function (): void { it('throws exception if price is negative', function (): void { // GIVEN // WHEN - $action = fn () => new OrderLineProduct(new IncoId(1), new ProductId(Uuid::uuid7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(-100), Money::EUR(100), Money::EUR(100), TaxRate::TVA_5_5); + $action = fn () => new OrderLineProduct( + new IncoId(1), + new ProductId(Uuid::uuid7()), + 'Name', + new ProductWeight(1, false), + ProductBrand::marie, + OrderUnit::KGM, + Money::EUR(-100), + Money::EUR(100), + Money::EUR(100), + TaxRate::TVA_5_5, + ); // THEN expect($action)->toThrow(\DomainException::class, 'Product price cannot be negative'); }); @@ -70,7 +92,18 @@ describe('OrderLineProduct', function (): void { it('throws exception if discounted price is negative', function (): void { // GIVEN // WHEN - $action = fn () => new OrderLineProduct(new IncoId(1), new ProductId(Uuid::uuid7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(-100), Money::EUR(100), TaxRate::TVA_5_5); + $action = fn () => new OrderLineProduct( + new IncoId(1), + new ProductId(Uuid::uuid7()), + 'Name', + new ProductWeight(1, false), + ProductBrand::marie, + OrderUnit::KGM, + Money::EUR(100), + Money::EUR(-100), + Money::EUR(100), + TaxRate::TVA_5_5, + ); // THEN expect($action)->toThrow(\DomainException::class, 'Product discounted price cannot be negative'); }); @@ -78,7 +111,18 @@ describe('OrderLineProduct', function (): void { it('throws exception if price per kg ttc is negative', function (): void { // GIVEN // WHEN - $action = fn () => new OrderLineProduct(new IncoId(1), new ProductId(Uuid::uuid7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(100), Money::EUR(-100), TaxRate::TVA_5_5); + $action = fn () => new OrderLineProduct( + new IncoId(1), + new ProductId(Uuid::uuid7()), + 'Name', + new ProductWeight(1, false), + ProductBrand::marie, + OrderUnit::KGM, + Money::EUR(100), + Money::EUR(100), + Money::EUR(-100), + TaxRate::TVA_5_5, + ); // THEN expect($action)->toThrow(\DomainException::class, 'Price per kg TTC cannot be negative'); }); @@ -86,7 +130,18 @@ describe('OrderLineProduct', function (): void { it('throws exception if discounted price is greater than price', function (): void { // GIVEN // WHEN - $action = fn () => new OrderLineProduct(new IncoId(1), new ProductId(Uuid::uuid7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(150), Money::EUR(100), TaxRate::TVA_5_5); + $action = fn () => new OrderLineProduct( + new IncoId(1), + new ProductId(Uuid::uuid7()), + 'Name', + new ProductWeight(1, false), + ProductBrand::marie, + OrderUnit::KGM, + Money::EUR(100), + Money::EUR(150), + Money::EUR(100), + TaxRate::TVA_5_5, + ); // THEN expect($action)->toThrow(\DomainException::class, 'Product discounted price cannot be greater than original price'); }); @@ -94,7 +149,18 @@ describe('OrderLineProduct', function (): void { it('throws exception if price per kg ttc is zero', function (): void { // GIVEN // WHEN - $action = fn () => new OrderLineProduct(new IncoId(1), new ProductId(Uuid::uuid7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(100), Money::EUR(0), TaxRate::TVA_5_5); + $action = fn () => new OrderLineProduct( + new IncoId(1), + new ProductId(Uuid::uuid7()), + 'Name', + new ProductWeight(1, false), + ProductBrand::marie, + OrderUnit::KGM, + Money::EUR(100), + Money::EUR(100), + Money::EUR(0), + TaxRate::TVA_5_5, + ); // THEN expect($action)->toThrow(\DomainException::class, 'Price per kg TTC has to be positive'); });