feat: upgrade phpunit to 12.5
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Repository\NewsletterConsentRepository;
|
||||
use App\Repository\NewsletterOptInRequestRepository;
|
||||
use App\Service\NewsletterManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\NullLogger;
|
||||
@@ -152,10 +153,13 @@ class NewsletterManagerTest extends TestCase
|
||||
|
||||
$mailjet->expects(self::never())->method('isSubscribed');
|
||||
$mailjet->expects(self::once())->method('upsertContact')->with('[email protected]', 'Mia', 'Muster');
|
||||
$ensureSubscribedCalls = [];
|
||||
$mailjet
|
||||
->expects(self::exactly(2))
|
||||
->method('ensureSubscribed')
|
||||
->withConsecutive(['[email protected]', 1], ['[email protected]', 2]);
|
||||
->willReturnCallback(static function (string $email, ?int $listId) use (&$ensureSubscribedCalls): void {
|
||||
$ensureSubscribedCalls[] = [$email, $listId];
|
||||
});
|
||||
$consents->method('findActiveByEmail')->with('[email protected]')->willReturn($existingConsent);
|
||||
$consents
|
||||
->method('findOneByEmailAndListId')
|
||||
@@ -184,6 +188,7 @@ class NewsletterManagerTest extends TestCase
|
||||
1 => NewsletterSubscriptionRequestResult::LIST_STATE_ALREADY_REGISTERED,
|
||||
2 => NewsletterSubscriptionRequestResult::LIST_STATE_ALREADY_REGISTERED,
|
||||
], $result->listStates);
|
||||
self::assertSame([['[email protected]', 1], ['[email protected]', 2]], $ensureSubscribedCalls);
|
||||
}
|
||||
|
||||
public function testApiRequestRejectsUnknownListIdsBeforeSideEffects(): void
|
||||
@@ -192,7 +197,7 @@ class NewsletterManagerTest extends TestCase
|
||||
$consents = $this->createMock(NewsletterConsentRepository::class);
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$mailjet = $this->createMock(ApiClient::class);
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer = $this->createStub(Mailer::class);
|
||||
|
||||
$mailjet->expects(self::never())->method('isSubscribed');
|
||||
$mailjet->expects(self::never())->method('ensureSubscribed');
|
||||
@@ -252,7 +257,7 @@ class NewsletterManagerTest extends TestCase
|
||||
$consents = $this->createMock(NewsletterConsentRepository::class);
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$mailjet = $this->createMock(ApiClient::class);
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer = $this->createStub(Mailer::class);
|
||||
|
||||
$mailjet->expects(self::never())->method('isSubscribed');
|
||||
$mailjet->expects(self::once())->method('upsertContact')->with('[email protected]', 'Mia', 'Muster');
|
||||
@@ -274,7 +279,7 @@ class NewsletterManagerTest extends TestCase
|
||||
public function testDefaultRequestCreatesDefaultListPendingConfirmation(): void
|
||||
{
|
||||
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
|
||||
$consents = $this->createMock(NewsletterConsentRepository::class);
|
||||
$consents = $this->createStub(NewsletterConsentRepository::class);
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$mailjet = $this->createMock(ApiClient::class);
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
@@ -301,7 +306,7 @@ class NewsletterManagerTest extends TestCase
|
||||
public function testRequestConfirmationTruncatesNamesBeforePersisting(): void
|
||||
{
|
||||
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
|
||||
$consents = $this->createMock(NewsletterConsentRepository::class);
|
||||
$consents = $this->createStub(NewsletterConsentRepository::class);
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$mailjet = $this->createMock(ApiClient::class);
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
@@ -340,7 +345,7 @@ class NewsletterManagerTest extends TestCase
|
||||
$consents = $this->createMock(NewsletterConsentRepository::class);
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$mailjet = $this->createMock(ApiClient::class);
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer = $this->createStub(Mailer::class);
|
||||
|
||||
$repository->expects(self::once())->method('findByTokenHash')->with(hash('sha256', $token))->willReturn($confirmation);
|
||||
$repository->expects(self::never())->method('deletePendingByEmail');
|
||||
@@ -371,16 +376,19 @@ class NewsletterManagerTest extends TestCase
|
||||
$consents = $this->createMock(NewsletterConsentRepository::class);
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$mailjet = $this->createMock(ApiClient::class);
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer = $this->createStub(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);
|
||||
$consents->method('findByEmailAndListIds')->with('[email protected]', [1, 2])->willReturn([]);
|
||||
$ensureSubscribedCalls = [];
|
||||
$mailjet
|
||||
->expects(self::exactly(2))
|
||||
->method('ensureSubscribed')
|
||||
->withConsecutive(['[email protected]', 1], ['[email protected]', 2]);
|
||||
->willReturnCallback(static function (string $email, ?int $listId) use (&$ensureSubscribedCalls): void {
|
||||
$ensureSubscribedCalls[] = [$email, $listId];
|
||||
});
|
||||
$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');
|
||||
@@ -389,6 +397,7 @@ class NewsletterManagerTest extends TestCase
|
||||
->confirmToken($token);
|
||||
|
||||
self::assertSame(NewsletterConfirmationResult::STATUS_CONFIRMED, $result->status);
|
||||
self::assertSame([['[email protected]', 1], ['[email protected]', 2]], $ensureSubscribedCalls);
|
||||
}
|
||||
|
||||
public function testConfirmationEntityNormalizesMailjetListIds(): void
|
||||
@@ -403,9 +412,7 @@ class NewsletterManagerTest extends TestCase
|
||||
self::assertSame([1, 2], $confirmation->getMailjetListIds());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidEntityMailjetListIdProvider
|
||||
*/
|
||||
#[DataProvider('invalidEntityMailjetListIdProvider')]
|
||||
public function testConfirmationEntityRejectsInvalidMailjetListIds(mixed $mailjetListId): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
Reference in New Issue
Block a user