fix: 🐛 resolve linter errors and tests

This commit is contained in:
Corentin Huet 2026-09-23 17:33:02 +02:00
parent 7560e9339b
commit 591ebf9fe2
6 changed files with 30 additions and 36 deletions

View file

@ -3,6 +3,7 @@
declare(strict_types=1);
namespace Domain\Models\Entities;
use Domain\Enums\Country;
use Domain\Models\Entities\Tag;
use Domain\Models\ValueObjects\Brand\BrandCode;
@ -26,7 +27,7 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier
public bool $publication,
public bool $printAllAtOnce,
public Country $availableIn,
/** @var CampaignCoupon[] */
/** @var array<int, CampaignCoupon> $coupons */
public array $coupons,
public BrandCode $brand,
public ?\DateTimeInterface $updatedAt = null,
@ -48,6 +49,9 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier
return $this->updatedAt;
}
/**
* @param array<int, CampaignCoupon> $coupons
*/
public static function create(
CampaignCode $code,
Tag $tag,
@ -55,7 +59,7 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier
bool $publication,
bool $printAllAtOnce,
Country $availableIn,
/** @var CampaignCoupon[] */
/** @var array<int, CampaignCoupon> $coupons */
array $coupons,
BrandCode $brand,
?\DateTimeInterface $updatedAt = null,
@ -74,6 +78,9 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier
);
}
/**
* @param array<int, CampaignCoupon> $coupons
*/
public static function hydrate(
CampaignId $id,
CampaignCode $code,
@ -82,7 +89,6 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier
bool $publication,
bool $printAllAtOnce,
Country $availableIn,
/** @var CampaignCoupon[] */
array $coupons,
BrandCode $brand,
?\DateTimeInterface $updatedAt = null,

View file

@ -25,7 +25,8 @@ final readonly class Stock implements AggregateRoot, HasTimestampIdentifier
/** @var array<int, StockAdjustment> $stockAdjustment */
public array $stockAdjustment,
public ?\DateTimeInterface $updatedAt = null,
) {}
) {
}
public function id(): StockId
{

View file

@ -3,6 +3,7 @@
declare(strict_types=1);
namespace Domain\Models\Entities;
use Domain\Models\ValueObjects\Tag\TagId;
use Domain\Models\ValueObjects\Tag\TagName;
use Shared\DDD\Models\AggregateRoot;

View file

@ -6,14 +6,15 @@ namespace Domain\Models\ValueObjects\Campaign;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\Stock\StockId;
final readonly class CampaignCoupon
{
public function __construct(
public ProcessingCode $code,
public StockId $qty,
public ?PrintRules $printRules,
public int $warningThresholdQty
public int $warningThresholdQty,
public ?PrintRules $printRules = null,
) {
if ($this->warningThresholdQty <= 0) {
throw new \DomainException('Campaign Coupon warningThresholdQty must be positive.');

View file

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Tests\Unit\Domain\Models\Entities;
use Carbon\CarbonImmutable;
use Domain\Enums\BarcodeFormat;
use Domain\Enums\Country;
use Domain\Models\Entities\Campaign;
use Domain\Models\Entities\Tag;
@ -14,26 +13,12 @@ use Domain\Models\ValueObjects\Campaign\CampaignCode;
use Domain\Models\ValueObjects\Campaign\CampaignCoupon;
use Domain\Models\ValueObjects\Campaign\CampaignId;
use Domain\Models\ValueObjects\Campaign\CampaignName;
use Domain\Models\ValueObjects\Coupon\CouponAvailabilityCalendar;
use Domain\Models\ValueObjects\Coupon\CouponDiffusion;
use Domain\Models\ValueObjects\Coupon\CouponId;
use Domain\Models\ValueObjects\Coupon\CouponLegalInformation;
use Domain\Models\ValueObjects\Coupon\CouponProduct;
use Domain\Models\ValueObjects\Coupon\CouponValidity;
use Domain\Models\ValueObjects\CouponName;
use Domain\Models\ValueObjects\CouponPicture;
use Domain\Models\ValueObjects\CouponProductName;
use Domain\Models\ValueObjects\GS1;
use Domain\Models\ValueObjects\MoneyAmount;
use Domain\Models\ValueObjects\PicturePath;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\Stock\StockId;
use Domain\Models\ValueObjects\Tag\TagId;
use Domain\Models\ValueObjects\Tag\TagName;
use Ramsey\Uuid\Uuid;
use Shared\Enums\Currency;
use Shared\ValueObjects\DateTime;
use Shared\ValueObjects\Money;
covers(Campaign::class);
@ -57,7 +42,7 @@ describe('campaign', function (): void {
$publication = \boolval(0);
$printAllAtOnce = \boolval(1);
$availableIn = Country::FR;
$coupons = [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)];
$coupons = [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))];
$brand = new BrandCode('AAA01');
// WHEN
@ -95,7 +80,7 @@ describe('campaign', function (): void {
$publication = \boolval(0);
$printAllAtOnce = \boolval(1);
$availableIn = Country::FR;
$coupons = [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)];
$coupons = [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))];
$brand = new BrandCode('AAA01');
$updatedAt = new \DateTimeImmutable('2026-09-22 10:00:00', new \DateTimeZone('UTC'));
@ -125,7 +110,7 @@ describe('campaign', function (): void {
$publication = \boolval(0);
$printAllAtOnce = \boolval(1);
$availableIn = Country::FR;
$coupons = [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)];
$coupons = [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))];
$brand = new BrandCode('AAA01');
// WHEN
@ -161,7 +146,7 @@ describe('campaign', function (): void {
$publication = \boolval(0);
$printAllAtOnce = \boolval(1);
$availableIn = Country::FR;
$coupons = [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)];
$coupons = [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))];
$brand = new BrandCode('AAA01');
// WHEN
@ -202,8 +187,7 @@ describe('campaign', function (): void {
\boolval(0),
\boolval(1),
Country::FR,
new GS1('110101010', BarcodeFormat::EAN13),
[new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)],
[new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))],
new BrandCode('AAA01')
);

