diff --git a/src/Application/UseCases/CampaignRequest/Find/FindCampaignRequest.php b/src/Application/UseCases/CampaignRequest/Find/FindCampaignRequest.php index c4737e6..55c207e 100644 --- a/src/Application/UseCases/CampaignRequest/Find/FindCampaignRequest.php +++ b/src/Application/UseCases/CampaignRequest/Find/FindCampaignRequest.php @@ -36,10 +36,10 @@ final readonly class FindCampaignRequest implements UseCase return new CampaignRequestNotFound(); } - $brand = $this->brandRepository->findByCode($campaignRequest->code); + $brand = $this->brandRepository->findByCode($campaignRequest->brandCode); if (! $brand instanceof Brand) { - throw new BrandNotFoundException($campaignRequest->code); + throw new BrandNotFoundException($campaignRequest->brandCode); } return new CampaignRequestFound( diff --git a/src/Application/UseCases/CampaignRequest/List/CampaignRequestListItem.php b/src/Application/UseCases/CampaignRequest/List/CampaignRequestListItem.php index ebfa33e..1ae91e0 100644 --- a/src/Application/UseCases/CampaignRequest/List/CampaignRequestListItem.php +++ b/src/Application/UseCases/CampaignRequest/List/CampaignRequestListItem.php @@ -12,7 +12,7 @@ use Domain\Models\ValueObjects\CampaignRequest\Applicant; final readonly class CampaignRequestListItem { public function __construct( - public BrandCode $code, + public BrandCode $brandCode, public Applicant $applicant, public CampaignRequestType $campaignType, public CampaignRequestStatus $status diff --git a/src/Application/UseCases/CampaignRequest/List/ListCampaignsRequest.php b/src/Application/UseCases/CampaignRequest/List/ListCampaignsRequest.php index f61059a..1b1d3de 100644 --- a/src/Application/UseCases/CampaignRequest/List/ListCampaignsRequest.php +++ b/src/Application/UseCases/CampaignRequest/List/ListCampaignsRequest.php @@ -32,7 +32,7 @@ final readonly class ListCampaignsRequest implements UseCase $items = array_map( static fn (CampaignRequest $campaignRequest): CampaignRequestListItem => new CampaignRequestListItem( - code: $campaignRequest->code, + brandCode: $campaignRequest->brandCode, applicant: $campaignRequest->applicant, campaignType: $campaignRequest->campaignType, status: $campaignRequest->status diff --git a/src/Domain/Exceptions/BrandNotFoundException.php b/src/Domain/Exceptions/BrandNotFoundException.php index a8901bb..eee250c 100644 --- a/src/Domain/Exceptions/BrandNotFoundException.php +++ b/src/Domain/Exceptions/BrandNotFoundException.php @@ -12,8 +12,8 @@ use Shared\DDD\Exceptions\NotFoundException; */ final class BrandNotFoundException extends NotFoundException { - public function __construct(BrandCode $code) + public function __construct(BrandCode $brandCode) { - parent::__construct(sprintf('Brand with code "%s" was not found.', $code->value)); + parent::__construct(sprintf('Brand with code "%s" was not found.', $brandCode->value)); } } diff --git a/src/Domain/Models/Entities/CampaignRequest.php b/src/Domain/Models/Entities/CampaignRequest.php index 3a1674c..92be622 100644 --- a/src/Domain/Models/Entities/CampaignRequest.php +++ b/src/Domain/Models/Entities/CampaignRequest.php @@ -23,7 +23,7 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent { private function __construct( public CampaignRequestId $id, - public BrandCode $code, + public BrandCode $brandCode, public Applicant $applicant, public CampaignRequestType $campaignType, public ?PrintRules $printRules, @@ -59,7 +59,7 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent public static function hydrate( CampaignRequestId $id, - BrandCode $code, + BrandCode $brandCode, Applicant $applicant, CampaignRequestType $campaignType, ?PrintRules $printRules, @@ -70,7 +70,7 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent ): self { return new self( id: $id, - code: $code, + brandCode: $brandCode, applicant: $applicant, campaignType: $campaignType, printRules: $printRules, @@ -89,7 +89,7 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent return new self( id: $this->id, - code: $this->code, + brandCode: $this->brandCode, applicant: $this->applicant, campaignType: $this->campaignType, printRules: $this->printRules, diff --git a/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php b/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php index 11e7944..200ab32 100644 --- a/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php +++ b/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php @@ -63,11 +63,11 @@ describe('find campaign request use case', function (): void { 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 = CampaignRequestId::generate(); + $brandCode = new BrandCode('AAA01'); + $campaignRequest = CampaignRequest::hydrate( $id, - $code, + $brandCode, new Applicant('John', 'Doe', new Email('john.doe@example.com')), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), @@ -76,7 +76,7 @@ describe('find campaign request use case', function (): void { ); $brand = Brand::hydrate( BrandId::generate(), - $code, + $brandCode, new BrandName('Brand A'), new PicturePath('brands/logo.jpg'), new Rcs('RCS PARIS 111 222 333'), @@ -87,7 +87,7 @@ describe('find campaign request use case', function (): void { $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); $brandRepository = \Mockery::mock(BrandRepository::class); - $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn($brand); + $brandRepository->shouldReceive('findByCode')->once()->with($brandCode)->andReturn($brand); $useCase = new FindCampaignRequest($repository, $brandRepository); @@ -168,11 +168,11 @@ describe('find campaign request use case', function (): void { it('throws when the campaign request references a brand that no longer exists', function (): void { // GIVEN - $id = CampaignRequestId::generate(); - $code = new BrandCode('AAA01'); - $campaignRequest = CampaignRequest::hydrate( + $id = CampaignRequestId::generate(); + $brandCode = new BrandCode('AAA01'); + $campaignRequest = CampaignRequest::hydrate( $id, - $code, + $brandCode, new Applicant('John', 'Doe', new Email('john.doe@example.com')), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), @@ -184,7 +184,7 @@ describe('find campaign request use case', function (): void { $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); $brandRepository = \Mockery::mock(BrandRepository::class); - $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn(null); + $brandRepository->shouldReceive('findByCode')->once()->with($brandCode)->andReturn(null); $useCase = new FindCampaignRequest($repository, $brandRepository); diff --git a/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php b/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php index 483a049..cc93d70 100644 --- a/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php +++ b/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php @@ -96,7 +96,7 @@ describe('list campaigns request use case', function (): void { new CampaignRequestSortClause(field: CampaignRequestSortField::CreatedAt, direction: \SortDirection::Descending) ] ); - $filters = new CampaignRequestFilters($campaignRequest2->code, CampaignRequestStatus::CREATED); + $filters = new CampaignRequestFilters($campaignRequest2->brandCode, CampaignRequestStatus::CREATED); $input = new Input(pagination: $pagination, sort: $sort, filters: $filters); $repository = \Mockery::mock(CampaignRequestRepository::class); @@ -116,7 +116,7 @@ describe('list campaigns request use case', function (): void { $items = $result->campaignsRequest->getItems(); expect($items)->toHaveCount(2) ->and($items[0])->toBeInstanceOf(CampaignRequestListItem::class) - ->and($items[0]->code)->toBe($campaignRequest1->code) + ->and($items[0]->brandCode)->toBe($campaignRequest1->brandCode) ->and($items[0]->applicant)->toBe($campaignRequest1->applicant) ->and($items[0]->campaignType)->toBe($campaignRequest1->campaignType) ->and($items[0]->status)->toBe($campaignRequest1->status) @@ -138,7 +138,7 @@ describe('list campaigns request use case', function (): void { ); $paginated = new Paginated($pagination, [$campaignRequest], 1); - $filters = new CampaignRequestFilters($campaignRequest->code, CampaignRequestStatus::CREATED); + $filters = new CampaignRequestFilters($campaignRequest->brandCode, CampaignRequestStatus::CREATED); $input = new Input(pagination: $pagination, filters: $filters); $repository = \Mockery::mock(CampaignRequestRepository::class); @@ -156,7 +156,7 @@ describe('list campaigns request use case', function (): void { $items = $result->campaignsRequest->getItems(); expect($items)->toHaveCount(1) ->and($items[0])->toBeInstanceOf(CampaignRequestListItem::class) - ->and($items[0]->code)->toBe($campaignRequest->code) + ->and($items[0]->brandCode)->toBe($campaignRequest->brandCode) ->and($items[0]->status)->toBe($campaignRequest->status) ->and($result->campaignsRequest->getTotal())->toBe(1) ->and($result->campaignsRequest->getPagination())->toBe($pagination); @@ -206,8 +206,8 @@ describe('list campaigns request use case', function (): void { // THEN $items = $result->campaignsRequest->getItems(); expect($items)->toHaveCount(2) - ->and($items[0]->code)->toBe($campaignRequest2->code) - ->and($items[1]->code)->toBe($campaignRequest1->code) + ->and($items[0]->brandCode)->toBe($campaignRequest2->brandCode) + ->and($items[1]->brandCode)->toBe($campaignRequest1->brandCode) ->and($result->campaignsRequest->getTotal())->toBe(2) ->and($result->campaignsRequest->getPagination())->toBe($pagination); }); diff --git a/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php b/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php index 2217f6e..d9dc6fb 100644 --- a/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php +++ b/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php @@ -77,7 +77,7 @@ describe('campaign request', function (): void { // THEN expect($campaignRequest->id())->toBe($id) - ->and($campaignRequest->code)->toBe($code) + ->and($campaignRequest->brandCode)->toBe($code) ->and($campaignRequest->applicant)->toBe($applicant) ->and($campaignRequest->campaignType)->toBe($campaignType) ->and($campaignRequest->printRules)->toBe($printRules) @@ -206,7 +206,7 @@ describe('campaign request', function (): void { expect($rejected->status)->toBe(CampaignRequestStatus::REJECTED) ->and($rejected->rejectionReason)->toBe($reason) ->and($rejected->id())->toBe($campaignRequest->id()) - ->and($rejected->code)->toBe($campaignRequest->code) + ->and($rejected->brandCode)->toBe($campaignRequest->brandCode) ->and($rejected->applicant)->toBe($campaignRequest->applicant) ->and($rejected->campaignType)->toBe($campaignRequest->campaignType) ->and($rejected->printRules)->toBe($campaignRequest->printRules)