$customerId =
$this->
createCustomer($email);
$alternativeSalesChannel =
$this->
createSalesChannel([ 'domains' =>
[[ 'languageId' => Defaults::LANGUAGE_SYSTEM,
'currencyId' => Defaults::CURRENCY,
'snippetSetId' =>
$this->
getSnippetSetIdForLocale('en-GB'
),
'url' => 'http://localhost.test/a',
]],
]);
// create unrelated newsletter recipient which should not be involved when updating the customer's newsletter sales channel ids
$this->
createNewsletterRecipient($context, 'foobar@example.com', TestDefaults::SALES_CHANNEL
);
// subscribe to default sales channel and assert that array contains only that id
$newsletterRecipientA =
$this->
createNewsletterRecipient($context,
$email, TestDefaults::SALES_CHANNEL
);
/** @var EntityRepository<CustomerCollection> $customerRepository */
$customerRepository =
$this->
getContainer()->
get('customer.repository'
);
$customer =
$customerRepository->
search(new Criteria([$customerId]),
$context)->
getEntities()->
first();
static::
assertNotNull($customer);
static::
assertNotNull($customer->
getNewsletterSalesChannelIds());
static::
assertCount(1,
$customer->
getNewsletterSalesChannelIds());