From 0764b9d60d0cb0a0c9460bb483241eb822515d2b Mon Sep 17 00:00:00 2001 From: aarohiprasad Date: Fri, 14 Feb 2025 14:10:57 +0530 Subject: [PATCH] callback subscriber test --- .../CallbackSubscriberTest.php | 32 ++++++++++++ .../SparkpostTransportMessageTest.php | 52 ++++++++++++++++--- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/Tests/Functional/EventSubscriber/CallbackSubscriberTest.php b/Tests/Functional/EventSubscriber/CallbackSubscriberTest.php index f426233..a85dc94 100644 --- a/Tests/Functional/EventSubscriber/CallbackSubscriberTest.php +++ b/Tests/Functional/EventSubscriber/CallbackSubscriberTest.php @@ -198,4 +198,36 @@ private function getCommentAndReason(string $type): array ], }; } + + /** + * For the message with 'type': 'out of band' and 'bounce class': 60 should never be called transportCallback. + */ + public function testProcessCallbackRequestWhenSoftBounce(): void + { + $payload = <<sparkpost->processCallbackRequest($request); + $this->transportCallbackMock->expects($this->never()) + ->method($this->anything()); + } } diff --git a/Tests/Unit/Mailer/Transport/SparkpostTransportMessageTest.php b/Tests/Unit/Mailer/Transport/SparkpostTransportMessageTest.php index cc9cf87..d329c96 100644 --- a/Tests/Unit/Mailer/Transport/SparkpostTransportMessageTest.php +++ b/Tests/Unit/Mailer/Transport/SparkpostTransportMessageTest.php @@ -16,6 +16,12 @@ class SparkpostTransportMessageTest extends TestCase { + /** + * @var TransportCallback|MockObject + */ + private $transportCallbackMock; + private SparkpostTransport $sparkpost; + public function testCcAndBccFields(): void { $emailId = 1; @@ -25,15 +31,15 @@ public function testCcAndBccFields(): void // so for maintain 64 bytes last char will be trimmed. $expectedInternalEmailName = '202211_シナリオメール②内視鏡機器提案のご案'; - $transportCallbackMock = $this->createMock(TransportCallback::class); - $httpClientMock = $this->createMock(HttpClientInterface::class); - $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class); - $loggerMock = $this->createMock(LoggerInterface::class); + $this->transportCallbackMock = $this->createMock(TransportCallback::class); + $httpClientMock = $this->createMock(HttpClientInterface::class); + $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class); + $loggerMock = $this->createMock(LoggerInterface::class); - $sparkpost = new SparkpostTransport( + $this->sparkpost = new SparkpostTransport( '1234', 'us', - $transportCallbackMock, + $this->transportCallbackMock, $httpClientMock, $eventDispatcherMock, $loggerMock @@ -66,7 +72,7 @@ public function testCcAndBccFields(): void $sentMessageMock->method('getOriginalMessage') ->willReturn($message); - $payload = $this->invokeInaccessibleMethod($sparkpost, 'getSparkpostPayload', [$sentMessageMock]); + $payload = $this->invokeInaccessibleMethod($this->sparkpost, 'getSparkpostPayload', [$sentMessageMock]); Assert::assertEquals(sprintf('%s:%s', $emailId, $expectedInternalEmailName), $payload['campaign_id']); Assert::assertEquals('from@xx.xx', $payload['content']['from']); Assert::assertEquals('Test subject', $payload['content']['subject']); @@ -187,4 +193,36 @@ private function invokeInaccessibleMethod(object $object, string $methodName, ar return $method->invokeArgs($object, $args); } + + /** + * For the message with 'type': 'out of band' and 'bounce class': 60 should never be called transportCallback. + */ + public function testProcessCallbackRequestWhenSoftBounce(): void + { + $payload = <<sparkpost->processCallbackRequest($request); + $this->transportCallbackMock->expects($this->never()) + ->method($this->anything()); + } }