Skip to content

Commit 0764b9d

Browse files
committed
callback subscriber test
1 parent 6f781aa commit 0764b9d

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

Tests/Functional/EventSubscriber/CallbackSubscriberTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,36 @@ private function getCommentAndReason(string $type): array
198198
],
199199
};
200200
}
201+
202+
/**
203+
* For the message with 'type': 'out of band' and 'bounce class': 60 should never be called transportCallback.
204+
*/
205+
public function testProcessCallbackRequestWhenSoftBounce(): void
206+
{
207+
$payload = <<<JSON
208+
[
209+
{
210+
"msys": {
211+
"message_event": {
212+
"reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
213+
"msg_from":"msprvs1=18290qww0ygol=bounces-44585-172@bounces.mauticsparkt3.com",
214+
"event_id":"13251575597141532",
215+
"raw_reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
216+
"error_code":"550",
217+
"subaccount_id":172,
218+
"delv_method":"esmtp",
219+
"customer_id":44585,
220+
"type":"out_of_band",
221+
"bounce_class":"60",
222+
"timestamp":"2020-01-22T21:59:32.000Z"
223+
}
224+
}
225+
}
226+
]
227+
JSON;
228+
$request = new Request([], json_decode($payload, true));
229+
$this->sparkpost->processCallbackRequest($request);
230+
$this->transportCallbackMock->expects($this->never())
231+
->method($this->anything());
232+
}
201233
}

Tests/Unit/Mailer/Transport/SparkpostTransportMessageTest.php

+45-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
class SparkpostTransportMessageTest extends TestCase
1818
{
19+
/**
20+
* @var TransportCallback|MockObject
21+
*/
22+
private $transportCallbackMock;
23+
private SparkpostTransport $sparkpost;
24+
1925
public function testCcAndBccFields(): void
2026
{
2127
$emailId = 1;
@@ -25,15 +31,15 @@ public function testCcAndBccFields(): void
2531
// so for maintain 64 bytes last char will be trimmed.
2632
$expectedInternalEmailName = '202211_シナリオメール②内視鏡機器提案のご案';
2733

28-
$transportCallbackMock = $this->createMock(TransportCallback::class);
29-
$httpClientMock = $this->createMock(HttpClientInterface::class);
30-
$eventDispatcherMock = $this->createMock(EventDispatcherInterface::class);
31-
$loggerMock = $this->createMock(LoggerInterface::class);
34+
$this->transportCallbackMock = $this->createMock(TransportCallback::class);
35+
$httpClientMock = $this->createMock(HttpClientInterface::class);
36+
$eventDispatcherMock = $this->createMock(EventDispatcherInterface::class);
37+
$loggerMock = $this->createMock(LoggerInterface::class);
3238

33-
$sparkpost = new SparkpostTransport(
39+
$this->sparkpost = new SparkpostTransport(
3440
'1234',
3541
'us',
36-
$transportCallbackMock,
42+
$this->transportCallbackMock,
3743
$httpClientMock,
3844
$eventDispatcherMock,
3945
$loggerMock
@@ -66,7 +72,7 @@ public function testCcAndBccFields(): void
6672
$sentMessageMock->method('getOriginalMessage')
6773
->willReturn($message);
6874

69-
$payload = $this->invokeInaccessibleMethod($sparkpost, 'getSparkpostPayload', [$sentMessageMock]);
75+
$payload = $this->invokeInaccessibleMethod($this->sparkpost, 'getSparkpostPayload', [$sentMessageMock]);
7076
Assert::assertEquals(sprintf('%s:%s', $emailId, $expectedInternalEmailName), $payload['campaign_id']);
7177
Assert::assertEquals('[email protected]', $payload['content']['from']);
7278
Assert::assertEquals('Test subject', $payload['content']['subject']);
@@ -187,4 +193,36 @@ private function invokeInaccessibleMethod(object $object, string $methodName, ar
187193

188194
return $method->invokeArgs($object, $args);
189195
}
196+
197+
/**
198+
* For the message with 'type': 'out of band' and 'bounce class': 60 should never be called transportCallback.
199+
*/
200+
public function testProcessCallbackRequestWhenSoftBounce(): void
201+
{
202+
$payload = <<<JSON
203+
[
204+
{
205+
"msys": {
206+
"message_event": {
207+
"reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
208+
"msg_from":"msprvs1=18290qww0ygol=bounces-44585-172@bounces.mauticsparkt3.com",
209+
"event_id":"13251575597141532",
210+
"raw_reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
211+
"error_code":"550",
212+
"subaccount_id":172,
213+
"delv_method":"esmtp",
214+
"customer_id":44585,
215+
"type":"out_of_band",
216+
"bounce_class":"60",
217+
"timestamp":"2020-01-22T21:59:32.000Z"
218+
}
219+
}
220+
}
221+
]
222+
JSON;
223+
$request = new Request([], json_decode($payload, true));
224+
$this->sparkpost->processCallbackRequest($request);
225+
$this->transportCallbackMock->expects($this->never())
226+
->method($this->anything());
227+
}
190228
}

0 commit comments

Comments
 (0)