Skip to content

Commit

Permalink
callback subscriber test
Browse files Browse the repository at this point in the history
  • Loading branch information
aarohiprasad committed Feb 14, 2025
1 parent 6f781aa commit 0764b9d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 deletions.
32 changes: 32 additions & 0 deletions Tests/Functional/EventSubscriber/CallbackSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<JSON
[
{
"msys": {
"message_event": {
"reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
"msg_from":"msprvs1=18290qww0ygol=bounces-44585-172@bounces.mauticsparkt3.com",
"event_id":"13251575597141532",
"raw_reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
"error_code":"550",
"subaccount_id":172,
"delv_method":"esmtp",
"customer_id":44585,
"type":"out_of_band",
"bounce_class":"60",
"timestamp":"2020-01-22T21:59:32.000Z"
}
}
}
]
JSON;
$request = new Request([], json_decode($payload, true));
$this->sparkpost->processCallbackRequest($request);
$this->transportCallbackMock->expects($this->never())
->method($this->anything());
}
}
52 changes: 45 additions & 7 deletions Tests/Unit/Mailer/Transport/SparkpostTransportMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

class SparkpostTransportMessageTest extends TestCase
{
/**
* @var TransportCallback|MockObject
*/
private $transportCallbackMock;
private SparkpostTransport $sparkpost;

public function testCcAndBccFields(): void
{
$emailId = 1;
Expand All @@ -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
Expand Down Expand Up @@ -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('[email protected]', $payload['content']['from']);
Assert::assertEquals('Test subject', $payload['content']['subject']);
Expand Down Expand Up @@ -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 = <<<JSON
[
{
"msys": {
"message_event": {
"reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
"msg_from":"msprvs1=18290qww0ygol=bounces-44585-172@bounces.mauticsparkt3.com",
"event_id":"13251575597141532",
"raw_reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
"error_code":"550",
"subaccount_id":172,
"delv_method":"esmtp",
"customer_id":44585,
"type":"out_of_band",
"bounce_class":"60",
"timestamp":"2020-01-22T21:59:32.000Z"
}
}
}
]
JSON;
$request = new Request([], json_decode($payload, true));
$this->sparkpost->processCallbackRequest($request);
$this->transportCallbackMock->expects($this->never())
->method($this->anything());
}
}

0 comments on commit 0764b9d

Please sign in to comment.