test(quality): resolve PHPStan level 10 errors in Feature tests and wrap long test lines

This commit is contained in:
Jérémy Munsch 2026-11-16 16:29:17 +01:00
parent 08c9028f91
commit 14fd20c303
No known key found for this signature in database
GPG key ID: 2AAECDA6B7330F91
14 changed files with 332 additions and 87 deletions

View file

@ -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(),
]);

View file

@ -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(),
]);

View file

@ -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) {

View file

@ -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',

View file

@ -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(

View file

@ -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(

View file

@ -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(

View file

@ -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(),
]);

View file

@ -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);
});
});

View file

@ -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'),
]);

View file

@ -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([

View file

@ -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);

View file

@ -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 = [];

View file

@ -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');
});