feat: MailJet list handling with DOI, webhook receiver and API endpoint

addresses #869cut134
This commit is contained in:
Björn Fromme
2026-04-29 09:51:57 +02:00
parent df7885ca1c
commit e4ef2f7adc
46 changed files with 3389 additions and 322 deletions
+197
View File
@@ -0,0 +1,197 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\Service\MailjetApiClient;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
class MailjetApiClientTest extends TestCase
{
public function testChecksSubscriptionAgainstSuppliedListId(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
if (true === str_contains($url, '/Contact?')) {
return new MockResponse(json_encode([
'Data' => [
['ID' => 99],
],
], JSON_THROW_ON_ERROR));
}
return new MockResponse(json_encode([
'Data' => [
[
'ContactID' => 99,
'IsActive' => true,
'IsUnsubscribed' => false,
],
],
], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$subscribed = $mailjet->isSubscribed(' [email protected] ', 123);
self::assertTrue($subscribed);
self::assertSame('123', (string) $requests[1][2]['query']['ContactsList']);
}
public function testUpsertContactCreatesContactAndUpdatesProperties(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
if (true === str_contains($url, '/Contact?')) {
return new MockResponse(json_encode([
'Data' => [],
], JSON_THROW_ON_ERROR));
}
if (true === str_contains($url, '/Contact')) {
return new MockResponse(json_encode([
'Data' => [
['ID' => 99],
],
], JSON_THROW_ON_ERROR));
}
return new MockResponse(json_encode([
'Data' => [],
], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient(
$client,
new NullLogger(),
'key',
'secret',
'https://mailjet.test',
'111',
[
'firstName' => 'vorname',
'lastName' => 'nachname',
],
);
$mailjet->upsertContact(' [email protected] ', ' Mia ', ' Muster ');
self::assertCount(3, $requests);
self::assertSame('GET', $requests[0][0]);
self::assertSame('https://mailjet.test/[email protected]&Limit=1', $requests[0][1]);
self::assertSame('[email protected]', (string) $requests[0][2]['query']['Email']);
self::assertSame('POST', $requests[1][0]);
self::assertSame('https://mailjet.test/Contact', $requests[1][1]);
self::assertSame([
'Email' => '[email protected]',
], json_decode((string) $requests[1][2]['body'], true, 512, JSON_THROW_ON_ERROR));
self::assertSame('POST', $requests[2][0]);
self::assertSame('https://mailjet.test/contactdata', $requests[2][1]);
self::assertSame([
'ContactID' => 99,
'Data' => [
[
'Name' => 'vorname',
'Value' => 'Mia',
],
[
'Name' => 'nachname',
'Value' => 'Muster',
],
],
], json_decode((string) $requests[2][2]['body'], true, 512, JSON_THROW_ON_ERROR));
}
public function testUpsertContactTruncatesLongNamesBeforeSending(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
if (true === str_contains($url, '/Contact?')) {
return new MockResponse(json_encode([
'Data' => [
['ID' => 99],
],
], JSON_THROW_ON_ERROR));
}
if (true === str_contains($url, '/Contact')) {
return new MockResponse(json_encode([
'Data' => [],
], JSON_THROW_ON_ERROR));
}
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient(
$client,
new NullLogger(),
'key',
'secret',
'https://mailjet.test',
'111',
[
'firstName' => 'vorname',
'lastName' => 'nachname',
],
);
$mailjet->upsertContact('[email protected]', str_repeat('A', 300), str_repeat('B', 300));
$payload = json_decode((string) $requests[1][2]['body'], true, 512, JSON_THROW_ON_ERROR);
self::assertSame(255, strlen($payload['Data'][0]['Value']));
self::assertSame(255, strlen($payload['Data'][1]['Value']));
self::assertSame(str_repeat('A', 255), $payload['Data'][0]['Value']);
self::assertSame(str_repeat('B', 255), $payload['Data'][1]['Value']);
}
public function testUpsertContactDoesNothingWithoutNames(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet->upsertContact(' [email protected] ');
self::assertSame([], $requests);
}
public function testEnsureSubscribedUsesSuppliedListId(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet->ensureSubscribed(' [email protected] ', 456);
self::assertCount(1, $requests);
self::assertSame('POST', $requests[0][0]);
self::assertSame('https://mailjet.test/Contactslist/456/managecontact', $requests[0][1]);
self::assertSame([
'Email' => '[email protected]',
'Action' => 'addforce',
], json_decode((string) $requests[0][2]['body'], true, 512, JSON_THROW_ON_ERROR));
}
}
+443
View File
@@ -0,0 +1,443 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\Email\Mailer;
use App\Entity\NewsletterConsent;
use App\Entity\NewsletterOptInRequest;
use App\Exception\NewsletterListNotAllowedException;
use App\Model\NewsletterConfirmationResult;
use App\Model\NewsletterSubscriptionRequestResult;
use App\Repository\NewsletterConsentRepository;
use App\Repository\NewsletterOptInRequestRepository;
use App\Service\MailjetApiClient;
use App\Service\NewsletterManager;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
class NewsletterManagerTest extends TestCase
{
public function testApiRequestCreatesPendingConfirmationForNewEmailWithNormalizedLists(): void
{
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet
->expects(self::exactly(2))
->method('isSubscribed')
->withConsecutive(['[email protected]', 1], ['[email protected]', 2])
->willReturn(false);
$consents->expects(self::once())->method('findActiveByEmail')->with('[email protected]')->willReturn(null);
$repository->expects(self::once())->method('deleteExpiredPendingByEmail')->with('[email protected]')->willReturn(0);
$repository->expects(self::once())->method('findPendingByEmail')->with('[email protected]')->willReturn(null);
$entityManager
->expects(self::once())
->method('persist')
->with(self::callback(static function (NewsletterOptInRequest $confirmation): bool {
self::assertSame('[email protected]', $confirmation->getEmail());
self::assertSame([1, 2], $confirmation->getMailjetListIds());
self::assertSame('Mia', $confirmation->getFirstName());
self::assertSame('Muster', $confirmation->getLastName());
return true;
}));
$entityManager->expects(self::once())->method('flush');
$mailer
->expects(self::once())
->method('createAndSendEmail')
->with(
self::callback(static function (array $context): bool {
self::assertArrayHasKey('token', $context);
self::assertSame([
['id' => 1, 'label' => 'List One'],
['id' => 2, 'label' => 'List Two'],
], $context['newsletterLists']);
return true;
}),
self::anything(),
);
$result = $this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestApiSubscription(' [email protected] ', [2, 1, 2], [1, 2], ' Mia ', ' Muster ');
self::assertSame('[email protected]', $result->email);
self::assertSame([1, 2], $result->listIds);
self::assertSame(NewsletterSubscriptionRequestResult::STATE_CONFIRMATION_REQUESTED, $result->state);
self::assertTrue($result->confirmationRequested);
self::assertSame([
1 => NewsletterSubscriptionRequestResult::LIST_STATE_PENDING,
2 => NewsletterSubscriptionRequestResult::LIST_STATE_PENDING,
], $result->listStates);
}
public function testApiRequestDoesNotResendForPendingConfirmationWithSameListSet(): void
{
$pending = new NewsletterOptInRequest('[email protected]', str_repeat('a', 64), new \DateTimeImmutable('+1 hour'), [1, 2]);
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->method('isSubscribed')->willReturn(false);
$consents->expects(self::once())->method('findActiveByEmail')->with('[email protected]')->willReturn(null);
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
$repository->expects(self::once())->method('findPendingByEmail')->with('[email protected]')->willReturn($pending);
$entityManager->expects(self::never())->method('persist');
$entityManager->expects(self::never())->method('flush');
$mailer->expects(self::never())->method('createAndSendEmail');
$result = $this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestApiSubscription('[email protected]', [2, 1]);
self::assertSame(NewsletterSubscriptionRequestResult::STATE_PENDING_CONFIRMATION, $result->state);
self::assertFalse($result->confirmationRequested);
self::assertSame([
1 => NewsletterSubscriptionRequestResult::LIST_STATE_PENDING,
2 => NewsletterSubscriptionRequestResult::LIST_STATE_PENDING,
], $result->listStates);
}
public function testApiRequestRefreshesPendingConfirmationWithLatestListSetAndNames(): void
{
$pending = new NewsletterOptInRequest('[email protected]', str_repeat('a', 64), new \DateTimeImmutable('+1 hour'), [1], 'Old', 'Name');
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->method('isSubscribed')->willReturn(false);
$consents->expects(self::once())->method('findActiveByEmail')->with('[email protected]')->willReturn(null);
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
$repository->expects(self::exactly(2))->method('findPendingByEmail')->with('[email protected]')->willReturn($pending);
$entityManager->expects(self::never())->method('persist');
$entityManager->expects(self::once())->method('flush');
$mailer->expects(self::once())->method('createAndSendEmail');
$result = $this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestApiSubscription('[email protected]', [3, 2], null, 'New', 'Person');
self::assertSame(NewsletterSubscriptionRequestResult::STATE_CONFIRMATION_REQUESTED, $result->state);
self::assertTrue($result->confirmationRequested);
self::assertSame([2, 3], $pending->getMailjetListIds());
self::assertSame('New', $pending->getFirstName());
self::assertSame('Person', $pending->getLastName());
}
public function testApiRequestRecordsConsentWhenAllListsAreAlreadySubscribed(): void
{
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->method('isSubscribed')->willReturn(true);
$mailjet->expects(self::once())->method('upsertContact')->with('[email protected]', 'Mia', 'Muster');
$consents->method('findActiveByEmail')->with('[email protected]')->willReturn(null);
$consents->method('findOneByEmailAndListId')->willReturn(null);
$repository->expects(self::once())->method('deletePendingByEmail')->with('[email protected]')->willReturn(0);
$entityManager->expects(self::exactly(2))->method('persist')->with(self::isInstanceOf(NewsletterConsent::class));
$entityManager->expects(self::once())->method('flush');
$mailer->expects(self::never())->method('createAndSendEmail');
$result = $this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestApiSubscription('[email protected]', [2, 1], null, 'Mia', 'Muster');
self::assertSame(NewsletterSubscriptionRequestResult::STATE_SUBSCRIBED, $result->state);
self::assertFalse($result->confirmationRequested);
self::assertSame([
1 => NewsletterSubscriptionRequestResult::LIST_STATE_ALREADY_REGISTERED,
2 => NewsletterSubscriptionRequestResult::LIST_STATE_ALREADY_REGISTERED,
], $result->listStates);
}
public function testApiRequestRejectsUnknownListIdsBeforeSideEffects(): void
{
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
$mailjet->expects(self::never())->method('ensureSubscribed');
$consents->expects(self::never())->method('findActiveByEmail');
$repository->expects(self::never())->method('findPendingByEmail');
$entityManager->expects(self::never())->method('persist');
$entityManager->expects(self::never())->method('flush');
try {
$this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestApiSubscription('[email protected]', [2, 3], [1, 2]);
self::fail('Expected unknown Mailjet list IDs to be rejected.');
} catch (NewsletterListNotAllowedException $exception) {
self::assertSame('One or more Mailjet list IDs are not allowed.', $exception->getMessage());
self::assertSame([2, 3], $exception->getListIds());
self::assertSame([3], $exception->getUnknownListIds());
}
}
public function testApiRequestDirectlySubscribesMissingListWhenEmailIsSubscribedToKnownList(): void
{
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet
->expects(self::exactly(2))
->method('isSubscribed')
->withConsecutive(['[email protected]', 2], ['[email protected]', 1])
->willReturnOnConsecutiveCalls(false, true);
$mailjet->expects(self::once())->method('upsertContact')->with('[email protected]', 'Mia', 'Muster');
$mailjet->expects(self::once())->method('ensureSubscribed')->with('[email protected]', 2);
$consents->method('findActiveByEmail')->with('[email protected]')->willReturn(null);
$consents->method('findOneByEmailAndListId')->willReturn(null);
$repository->expects(self::once())->method('deletePendingByEmail')->with('[email protected]')->willReturn(0);
$repository->expects(self::never())->method('findPendingByEmail');
$entityManager->expects(self::once())->method('persist')->with(self::isInstanceOf(NewsletterConsent::class));
$entityManager->expects(self::once())->method('flush');
$mailer->expects(self::never())->method('createAndSendEmail');
$result = $this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestApiSubscription('[email protected]', [2], [1, 2], 'Mia', 'Muster');
self::assertSame(NewsletterSubscriptionRequestResult::STATE_SUBSCRIBED, $result->state);
self::assertFalse($result->confirmationRequested);
self::assertSame([
2 => NewsletterSubscriptionRequestResult::LIST_STATE_SUCCESS,
], $result->listStates);
}
public function testApiRequestDirectlySubscribesMissingListWhenEmailHasLocalConsent(): void
{
$existingConsent = new NewsletterConsent('[email protected]', 1, 'Old', 'Name');
$existingConsent->markConfirmed();
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->method('isSubscribed')->with('[email protected]', 2)->willReturn(false);
$mailjet->expects(self::once())->method('upsertContact')->with('[email protected]', 'Mia', 'Muster');
$mailjet->expects(self::once())->method('ensureSubscribed')->with('[email protected]', 2);
$consents->method('findActiveByEmail')->with('[email protected]')->willReturn($existingConsent);
$consents->method('findOneByEmailAndListId')->with('[email protected]', 2)->willReturn(null);
$repository->expects(self::once())->method('deletePendingByEmail')->with('[email protected]')->willReturn(0);
$entityManager->expects(self::once())->method('persist')->with(self::isInstanceOf(NewsletterConsent::class));
$entityManager->expects(self::once())->method('flush');
$result = $this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestApiSubscription('[email protected]', [2], [1, 2], 'Mia', 'Muster');
self::assertSame(NewsletterSubscriptionRequestResult::STATE_SUBSCRIBED, $result->state);
self::assertFalse($result->confirmationRequested);
}
public function testDefaultRequestCreatesDefaultListPendingConfirmation(): void
{
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
$repository->method('findPendingByEmail')->with('[email protected]')->willReturn(null);
$entityManager
->expects(self::once())
->method('persist')
->with(self::callback(static function (NewsletterOptInRequest $confirmation): bool {
self::assertSame('[email protected]', $confirmation->getEmail());
self::assertSame([10321569], $confirmation->getMailjetListIds());
return true;
}));
$entityManager->expects(self::once())->method('flush');
$mailer->expects(self::once())->method('createAndSendEmail');
$this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestConfirmation('[email protected]');
}
public function testRequestConfirmationTruncatesNamesBeforePersisting(): void
{
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
$repository->method('findPendingByEmail')->with('[email protected]')->willReturn(null);
$entityManager
->expects(self::once())
->method('persist')
->with(self::callback(static function (NewsletterOptInRequest $confirmation): bool {
self::assertSame(str_repeat('A', 255), $confirmation->getFirstName());
self::assertSame(str_repeat('B', 255), $confirmation->getLastName());
return true;
}));
$entityManager->expects(self::once())->method('flush');
$mailer->expects(self::once())->method('createAndSendEmail');
$this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestConfirmation('[email protected]', str_repeat('A', 300), str_repeat('B', 300));
}
public function testConfirmationSubscribesDefaultListAndStoresConsent(): void
{
$token = 'token';
$confirmation = new NewsletterOptInRequest(
'[email protected]',
hash('sha256', $token),
new \DateTimeImmutable('+1 hour'),
[],
'Mia',
'Muster',
);
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->expects(self::once())->method('findByTokenHash')->with(hash('sha256', $token))->willReturn($confirmation);
$repository->expects(self::never())->method('deletePendingByEmail');
$consents->expects(self::once())->method('findOneByEmailAndListId')->with('[email protected]', 10321569)->willReturn(null);
$mailjet->expects(self::once())->method('upsertContact')->with('[email protected]', 'Mia', 'Muster');
$mailjet->expects(self::once())->method('ensureSubscribed')->with('[email protected]', 10321569);
$entityManager->expects(self::once())->method('persist')->with(self::isInstanceOf(NewsletterConsent::class));
$entityManager->expects(self::once())->method('remove')->with($confirmation);
$entityManager->expects(self::once())->method('flush');
$result = $this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->confirmToken($token);
self::assertSame(NewsletterConfirmationResult::STATUS_CONFIRMED, $result->status);
self::assertSame([10321569], $confirmation->getMailjetListIds());
}
public function testConfirmationSubscribesStoredListIdsAndStoresConsents(): void
{
$token = 'token';
$confirmation = new NewsletterOptInRequest(
'[email protected]',
hash('sha256', $token),
new \DateTimeImmutable('+1 hour'),
[2, 1],
);
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->expects(self::once())->method('findByTokenHash')->with(hash('sha256', $token))->willReturn($confirmation);
$repository->expects(self::never())->method('deletePendingByEmail');
$consents->method('findOneByEmailAndListId')->willReturn(null);
$mailjet
->expects(self::exactly(2))
->method('ensureSubscribed')
->withConsecutive(['[email protected]', 1], ['[email protected]', 2]);
$entityManager->expects(self::exactly(2))->method('persist')->with(self::isInstanceOf(NewsletterConsent::class));
$entityManager->expects(self::once())->method('remove')->with($confirmation);
$entityManager->expects(self::once())->method('flush');
$result = $this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->confirmToken($token);
self::assertSame(NewsletterConfirmationResult::STATUS_CONFIRMED, $result->status);
}
public function testConfirmationEntityNormalizesMailjetListIds(): void
{
$confirmation = new NewsletterOptInRequest(
'[email protected]',
str_repeat('a', 64),
new \DateTimeImmutable('+1 hour'),
[2, '1', 2],
);
self::assertSame([1, 2], $confirmation->getMailjetListIds());
}
/**
* @dataProvider invalidEntityMailjetListIdProvider
*/
public function testConfirmationEntityRejectsInvalidMailjetListIds(mixed $mailjetListId): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Mailjet list IDs must be positive integers.');
new NewsletterOptInRequest(
'[email protected]',
str_repeat('a', 64),
new \DateTimeImmutable('+1 hour'),
[$mailjetListId],
);
}
/**
* @return iterable<string, array{mixed}>
*/
public static function invalidEntityMailjetListIdProvider(): iterable
{
yield 'zero' => [0];
yield 'negative integer' => [-1];
yield 'zero string' => ['0'];
yield 'decimal' => [1.5];
yield 'numeric prefix' => ['1abc'];
yield 'boolean' => [true];
}
/**
* @param MockObject&NewsletterOptInRequestRepository $repository
* @param MockObject&NewsletterConsentRepository $consents
* @param MockObject&EntityManagerInterface $entityManager
* @param MockObject&MailjetApiClient $mailjet
* @param MockObject&Mailer $mailer
* @param array<int, string> $mailjetLists
*/
private function createManager(
NewsletterOptInRequestRepository $repository,
NewsletterConsentRepository $consents,
EntityManagerInterface $entityManager,
MailjetApiClient $mailjet,
Mailer $mailer,
array $mailjetLists = [
10321569 => 'E&P Newsletter',
1 => 'List One',
2 => 'List Two',
3 => 'List Three',
],
): NewsletterManager {
return new NewsletterManager(
optInRequestRepository: $repository,
consentRepository: $consents,
entityManager: $entityManager,
newsletterService: $mailjet,
mailer: $mailer,
logger: new NullLogger(),
newsletterConfirmationTtlHours: 24,
mailjetLists: $mailjetLists,
defaultMailjetListId: '10321569',
);
}
}