Skip to content

Commit a49bfbf

Browse files
committed
Fix count error when no 'cc', 'bcc' or 'to' fields are set
1 parent db9872c commit a49bfbf

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/Services/SendGridTransport.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace ExpertCoder\Swiftmailer\SendGridBundle\Services;
44

55
use finfo;
6+
use Psr\Log\LoggerInterface;
67
use SendGrid;
8+
use Swift_Events_EventDispatcher;
79
use Swift_Events_EventListener;
10+
use Swift_Events_SendEvent;
811
use Swift_Mime_Attachment;
912
use Swift_Mime_SimpleMessage;
1013
use Swift_Transport;
11-
use Swift_Events_EventDispatcher;
12-
use Swift_Events_SendEvent;
13-
use Psr\Log\LoggerInterface;
1414

1515
class SendGridTransport implements Swift_Transport
1616
{
@@ -70,11 +70,22 @@ class SendGridTransport implements Swift_Transport
7070

7171
/**
7272
* Some header keys are reserved. You may not include any of the following reserved keys
73-
* (From SendGrid docs)
73+
*
74+
* @see https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#-Headers-Errors
7475
*/
7576
const RESERVED_KEYWORDS = [
76-
'X-SG-ID', 'X-SG-EID', 'RECEIVED', 'DKIM-SIGNATURE', 'CONTENT-TYPE', 'CONTENT-TRANSFER-ENCODING',
77-
'TO', 'FROM', 'SUBJECT', 'REPLY-TO', 'CC', 'BCC'
77+
'X-SG-ID',
78+
'X-SG-EID',
79+
'RECEIVED',
80+
'DKIM-SIGNATURE',
81+
'CONTENT-TYPE',
82+
'CONTENT-TRANSFER-ENCODING',
83+
'TO',
84+
'FROM',
85+
'SUBJECT',
86+
'REPLY-TO',
87+
'CC',
88+
'BCC',
7889
];
7990

8091
public function __construct(Swift_Events_EventDispatcher $eventDispatcher, $sendGridApiKey, $sendGridCategories)
@@ -260,7 +271,7 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
260271
}
261272

262273
if ($evt) {
263-
if ($sent == count($toArr) + count($ccArr) + count($bccArr)) {
274+
if ($sent == count($toArr ?? []) + count($ccArr ?? []) + count($bccArr ?? [])) {
264275
$evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
265276
} elseif ($sent > 0) {
266277
$evt->setResult(Swift_Events_SendEvent::RESULT_TENTATIVE);

tests/BundleInitializationTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace ExpertCoder\Swiftmailer\SendGridBundle\Tests;
44

5-
use Nyholm\BundleTest\BaseBundleTestCase;
6-
use Nyholm\BundleTest\CompilerPass\PublicServicePass;
75
use ExpertCoder\Swiftmailer\SendGridBundle\ExpertCoderSwiftmailerSendGridBundle;
86
use ExpertCoder\Swiftmailer\SendGridBundle\Services\SendGridTransport;
7+
use Nyholm\BundleTest\BaseBundleTestCase;
8+
use Nyholm\BundleTest\CompilerPass\PublicServicePass;
9+
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
910

1011
class BundleInitializationTest extends BaseBundleTestCase
1112
{
@@ -22,6 +23,7 @@ protected function setUp()
2223
$this->addCompilerPass(new PublicServicePass('|swiftmailer.mailer.transport.expertcoder_swift_mailer.*|'));
2324
// Create a new Kernel
2425
$kernel = $this->createKernel();
26+
$kernel->addBundle(SwiftmailerBundle::class);
2527

2628
// Add some configuration
2729
$kernel->addConfigFile(__DIR__.'/config_test.yml');
@@ -60,6 +62,6 @@ public function testSimpleMail()
6062
$mailer = new \Swift_Mailer($transport);
6163
$result = $mailer->send($message);
6264

63-
$this->assertEquals(0, $mailer->send($message)); // This should gives us 0 for no email sent
65+
$this->assertSame(0, $mailer->send($message)); // This should gives us 0 for no email sent
6466
}
6567
}

0 commit comments

Comments
 (0)