View file

@ -7,6 +7,7 @@ namespace Tests\Unit\Domain\Models\ValueObjects\Campaign;
use Domain\Models\ValueObjects\Campaign\CampaignCoupon;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\Stock\StockId;
covers(CampaignCoupon::class);
@ -14,12 +15,12 @@ describe('campaign coupon', function (): void {
it('creates a valid campaign coupon', function (): void {
// GIVEN
$code = new ProcessingCode('PC1');
$qty = new StockId();
$qty = StockId::generate();
$printRules = new PrintRules(maxPerCustomer: 3);
$warningThresholdQty = 100;
// WHEN
$campaignCoupon = new CampaignCoupon(code: $code, qty: $qty, printRules: $printRules, warningThresholdQty: $warningThresholdQty);
$campaignCoupon = new CampaignCoupon($code, $qty, $warningThresholdQty, $printRules);
// THEN
expect($campaignCoupon->code)->toBe($code)
@ -31,11 +32,11 @@ describe('campaign coupon', function (): void {
it('creates a valid campaign coupon whitout print rules', function (): void {
// GIVEN
$code = new ProcessingCode('PC1');
$qty = new StockId();
$qty = StockId::generate();
$warningThresholdQty = 100;
// WHEN
$campaignCoupon = new CampaignCoupon(code: $code, qty: $qty, warningThresholdQty: $warningThresholdQty);
$campaignCoupon = new CampaignCoupon($code, $qty, $warningThresholdQty);
// THEN
expect($campaignCoupon->code)->toBe($code)
@ -46,21 +47,21 @@ describe('campaign coupon', function (): void {
it('rejects invalid campaign coupon', function (): void {
// GIVEN
$code = new ProcessingCode('PC1');
$qty = new StockId();
$qty = StockId::generate();
$printRules = new PrintRules(maxPerCustomer: 3);
$warningThresholdQty = -100;
// GIVEN / THEN
expect(fn (): CampaignCoupon => new CampaignCoupon(code: $code, qty: $qty, printRules: $printRules, warningThresholdQty: $warningThresholdQty))->toThrow(\DomainException::class);
expect(fn (): CampaignCoupon => new CampaignCoupon($code, $qty, $warningThresholdQty, $printRules))->toThrow(\DomainException::class);
});
it('rejects invalid campaign coupon whitout print rules', function (): void {
// GIVEN
$code = new ProcessingCode('PC1');
$qty = new StockId();
$qty = StockId::generate();
$warningThresholdQty = -100;
// GIVEN / THEN
expect(fn (): CampaignCoupon => new CampaignCoupon(code: $code, qty: $qty, warningThresholdQty: $warningThresholdQty))->toThrow(\DomainException::class);
expect(fn (): CampaignCoupon => new CampaignCoupon($code, $qty, $warningThresholdQty))->toThrow(\DomainException::class);
});
});