public function testReplaceIndividualCodes(): void
{ $promotionRepository =
$this->
getContainer()->
get('promotion.repository'
);
$codeRepository =
$this->
getContainer()->
get('promotion_individual_code.repository'
);
$salesChannelContext =
$this->
getContainer()->
get(SalesChannelContextFactory::
class) ->
create(Uuid::
randomHex(), TestDefaults::SALES_CHANNEL
);
$context =
$salesChannelContext->
getContext();
$id = Uuid::
randomHex();
$codes =
['myIndividualCode_00A', 'myIndividualCode_11B'
];
$this->
createPromotion($id, null,
$promotionRepository,
$salesChannelContext);
$this->
createIndividualCode($id,
$codes[0
],
$codeRepository,
$context);
$this->
createIndividualCode($id,
$codes[1
],
$codeRepository,
$context);
$criteria =
(new Criteria([$id])) ->
addAssociation('individualCodes'
);
/** @var PromotionEntity|null $promotion */
$promotion =
$promotionRepository->
search($criteria,
$context)->
get($id);
static::
assertNotNull($promotion);
static::
assertNotNull($promotion->
getIndividualCodes());
static::
assertCount(2,
$promotion->
getIndividualCodes()->
getElements());