Issues (3627)

Tests/Transport/AmazonApiTransportTest.php (9 issues)

1
<?php
2
3
/*
4
 * @copyright   2020 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 *
11
 */
12
13
namespace Mautic\EmailBundle\Tests\Transport;
14
15
use Aws\CommandInterface;
16
use Aws\Credentials\Credentials;
17
use Aws\Exception\AwsException;
18
use Aws\MockHandler;
19
use Aws\Result;
20
use Aws\SesV2\SesV2Client;
21
use Joomla\Http\Http;
22
use Mautic\EmailBundle\Model\TransportCallback;
23
use Mautic\EmailBundle\MonitoredEmail\Message;
24
use Mautic\EmailBundle\MonitoredEmail\Processor\Bounce\BouncedEmail;
25
use Mautic\EmailBundle\MonitoredEmail\Processor\Unsubscription\UnsubscribedEmail;
26
use Mautic\EmailBundle\Swiftmailer\Amazon\AmazonCallback;
27
use Mautic\EmailBundle\Swiftmailer\Message\MauticMessage;
28
use Mautic\EmailBundle\Swiftmailer\Transport\AmazonApiTransport;
29
use Psr\Http\Message\RequestInterface;
30
use Psr\Log\LoggerInterface;
31
use Symfony\Component\HttpFoundation\Request;
32
use Symfony\Component\HttpFoundation\Response;
33
use Symfony\Component\HttpKernel\Exception\HttpException;
34
use Symfony\Component\Translation\TranslatorInterface;
35
36
class AmazonApiTransportTest extends \PHPUnit\Framework\TestCase
37
{
38
    private $translator;
39
    private $amazonCallback;
40
    private $amazonClient;
41
    private $amazonMock;
42
    private $amazonTransport;
43
    private $logger;
44
    private $headers;
45
    private $request;
46
47
    /**
48
     * @var Http
49
     */
50
    private $mockHttp;
51
    /**
52
     * @var TransportCallback
53
     */
54
    private $transportCallback;
55
56
    /**
57
     * @var MauticMessage
58
     */
59
    private $message;
60
61
    protected function setUp(): void
62
    {
63
        parent::setUp();
64
65
        $this->translator         = $this->createMock(TranslatorInterface::class);
66
        $this->amazonCallback     = $this->createMock(AmazonCallback::class);
67
        $this->logger             = $this->createMock(LoggerInterface::class);
68
        $this->message            = $this->createMock(MauticMessage::class);
69
        $this->headers            = $this->createMock(\Swift_Mime_SimpleHeaderSet::class);
70
        $this->request            =  $this->createMock(Request::class);
71
72
        // Mock http connector
73
        $this->mockHttp = $this->getMockBuilder(Http::class)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(Jo...onstructor()->getMock() of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Joomla\Http\Http of property $mockHttp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
74
            ->disableOriginalConstructor()
75
            ->getMock();
76
        $this->transportCallback = $this->getMockBuilder(TransportCallback::class)
77
            ->disableOriginalConstructor()
78
            ->getMock();
79
80
        $this->amazonMock         = new MockHandler();
81
82
        $this->amazonTransport = new AmazonApiTransport(
83
            $this->translator,
84
            $this->amazonCallback,
85
            $this->logger
86
        );
87
88
        $this->amazonTransport->setRegion('us-east-1', '');
89
        $this->amazonTransport->setUsername('username');
90
        $this->amazonTransport->setPassword('password');
91
        $this->amazonTransport->setHandler($this->amazonMock);
92
        $this->amazonTransport->setDebug(true);
93
94
        $this->translator->method('trans')
95
            ->willReturnCallback(function ($key) {
96
                return $key;
97
            });
98
99
        $this->message->method('getChildren')->willReturn([]);
100
        $this->message->method('getMetadata')->willReturn([
101
            '[email protected]' => [
102
                'name'        => 'firstname227 lastname227',
103
                'leadId'      => 228,
104
                'emailId'     => 2,
105
                'emailName'   => 'simple',
106
                'hashId'      => '5f86a61cc8084320276637',
107
                'hashIdState' => true,
108
                'source'      => [
109
                    'campaign.event',
110
                        23,
111
                ],
112
                'tokens' => [
113
                    '{dynamiccontent="Dynamic Content 1"}' => 'Default Dynamic Content',
114
                    '{unsubscribe_text}'                   => '<a href="https://mautic3.ddev.site/email/unsubscribe/5f86a61cc8084320276637">Unsubscribe</a> to no longer receive emails from us.',
115
                    '{unsubscribe_url}'                    => 'https://mautic3.ddev.site/email/unsubscribe/5f86a61cc8084320276637',
116
                    '{webview_text}'                       => '<a href="https://mautic3.ddev.site/email/view/5f86a61cc8084320276637">Having trouble reading this email? Click here.</a>',
117
                    '{webview_url}'                        => 'https://mautic3.ddev.site/email/view/5f86a61cc8084320276637',
118
                    '{signature}'                          => 'Best regards, Mohammad Musa',
119
                    '{subject}'                            => 'simple message',
120
                    '{contactfield=firstname}'             => 'firstname227',
121
                    '{contactfield=lastname}'              => 'lastname227',
122
                    '{ownerfield=email}'                   => '',
123
                    '{ownerfield=firstname}'               => '',
124
                    '{ownerfield=lastname}'                => '',
125
                    '{ownerfield=position}'                => '',
126
                    '{ownerfield=signature}'               => '',
127
                    '{tracking_pixel}'                     => 'https://mautic3.ddev.site/email/5f86a61cc8084320276637.gif',
128
                ],
129
                'utmTags' => [
130
                    'utmSource'   => 'c_source',
131
                    'utmMedium'   => 'c_medium',
132
                    'utmCampaign' => 'c_name',
133
                    'utmContent'  => 'c_content',
134
                ],
135
            ],
136
        ]);
137
        $this->message->method('getSubject')->willReturn('Top secret');
138
        $this->message->method('getFrom')->willReturn(['[email protected]' => 'John']);
139
        $this->message->method('getTo')->willReturn(['[email protected]' => 'Jane']);
140
        $this->message->method('getCc')->willReturn(['[email protected]' => 'Jane']);
141
        $this->message->method('getBcc')->willReturn(['[email protected]' => 'Jane']);
142
        $this->message->method('getHeaders')->willReturn($this->headers);
143
        $this->headers->method('getAll')->willReturn([]);
144
        $this->message->method('getBody')->willReturn('Test Body');
145
        $this->message->method('getAttachments')->willReturn([]);
146
        $this->message->method('toString')->willReturn('test');
147
        $this->amazonMock->append(new Result([
148
          'SendQuota' => [
149
            'Max24HourSend'  => 1000,
150
            'MaxSendRate'    => 160,
151
            'SentLast24Hours'=> 0,
152
          ],
153
          'SendingEnabled' => true,
154
        ]));
155
156
        $this->amazonMock->append(new Result([
157
          'MessageId' => 'abcd12',
158
        ]));
159
    }
160
161
    public function testAmazonStart()
162
    {
163
        $this->assertNull($this->amazonTransport->start());
164
    }
165
166
    public function testAmazonSend()
167
    {
168
        $this->amazonTransport->start();
169
        $sent = $this->amazonTransport->send($this->message);
170
        $this->assertEquals(1, $sent);
171
    }
172
173
    public function testprocessInvalidJsonRequest()
174
    {
175
        $payload = <<< 'PAYLOAD'
176
{
177
    "Type": "Invalid
178
}
179
PAYLOAD;
180
181
        $amazonCallback = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
182
183
        $request = $this->getMockBuilder(Request::class)
184
        ->disableOriginalConstructor()
185
        ->getMock();
186
187
        $request->expects($this->any())
188
            ->method('getContent')
189
            ->will($this->returnValue($payload));
190
191
        $this->expectException(HttpException::class);
192
193
        $amazonCallback->processCallbackRequest($request);
194
    }
195
196
    public function testprocessValidJsonWithoutTypeRequest()
197
    {
198
        $payload = <<< 'PAYLOAD'
199
{
200
    "Content": "Not Type"
201
}
202
PAYLOAD;
203
204
        $amazonCallback = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
205
206
        $request = $this->getMockBuilder(Request::class)
207
        ->disableOriginalConstructor()
208
        ->getMock();
209
210
        $request->expects($this->any())
211
            ->method('getContent')
212
            ->will($this->returnValue($payload));
213
214
        $this->expectException(HttpException::class);
215
216
        $amazonCallback->processCallbackRequest($request);
217
    }
218
219
    public function testprocessSubscriptionConfirmationRequest()
220
    {
221
        $payload = <<< 'PAYLOAD'
222
{
223
    "Type" : "SubscriptionConfirmation",
224
    "MessageId" : "a3466e9f-872a-4438-9cf8-91d282af0f53",
225
    "Token" : "2336412f37fb687f5d51e6e241d44a2cbcd89f3e7ec51a160fe3cbfc82bc5853b2b75443b051bbeb52c98da19f609e9de0da18c341fe56a51b34f95203cb9bbab9fda0ba97eb5c43b3102911d6a68e05b8023efa4daeb8e217fd1c7325237d53f8e4e95fd3b0217dd13485a8f61f39478a21d55ec0a96ec0f163167053d86c76",
226
    "TopicArn" : "arn:aws:sns:eu-west-1:918057160339:55hubs-mautic-test",
227
    "Message" : "You have chosen to subscribe to the topic arn:aws:sns:eu-west-1:918057160339:55hubs-mautic-test. To confirm the subscription, visit the SubscribeURL included in this message.",
228
    "SubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:eu-west-1:918057160339:55hubs-mautic-test&Token=2336412f37fb687f5d51e6e241d44a2cbcd89f3e7ec51a160fe3cbfc82bc5853b2b75443b051bbeb52c98da19f609e9de0da18c341fe56a51b34f95203cb9bbab9fda0ba97eb5c43b3102911d6a68e05b8023efa4daeb8e217fd1c7325237d53f8e4e95fd3b0217dd13485a8f61f39478a21d55ec0a96ec0f163167053d86c76",
229
    "Timestamp" : "2016-08-17T07:14:09.912Z",
230
    "SignatureVersion" : "1",
231
    "Signature" : "Vzi/S+YKbWA7VfLMPJxiKoIEi61/kH3BHtRMFe3FdMAm6RcJyEUjVZ5CmJCRFywGspHcCP6db3JedeI9yLAKm9fwDDg74PanONzGhcb4ja3e7E7B7auCk7exAVZojrKbY+yEJk91CfoqY4BTp3m3sD2/9o1phj+Dn+hENDSGVRP3zrs6VCuL7KFPYi88kCT/5d3suHDpbINwCAkKkXZWcRtx+Ka7uZdq2AA6MJdedIQ+DscL+7C1htJ/X4LcUiw9KUsweibCbz1mxpZVJ9uLbW5uLmykkBjnp5SecRcYA5vqowGpMq/vyI8RANs9udnn0vnGYFh6GwHXFZbdZtDCsw==",
232
    "SigningCertURL" : "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"
233
}
234
PAYLOAD;
235
236
        $amazonCallback = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
237
238
        $request = $this->getMockBuilder(Request::class)
239
        ->disableOriginalConstructor()
240
        ->getMock();
241
242
        $request->expects($this->any())
243
            ->method('getContent')
244
            ->will($this->returnValue($payload));
245
246
        // Mock a successful response
247
        $mockResponse       = $this->getMockBuilder(Response::class)->getMock();
248
        $mockResponse->code = 200;
0 ignored issues
show
Accessing code on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
249
250
        $this->mockHttp->expects($this->once())
0 ignored issues
show
The method expects() does not exist on Joomla\Http\Http. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

250
        $this->mockHttp->/** @scrutinizer ignore-call */ 
251
                         expects($this->once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
251
            ->method('get')
252
            ->willReturn($mockResponse);
253
254
        $amazonCallback->processCallbackRequest($request);
255
    }
256
257
    public function testprocessNotificationBounceRequest()
258
    {
259
        $payload = <<< 'PAYLOAD'
260
{
261
    "Type" : "Notification",
262
    "MessageId" : "7c2d7069-7db3-53c8-87d0-20476a630fb6",
263
    "TopicArn" : "arn:aws:sns:eu-west-1:918057160339:55hubs-mautic-test",
264
    "Message" : "{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceType\":\"Permanent\",\"bounceSubType\":\"General\",\"bouncedRecipients\":[{\"emailAddress\":\"[email protected]\",\"action\":\"failed\",\"status\":\"5.1.1\",\"diagnosticCode\":\"smtp; 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in virtual alias table\"}],\"timestamp\":\"2016-08-17T07:43:12.776Z\",\"feedbackId\":\"0102015697743d4c-619f1aa8-763f-4bea-8648-0b3bbdedd1ea-000000\",\"reportingMTA\":\"dsn; a4-24.smtp-out.eu-west-1.amazonses.com\"},\"mail\":{\"timestamp\":\"2016-08-17T07:43:11.000Z\",\"source\":\"[email protected]\",\"sourceArn\":\"arn:aws:ses:eu-west-1:918057160339:identity/nope.com\",\"sendingAccountId\":\"918057160339\",\"messageId\":\"010201569774384f-81311784-10dd-48a8-921f-8316c145e64d-000000\",\"destination\":[\"[email protected]\"]}}",
265
    "Timestamp" : "2016-08-17T07:43:12.822Z",
266
    "SignatureVersion" : "1",
267
    "Signature" : "GNWnMWfKx1PPDjUstq2Ln13+AJWEK/Qo8YllYC7dGSlPhC5nClop5+vCj0CG2XN7aN41GhsJJ1e+F4IiRxm9v2wwua6BC3mtykrXEi8VeGy2HuetbF9bEeBEPbtbeIyIXJhdPDhbs4anPJwcEiN/toCoANoPWJ3jyVTOaUAxJb2oPTrvmjMxMpVE59sSo7Mz2+pQaUJl3ma0UgAC/lrYghi6n4cwlDTfbbIW+mbV7/d/5YN/tjL9/sD3DOuf+1PpFFTPsOVseZWV8PQ0/MWB2BOrKOKQyF7msLNX5iTkmsvRrbYULPvpbx32LsIxfNVFZJmsnTe2/6EGaAXf3TVPZA==",
268
    "SigningCertURL" : "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem",
269
    "UnsubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:918057160339:nope:1cddd2a6-bfa8-4eb5-b2b2-a7833eb5db9b"
270
}
271
PAYLOAD;
272
273
        $amazonCallback = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
274
275
        $request = $this->getMockBuilder(Request::class)
276
        ->disableOriginalConstructor()
277
        ->getMock();
278
279
        $request->expects($this->any())
280
            ->method('getContent')
281
            ->will($this->returnValue($payload));
282
283
        // Mock a successful response
284
        $mockResponse       = $this->getMockBuilder(Response::class)->getMock();
285
        $mockResponse->code = 200;
286
287
        $this->transportCallback->expects($this->once())
288
            ->method('addFailureByAddress');
289
290
        $amazonCallback->processCallbackRequest($request);
291
    }
292
293
    public function testprocessNotificationComplaintRequest()
294
    {
295
        $payload = <<< 'PAYLOAD'
296
{
297
    "Type" : "Notification",
298
    "MessageId" : "7c2d7069-7db3-53c8-87d0-20476a630fb6",
299
    "TopicArn" : "arn:aws:sns:eu-west-1:918057160339:55hubs-mautic-test",
300
    "Message": "{\"notificationType\":\"Complaint\", \"complaint\":{ \"complainedRecipients\":[ { \"emailAddress\":\"[email protected]\" } ], \"timestamp\":\"2016-01-27T14:59:38.237Z\", \"feedbackId\":\"0000013786031775-fea503bc-7497-49e1-881b-a0379bb037d3-000000\" } }",
301
    "Timestamp" : "2016-08-17T07:43:12.822Z",
302
    "SignatureVersion" : "1",
303
    "Signature" : "GNWnMWfKx1PPDjUstq2Ln13+AJWEK/Qo8YllYC7dGSlPhC5nClop5+vCj0CG2XN7aN41GhsJJ1e+F4IiRxm9v2wwua6BC3mtykrXEi8VeGy2HuetbF9bEeBEPbtbeIyIXJhdPDhbs4anPJwcEiN/toCoANoPWJ3jyVTOaUAxJb2oPTrvmjMxMpVE59sSo7Mz2+pQaUJl3ma0UgAC/lrYghi6n4cwlDTfbbIW+mbV7/d/5YN/tjL9/sD3DOuf+1PpFFTPsOVseZWV8PQ0/MWB2BOrKOKQyF7msLNX5iTkmsvRrbYULPvpbx32LsIxfNVFZJmsnTe2/6EGaAXf3TVPZA==",
304
    "SigningCertURL" : "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem",
305
    "UnsubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:918057160339:nope:1cddd2a6-bfa8-4eb5-b2b2-a7833eb5db9b"
306
    }
307
PAYLOAD;
308
309
        $amazonCallback = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
310
311
        $request = $this->getMockBuilder(Request::class)
312
        ->disableOriginalConstructor()
313
        ->getMock();
314
315
        $request->expects($this->any())
316
            ->method('getContent')
317
            ->will($this->returnValue($payload));
318
319
        // Mock a successful response
320
        $mockResponse       = $this->getMockBuilder(Response::class)->getMock();
321
        $mockResponse->code = 200;
0 ignored issues
show
Accessing code on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
322
323
        $this->transportCallback->expects($this->once())
324
            ->method('addFailureByAddress');
325
326
        $amazonCallback->processCallbackRequest($request);
327
    }
328
329
    public function testprocessBounce()
330
    {
331
        $messageMock = $this->getMockBuilder(Message::class)
332
                        ->disableOriginalConstructor()
333
                        ->getMock();
334
        $messageMock->fromAddress = '[email protected]';
335
        $messageMock->textPlain   = '{"notificationType":"Bounce","bounce":{"bounceType":"Permanent","bounceSubType":"General","bouncedRecipients":[{"emailAddress":"[email protected]","action":"failed","status":"5.1.1","diagnosticCode":"smtp; 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in virtual alias table"}],"timestamp":"2016-08-17T07:43:12.776Z","feedbackId":"0102015697743d4c-619f1aa8-763f-4bea-8648-0b3bbdedd1ea-000000","reportingMTA":"dsn; a4-24.smtp-out.eu-west-1.amazonses.com"},"mail":{"timestamp":"2016-08-17T07:43:11.000Z","source":"[email protected]","sourceArn":"arn:aws:ses:eu-west-1:918057160339:identity/nope.com","sendingAccountId":"918057160339","messageId":"010201569774384f-81311784-10dd-48a8-921f-8316c145e64d-000000","destination":["[email protected]"]}}';
0 ignored issues
show
Accessing textPlain on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
336
        $amazonCallback           = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
337
        $bounce                   = new BouncedEmail();
338
        $bounce->setContactEmail('[email protected]')
339
            ->setBounceAddress('[email protected]')
340
            ->setType('unknown')
341
            ->setRuleCategory('unknown')
342
            ->setRuleNumber('0013')
343
            ->setIsFinal(true);
344
345
        $this->assertEquals($bounce, $amazonCallback->processBounce($messageMock));
346
    }
347
348
    public function testprocessUnsubscription()
349
    {
350
        $messageMock = $this->getMockBuilder(Message::class)
351
                        ->disableOriginalConstructor()
352
                        ->getMock();
353
        $messageMock->fromAddress = '[email protected]';
354
        $messageMock->textPlain   = '{"notificationType":"Complaint", "complaint":{ "complainedRecipients":[ { "emailAddress":"[email protected]" } ], "timestamp":"2016-01-27T14:59:38.237Z", "feedbackId":"0000013786031775-fea503bc-7497-49e1-881b-a0379bb037d3-000000" }, "mail":{"source": "unknown"} }';
355
        $amazonCallback           = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
356
        $unsubscribe              = new UnsubscribedEmail('[email protected]', 'unknown');
357
        $this->assertEquals($unsubscribe, $amazonCallback->processUnsubscription($messageMock));
358
    }
359
360
    public function testprocessNotificationBounceRequestConfigSet()
361
    {
362
        $payload = <<< 'PAYLOAD'
363
        {"eventType":"Bounce","bounce":{"bounceType":"Permanent","bounceSubType":"General","bouncedRecipients":[{"emailAddress":"[email protected]","action":"failed","status":"5.1.1","diagnosticCode":"smtp; 550 5.1.1 user unknown"}],"timestamp":"2017-08-05T00:41:02.669Z","feedbackId":"01000157c44f053b-61b59c11-9236-11e6-8f96-7be8aexample-000000","reportingMTA":"dsn; mta.example.com"},"mail":{"timestamp":"2017-08-05T00:40:02.012Z","source":"Sender Name <[email protected]>","sourceArn":"arn:aws:ses:us-east-1:123456789012:identity/[email protected]","sendingAccountId":"123456789012","messageId":"EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000","destination":["[email protected]"],"headersTruncated":false,"headers":[{"name":"From","value":"Sender Name <[email protected]>"},{"name":"To","value":"[email protected]"},{"name":"Subject","value":"Message sent from Amazon SES"},{"name":"MIME-Version","value":"1.0"},{"name":"Content-Type","value":"multipart/alternative; boundary=\"----=_Part_7307378_1629847660.1516840721503\""}],"commonHeaders":{"from":["Sender Name <[email protected]>"],"to":["[email protected]"],"messageId":"EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000","subject":"Message sent from Amazon SES"},"tags":{"ses:configuration-set":["ConfigSet"],"ses:source-ip":["192.0.2.0"],"ses:from-domain":["example.com"],"ses:caller-identity":["ses_user"]}}}
364
PAYLOAD;
365
366
        $amazonCallback = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
367
368
        $request = $this->getMockBuilder(Request::class)
369
        ->disableOriginalConstructor()
370
        ->getMock();
371
372
        $request->expects($this->any())
373
            ->method('getContent')
374
            ->will($this->returnValue($payload));
375
376
        // Mock a successful response
377
        $mockResponse       = $this->getMockBuilder(Response::class)->getMock();
378
        $mockResponse->code = 200;
379
380
        $this->transportCallback->expects($this->once())
381
            ->method('addFailureByAddress');
382
383
        $amazonCallback->processCallbackRequest($request);
384
    }
385
386
    public function testprocessNotificationComplaintRequestConfigSet()
387
    {
388
        $payload = <<< 'PAYLOAD'
389
        {"eventType":"Complaint","complaint":{"complainedRecipients":[{"emailAddress":"[email protected]"}],"timestamp":"2017-08-05T00:41:02.669Z","feedbackId":"01000157c44f053b-61b59c11-9236-11e6-8f96-7be8aexample-000000","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36","complaintFeedbackType":"abuse","arrivalDate":"2017-08-05T00:41:02.669Z"},"mail":{"timestamp":"2017-08-05T00:40:01.123Z","source":"Sender Name <[email protected]>","sourceArn":"arn:aws:ses:us-east-1:123456789012:identity/[email protected]","sendingAccountId":"123456789012","messageId":"EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000","destination":["[email protected]"],"headersTruncated":false,"headers":[{"name":"From","value":"Sender Name <[email protected]>"},{"name":"To","value":"[email protected]"},{"name":"Subject","value":"Message sent from Amazon SES"},{"name":"MIME-Version","value":"1.0"},{"name":"Content-Type","value":"multipart/alternative; boundary=\"----=_Part_7298998_679725522.1516840859643\""}],"commonHeaders":{"from":["Sender Name <[email protected]>"],"to":["[email protected]"],"messageId":"EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000","subject":"Message sent from Amazon SES"},"tags":{"ses:configuration-set":["ConfigSet"],"ses:source-ip":["192.0.2.0"],"ses:from-domain":["example.com"],"ses:caller-identity":["ses_user"]}}}
390
PAYLOAD;
391
392
        $amazonCallback = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
393
394
        $request = $this->getMockBuilder(Request::class)
395
        ->disableOriginalConstructor()
396
        ->getMock();
397
398
        $request->expects($this->any())
399
            ->method('getContent')
400
            ->will($this->returnValue($payload));
401
402
        // Mock a successful response
403
        $mockResponse       = $this->getMockBuilder(Response::class)->getMock();
404
        $mockResponse->code = 200;
0 ignored issues
show
Accessing code on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
405
406
        $this->transportCallback->expects($this->once())
407
            ->method('addFailureByAddress');
408
409
        $amazonCallback->processCallbackRequest($request);
410
    }
411
412
    public function testprocessBounceConfigSet()
413
    {
414
        $messageMock = $this->getMockBuilder(Message::class)
415
                        ->disableOriginalConstructor()
416
                        ->getMock();
417
        $messageMock->fromAddress = '[email protected]';
0 ignored issues
show
Accessing fromAddress on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
418
        $messageMock->textPlain   = '{"eventType":"Bounce","bounce":{"bounceType":"Permanent","bounceSubType":"General","bouncedRecipients":[{"emailAddress":"[email protected]","action":"failed","status":"5.1.1","diagnosticCode":"smtp; 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in virtual alias table"}],"timestamp":"2016-08-17T07:43:12.776Z","feedbackId":"0102015697743d4c-619f1aa8-763f-4bea-8648-0b3bbdedd1ea-000000","reportingMTA":"dsn; a4-24.smtp-out.eu-west-1.amazonses.com"},"mail":{"timestamp":"2016-08-17T07:43:11.000Z","source":"[email protected]","sourceArn":"arn:aws:ses:eu-west-1:918057160339:identity/nope.com","sendingAccountId":"918057160339","messageId":"010201569774384f-81311784-10dd-48a8-921f-8316c145e64d-000000","destination":["[email protected]"]}}';
419
        $amazonCallback           = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
420
        $bounce                   = new BouncedEmail();
421
        $bounce->setContactEmail('[email protected]')
422
            ->setBounceAddress('[email protected]')
423
            ->setType('unknown')
424
            ->setRuleCategory('unknown')
425
            ->setRuleNumber('0013')
426
            ->setIsFinal(true);
427
428
        $this->assertEquals($bounce, $amazonCallback->processBounce($messageMock));
429
    }
430
431
    public function testprocessUnsubscriptionConfigSet()
432
    {
433
        $messageMock = $this->getMockBuilder(Message::class)
434
                        ->disableOriginalConstructor()
435
                        ->getMock();
436
        $messageMock->fromAddress = '[email protected]';
0 ignored issues
show
Accessing fromAddress on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
437
        $messageMock->textPlain   = '{"eventType":"Complaint", "complaint":{ "complainedRecipients":[ { "emailAddress":"[email protected]" } ], "timestamp":"2016-01-27T14:59:38.237Z", "feedbackId":"0000013786031775-fea503bc-7497-49e1-881b-a0379bb037d3-000000" }, "mail":{"source": "unknown"} }';
0 ignored issues
show
Accessing textPlain on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
438
        $amazonCallback           = new AmazonCallback($this->translator, $this->logger, $this->mockHttp, $this->transportCallback);
439
        $unsubscribe              = new UnsubscribedEmail('[email protected]', 'unknown');
440
        $this->assertEquals($unsubscribe, $amazonCallback->processUnsubscription($messageMock));
441
    }
442
}
443