From cefc4e92a3e62acccfdb57beaf5256b3231a640f Mon Sep 17 00:00:00 2001 From: K Muller Date: Wed, 23 Sep 2026 09:40:47 +0200 Subject: [PATCH] fix: :rotating_light: linters --- .../Find/Output/CampaignRequestFound.php | 4 +- .../CampaignRequestRepository.php | 5 +- .../Find/FindCampaignRequestTest.php | 214 +++++++++--------- 3 files changed, 111 insertions(+), 112 deletions(-) diff --git a/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php b/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php index 732a2e4..ecb675e 100644 --- a/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php +++ b/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php @@ -7,8 +7,8 @@ namespace Application\UseCases\CampaignRequest\Find\Output; use Domain\Enums\Campaign\CampaignStatus; use Domain\Enums\Campaign\CampaignType; use Domain\Enums\Country; +use Domain\Models\Entities\Brand; use Domain\Models\Entities\RequestedCoupon; -use Domain\Models\ValueObjects\Brand\BrandCode; use Domain\Models\ValueObjects\CampaignRequest\Applicant; use Domain\Models\ValueObjects\CampaignRequest\RejectionReason; use Domain\Models\ValueObjects\PrintRules; @@ -16,7 +16,7 @@ use Domain\Models\ValueObjects\PrintRules; final readonly class CampaignRequestFound implements Output { public function __construct( - public BrandCode $code, + public Brand $brand, public Applicant $applicant, public Country $country, public CampaignType $campaignType, diff --git a/src/Domain/Ports/Repositories/CampaignRequestRepository.php b/src/Domain/Ports/Repositories/CampaignRequestRepository.php index 6c2c086..b421c0c 100644 --- a/src/Domain/Ports/Repositories/CampaignRequestRepository.php +++ b/src/Domain/Ports/Repositories/CampaignRequestRepository.php @@ -11,6 +11,7 @@ use Shared\DDD\Ports\Repository; /** * @extends \Shared\DDD\Ports\Repository<\Domain\Models\ValueObjects\Brand\BrandId, \Domain\Models\Entities\Brand> */ -interface CampaignRequestRepository extends Repository { - public function findById(CampaignRequestId $id): ?CampaignRequest; +interface CampaignRequestRepository extends Repository +{ + public function findById(CampaignRequestId $id): ?CampaignRequest; } diff --git a/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php b/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php index 3a91a39..62dc9b8 100644 --- a/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php +++ b/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php @@ -45,113 +45,111 @@ use Shared\ValueObjects\Rcs; covers(FindCampaignRequest::class, Input::class, CampaignRequestFound::class, CampaignRequestNotFound::class); -function aFindableRequestedCoupon(): RequestedCoupon -{ - return RequestedCoupon::hydrate( - RequestedCouponId::generate(), - new CouponName('Coupon A'), - new CouponProductName('Product A'), - 100, - 10, - new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01')), - new MoneyAmount(new Money(Currency::EUR, 300)), - new ProcessingCode('PC1'), - new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')), - new GS1('01234567890128', BarcodeFormat::EAN13), - new CouponValidity(30, DateTime::now()), - ); -} - -function aFindableBrand(BrandCode $code): Brand -{ - return Brand::hydrate( - BrandId::generate(), - $code, - new BrandName('Brand A'), - new PicturePath('brands/logo.jpg'), - new Rcs('RCS PARIS 111 222 333'), - new Email('contact@example.com'), - ); -} -#FIXME describe('find campaign request use case', function (): void { - // Disabled: these two tests build a real Brand via aFindableBrand(), which calls - // BrandId::generate(). BrandId::generate(): self is not covariant with the parent - // Uuidv7EntityId::generate(): static, which fatals PHP as soon as BrandId.php is - // loaded. Re-enable once BrandId is fixed (self -> static), out of scope for now. - // - // it('finds a campaign request by its id, along with its brand', function (): void { - // // GIVEN - // $id = CampaignRequestId::generate(); - // $code = new BrandCode('AAA01'); - // $campaignRequest = CampaignRequest::hydrate( - // $id, - // $code, - // new Applicant('John', 'Doe', new Email('john.doe@example.com')), - // Country::FR, - // CampaignType::CLUB, - // new PrintRules(maxPerCustomer: 3), - // aFindableRequestedCoupon(), - // CampaignStatus::CREATED, - // ); - // $brand = aFindableBrand($code); - // - // $repository = \Mockery::mock(CampaignRequestRepository::class); - // $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); - // - // $brandRepository = \Mockery::mock(BrandRepository::class); - // $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn($brand); - // - // $useCase = new FindCampaignRequest($repository, $brandRepository); - // - // // WHEN - // $result = $useCase->execute(new Input(id: $id)); - // - // // THEN - // expect($result)->toBeInstanceOf(CampaignRequestFound::class) - // ->and($result->brand)->toBe($brand) - // ->and($result->applicant)->toBe($campaignRequest->applicant) - // ->and($result->country)->toBe($campaignRequest->country) - // ->and($result->campaignType)->toBe($campaignRequest->campaignType) - // ->and($result->printRules)->toBe($campaignRequest->printRules) - // ->and($result->requestedCoupon)->toBe($campaignRequest->requestedCoupon) - // ->and($result->status)->toBe($campaignRequest->status) - // ->and($result->rejectionReason)->toBeNull(); - // }); - // - // it('finds a rejected campaign request with its rejection reason', function (): void { - // // GIVEN - // $id = CampaignRequestId::generate(); - // $code = new BrandCode('AAA01'); - // $rejectionReason = new RejectionReason('Missing legal documents.'); - // $campaignRequest = CampaignRequest::hydrate( - // $id, - // $code, - // new Applicant('John', 'Doe', new Email('john.doe@example.com')), - // Country::FR, - // CampaignType::CLUB, - // new PrintRules(maxPerCustomer: 3), - // aFindableRequestedCoupon(), - // CampaignStatus::REJECTED, - // $rejectionReason, - // ); - // - // $repository = \Mockery::mock(CampaignRequestRepository::class); - // $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); - // - // $brandRepository = \Mockery::mock(BrandRepository::class); - // $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn(aFindableBrand($code)); - // - // $useCase = new FindCampaignRequest($repository, $brandRepository); - // - // // WHEN - // $result = $useCase->execute(new Input(id: $id)); - // - // // THEN - // expect($result)->toBeInstanceOf(CampaignRequestFound::class) - // ->and($result->status)->toBe(CampaignStatus::REJECTED) - // ->and($result->rejectionReason)->toBe($rejectionReason); - // }); + beforeEach(function (): void { + $this->requestedCoupon = RequestedCoupon::hydrate( + RequestedCouponId::generate(), + new CouponName('Coupon A'), + new CouponProductName('Product A'), + 100, + 10, + new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01')), + new MoneyAmount(new Money(Currency::EUR, 300)), + new ProcessingCode('PC1'), + new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')), + new GS1('01234567890128', BarcodeFormat::EAN13), + new CouponValidity(30, DateTime::now()), + ); + }); + + it('finds a campaign request by its id, along with its brand', function (): void { + // GIVEN + $id = CampaignRequestId::generate(); + $code = new BrandCode('AAA01'); + $campaignRequest = CampaignRequest::hydrate( + $id, + $code, + new Applicant('John', 'Doe', new Email('john.doe@example.com')), + Country::FR, + CampaignType::CLUB, + new PrintRules(maxPerCustomer: 3), + $this->requestedCoupon, + CampaignStatus::CREATED, + ); + $brand = Brand::hydrate( + BrandId::generate(), + $code, + new BrandName('Brand A'), + new PicturePath('brands/logo.jpg'), + new Rcs('RCS PARIS 111 222 333'), + new Email('contact@example.com'), + ); + + $repository = \Mockery::mock(CampaignRequestRepository::class); + $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); + + $brandRepository = \Mockery::mock(BrandRepository::class); + $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn($brand); + + $useCase = new FindCampaignRequest($repository, $brandRepository); + + // WHEN + $result = $useCase->execute(new Input(id: $id)); + + // THEN + expect($result)->toBeInstanceOf(CampaignRequestFound::class) + ->and($result->brand)->toBe($brand) + ->and($result->applicant)->toBe($campaignRequest->applicant) + ->and($result->country)->toBe($campaignRequest->country) + ->and($result->campaignType)->toBe($campaignRequest->campaignType) + ->and($result->printRules)->toBe($campaignRequest->printRules) + ->and($result->requestedCoupon)->toBe($campaignRequest->requestedCoupon) + ->and($result->status)->toBe($campaignRequest->status) + ->and($result->rejectionReason)->toBeNull(); + }); + + it('finds a rejected campaign request with its rejection reason', function (): void { + // GIVEN + $id = CampaignRequestId::generate(); + $code = new BrandCode('AAA01'); + $rejectionReason = new RejectionReason('Missing legal documents.'); + $campaignRequest = CampaignRequest::hydrate( + $id, + $code, + new Applicant('John', 'Doe', new Email('john.doe@example.com')), + Country::FR, + CampaignType::CLUB, + new PrintRules(maxPerCustomer: 3), + $this->requestedCoupon, + CampaignStatus::REJECTED, + $rejectionReason, + ); + + $repository = \Mockery::mock(CampaignRequestRepository::class); + $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); + + $brandRepository = \Mockery::mock(BrandRepository::class); + $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn( + Brand::hydrate( + BrandId::generate(), + $code, + new BrandName('Brand A'), + new PicturePath('brands/logo.jpg'), + new Rcs('RCS PARIS 111 222 333'), + new Email('contact@example.com'), + ) + ); + + $useCase = new FindCampaignRequest($repository, $brandRepository); + + // WHEN + $result = $useCase->execute(new Input(id: $id)); + + // THEN + expect($result)->toBeInstanceOf(CampaignRequestFound::class) + ->and($result->status)->toBe(CampaignStatus::REJECTED) + ->and($result->rejectionReason)->toBe($rejectionReason); + }); it('returns CampaignRequestNotFound when the id is not found', function (): void { // GIVEN @@ -183,7 +181,7 @@ describe('find campaign request use case', function (): void { Country::FR, CampaignType::CLUB, new PrintRules(maxPerCustomer: 3), - aFindableRequestedCoupon(), + $this->requestedCoupon, CampaignStatus::CREATED, ); @@ -204,7 +202,7 @@ describe('find campaign request use case', function (): void { }); describe('find campaign request use case assertions', function (): void { - it('rejects a wrong type input', function (): void { + it('rejects an input of the wrong type', function (): void { // GIVEN $repository = \Mockery::mock(CampaignRequestRepository::class); $brandRepository = \Mockery::mock(BrandRepository::class);