@@ -58,4 +58,52 @@ public function testSend()
58
58
59
59
$ mailer ->send ($ email );
60
60
}
61
+
62
+ public function testLineBreaksInEncodedAttachment ()
63
+ {
64
+ $ email = new Email ();
65
+ $ email ->from ('foo@example.com ' )
66
+ ->to ('bar@example.com ' )
67
+ // even if content doesn't include new lines, the base64 encoding performed later may add them
68
+ ->attach ('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod ' , 'lorem.txt ' );
69
+
70
+ $ response = $ this ->createMock (ResponseInterface::class);
71
+
72
+ $ response
73
+ ->expects ($ this ->once ())
74
+ ->method ('getStatusCode ' )
75
+ ->willReturn (202 );
76
+
77
+ $ httpClient = $ this ->createMock (HttpClientInterface::class);
78
+
79
+ $ httpClient
80
+ ->expects ($ this ->once ())
81
+ ->method ('request ' )
82
+ ->with ('POST ' , 'https://api.sendgrid.com/v3/mail/send ' , [
83
+ 'json ' => [
84
+ 'personalizations ' => [
85
+ [
86
+ 'to ' => [['email ' => 'bar@example.com ' ]],
87
+ 'subject ' => null ,
88
+ ],
89
+ ],
90
+ 'from ' => ['email ' => 'foo@example.com ' ],
91
+ 'content ' => [],
92
+ 'attachments ' => [
93
+ [
94
+ 'content ' => 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2VkIGRvIGVpdXNtb2Q= ' ,
95
+ 'filename ' => 'lorem.txt ' ,
96
+ 'type ' => 'application/octet-stream ' ,
97
+ 'disposition ' => 'attachment ' ,
98
+ ],
99
+ ],
100
+ ],
101
+ 'auth_bearer ' => 'foo ' ,
102
+ ])
103
+ ->willReturn ($ response );
104
+
105
+ $ mailer = new SendgridTransport ('foo ' , $ httpClient );
106
+
107
+ $ mailer ->send ($ email );
108
+ }
61
109
}
0 commit comments