fix: 🚨 linters
This commit is contained in:
parent
54fe53528e
commit
cefc4e92a3
3 changed files with 111 additions and 112 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue